-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathCommandHistory.cs
49 lines (38 loc) · 997 Bytes
/
CommandHistory.cs
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
using System.Collections.Generic;
namespace CommandTerminal
{
public class CommandHistory
{
List<string> history = new List<string>();
int position;
public void Push(string command_string) {
if (command_string == "") {
return;
}
history.Add(command_string);
position = history.Count;
}
public string Next() {
position++;
if (position >= history.Count) {
position = history.Count;
return "";
}
return history[position];
}
public string Previous() {
if (history.Count == 0) {
return "";
}
position--;
if (position < 0) {
position = 0;
}
return history[position];
}
public void Clear() {
history.Clear();
position = 0;
}
}
}