-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConsoleHistory.cpp
58 lines (47 loc) · 1.03 KB
/
ConsoleHistory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "ConsoleHistory.h"
void ConsoleHistory::AddLine( std::string_view str )
{
if( str.empty() )
{
return;
}
if( history[( numLines - 1 ) & ( MAX_LINES - 1 )] == str )
{
return;
}
upHistory = numLines;
returnLine = numLines;
downHistory = numLines + 1;
history[numLines & ( MAX_LINES - 1 )] = str;
numLines += 1;
}
std::string_view ConsoleHistory::GetFromHistory( const bool toUp )
{
if( numLines == 0 )
{
return "";
}
// move the history point
if( toUp )
{
if( upHistory < numLines - MAX_LINES || upHistory < 0 )
{
return "";
}
returnLine = upHistory;
downHistory = upHistory + 1;
upHistory--;
}
else
{
if( downHistory >= numLines )
{
upHistory = downHistory - 1;
return "";
}
returnLine = downHistory;
upHistory = downHistory - 1;
downHistory++;
}
return history[returnLine & ( MAX_LINES - 1 )];
}