|
|
|
|
|
|
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Linq; |
|
|
using System.Text; |
|
|
|
|
|
namespace PythonConsoleControl |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
public class CommandLineHistory |
|
|
{ |
|
|
List<string> lines = new List<string>(); |
|
|
int position; |
|
|
|
|
|
public CommandLineHistory() |
|
|
{ |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Add(string line) |
|
|
{ |
|
|
if (!String.IsNullOrEmpty(line)) |
|
|
{ |
|
|
int index = lines.Count - 1; |
|
|
if (index >= 0) |
|
|
{ |
|
|
if (lines[index] != line) |
|
|
{ |
|
|
lines.Add(line); |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
lines.Add(line); |
|
|
} |
|
|
} |
|
|
position = lines.Count; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string Current |
|
|
{ |
|
|
get |
|
|
{ |
|
|
if ((position >= 0) && (position < lines.Count)) |
|
|
{ |
|
|
return lines[position]; |
|
|
} |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool MoveNext() |
|
|
{ |
|
|
int nextPosition = position + 1; |
|
|
if (nextPosition < lines.Count) |
|
|
{ |
|
|
++position; |
|
|
} |
|
|
return nextPosition < lines.Count; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool MovePrevious() |
|
|
{ |
|
|
if (position >= 0) |
|
|
{ |
|
|
if (position == 0) |
|
|
{ |
|
|
return false; |
|
|
} |
|
|
--position; |
|
|
} |
|
|
return position >= 0; |
|
|
} |
|
|
} |
|
|
} |
|
|
|