first version of entry menu (working)
continuous-integration/drone/push Build is passing Details

pull/38/head
Alexandre AGOSTINHO 2 years ago
parent 65a3c8feea
commit d0146a0e14

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp.Menu
{
internal class ConnectionMenu : Entry
{
public ConnectionMenu(params EntryStep[] entrySteps)
: base("Connection", entrySteps)
{ }
public override IMenu? Return()
{
string username = _selectList[0].Item.Input;
string password = _selectList[1].Item.Input;
return new PlainText($"User: {username} connected with password: {password}");
}
}
}

@ -13,22 +13,17 @@ namespace ConsoleApp.Menu
private Type _entryType;
public string Description { get; private set; }
public string? Input { get; private set; }
public string Input { get; internal set; }
internal EntryStep(string description, Type type)
{
Description = description;
Input = null;
Input = "";
_entryType = type;
}
public object GetEntry()
{
Input = Console.ReadLine();
if (Input is null)
throw new ArgumentException("Error: input is null.");
try
{
if (_entryType == typeof(string))

@ -8,27 +8,95 @@ namespace ConsoleApp.Menu
{
internal abstract partial class Entry : Menu<Entry.EntryStep>
{
private List<Selector<EntryStep>> _allSelectors;
private List<EntryStep> _steps = new List<EntryStep>();
protected Entry(string title) : base(title)
protected Entry(string title, params EntryStep[] entrySteps) : base(title)
{
_allSelectors = _selectList;
_steps = entrySteps.ToList();
_allSelectors = ConvertEntryStepsInSelector();
_selectList = _allSelectors;
}
protected override List<Selector<EntryStep>> SearchInSelection()
private List<Selector<EntryStep>> ConvertEntryStepsInSelector()
{
return _allSelectors;
List<Selector<EntryStep>> newSelectors = new List<Selector<EntryStep>>();
foreach (EntryStep step in _steps)
{
newSelectors.Add(new Selector<EntryStep>(step, step.Description));
}
return newSelectors;
}
public override IMenu? Return()
public override void WriteMenuMode(ConsoleKeyInfo cki)
{
if (CurrentSelected == null)
throw new Exception("Error: CurrentSelected is null.");
if (!WriteMode && cki.Key == ConsoleKey.R)
{
EnableWriteMode();
return;
}
if (WriteMode)
{
if (cki.Key == ConsoleKey.Escape)
{
if (CurrentSelected is null)
throw new Exception("Error: CurrentSelected is null.");
return null;
CurrentSelected.Input = InputStr.ToString();
DisableWriteMode();
InputStr.Clear();
return;
}
if (cki.Key == ConsoleKey.Backspace && InputStr.Length > 0)
{
InputStr.Remove(InputStr.Length - 1, 1);
return;
}
InputStr.Append(cki.KeyChar);
}
}
public override void Update()
{
if (_selectList == null || _selectList.Count == 0)
{
CurrentSelected = default;
return;
}
CurrentSelected = _selectList[CurrentLine].Item;
}
public override void Display()
{
_screenDisplay.Clear();
Console.Clear();
_screenDisplay.AppendLine($"[ {Title} ]");
_screenDisplay.AppendLine("-------------------------------------------");
for (int i = 0; i < _selectList.Count; i++)
{
if (CurrentLine == i)
_screenDisplay.Append($"> ");
else
_screenDisplay.Append($" ");
_screenDisplay.Append($"{_selectList[i].Line} {_selectList[i].Item.Input}");
if (CurrentLine == i && WriteMode)
_screenDisplay.Append(InputStr.ToString());
_screenDisplay.AppendLine();
}
if (_selectList == null || _selectList.Count == 0)
_screenDisplay.AppendLine("Empty...");
_screenDisplay.AppendLine(
"\n\nHint:\n^:previous, v:next, <:ret, -enter-:return, r:write, -escape-:exit search mode");
Console.WriteLine(_screenDisplay);
}
}
}

@ -21,7 +21,8 @@ namespace ConsoleApp.Menu
public StringBuilder InputStr { get; set; }
private int _currentLine;
public int CurrentLine {
public int CurrentLine
{
get
{
if (_currentLine >= _selectList.Count) _currentLine = _selectList.Count - 1;
@ -71,7 +72,7 @@ namespace ConsoleApp.Menu
x.Line.ToLower().Contains(InputStr.ToString().ToLower()));
}
public void WriteMenuMode(ConsoleKeyInfo cki)
public virtual void WriteMenuMode(ConsoleKeyInfo cki)
{
if (!WriteMode && cki.Key == ConsoleKey.R)
{
@ -98,7 +99,7 @@ namespace ConsoleApp.Menu
}
}
public void Update()
public virtual void Update()
{
_selectList = SearchInSelection();
@ -138,7 +139,7 @@ namespace ConsoleApp.Menu
_screenDisplay.AppendLine("Empty...");
_screenDisplay.AppendLine(
"\n\nHint:\n^:previous, v:next, <:ret, -enter-:select, r:search mode, -escape-:exit search mode");
"\n\nHint:\n^:previous, v:next, <:ret, -enter-:select, r:search, -escape-:exit search mode");
Console.WriteLine(_screenDisplay);
}

@ -22,7 +22,10 @@ if (allRecipe == null)
DataManager dataMgr = new DataManager(allRecipe);
MenuManager menuMgr = new MenuManager(dataMgr, new SearcherRecipe(dataMgr.AllRecipes));
MenuManager menuMgr = new MenuManager(dataMgr, new ConnectionMenu(
new Entry.EntryStep("Username: ", typeof(string)),
new Entry.EntryStep("Password: ", typeof(string))));
menuMgr.Loop();
// press any key to quit

Loading…
Cancel
Save