|
|
|
@ -12,15 +12,26 @@ namespace ConsoleApp.Menu
|
|
|
|
|
where T : notnull
|
|
|
|
|
{
|
|
|
|
|
protected StringBuilder _screenDisplay;
|
|
|
|
|
protected readonly List<Selector<T>>? _selectList;
|
|
|
|
|
protected List<Selector<T>> _selectList = new List<Selector<T>>();
|
|
|
|
|
|
|
|
|
|
public string Title { get; private set; }
|
|
|
|
|
public StringBuilder InputStr { get; set; }
|
|
|
|
|
public int CurrentLine { get; private set; }
|
|
|
|
|
public T? CurrentSelected { get; private set; }
|
|
|
|
|
|
|
|
|
|
private int _currentLine;
|
|
|
|
|
public int CurrentLine {
|
|
|
|
|
get => _currentLine;
|
|
|
|
|
private set
|
|
|
|
|
{
|
|
|
|
|
_currentLine = value;
|
|
|
|
|
if (_currentLine < 0) _currentLine = 0;
|
|
|
|
|
if (_currentLine >= _selectList.Count) _currentLine = _selectList.Count-1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public T? CurrentSelected { get; protected set; }
|
|
|
|
|
public bool WriteMode { get; set; }
|
|
|
|
|
|
|
|
|
|
private Menu(string title)
|
|
|
|
|
protected Menu(string title)
|
|
|
|
|
{
|
|
|
|
|
Title = title;
|
|
|
|
|
CurrentLine = 0;
|
|
|
|
@ -29,7 +40,7 @@ namespace ConsoleApp.Menu
|
|
|
|
|
InputStr = new StringBuilder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Menu(string title, params Selector<T>[] selections ) : this(title)
|
|
|
|
|
protected Menu(string title, params Selector<T>[] selections ) : this(title)
|
|
|
|
|
{
|
|
|
|
|
if (selections == null || selections.Length == 0)
|
|
|
|
|
throw new ArgumentException("Error: a menu must contain at least 1 selection");
|
|
|
|
@ -40,6 +51,7 @@ namespace ConsoleApp.Menu
|
|
|
|
|
|
|
|
|
|
public virtual void Display()
|
|
|
|
|
{
|
|
|
|
|
Console.Clear();
|
|
|
|
|
Console.WriteLine(_screenDisplay);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -48,14 +60,14 @@ namespace ConsoleApp.Menu
|
|
|
|
|
_screenDisplay.AppendLine($"[ {Title} ]");
|
|
|
|
|
_screenDisplay.AppendLine("-------------------------------------------\n");
|
|
|
|
|
|
|
|
|
|
foreach (Selector<T> selector in _selectList)
|
|
|
|
|
for (int i = 0; i < _selectList.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (selector.Equals(CurrentSelected))
|
|
|
|
|
if (CurrentLine == i)
|
|
|
|
|
_screenDisplay.Append($"> ");
|
|
|
|
|
else
|
|
|
|
|
_screenDisplay.Append($" ");
|
|
|
|
|
|
|
|
|
|
_screenDisplay.AppendLine($"{selector.Line}");
|
|
|
|
|
_screenDisplay.AppendLine($"{_selectList[i].Line}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|