You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.7 KiB
61 lines
1.7 KiB
using ConsoleApp;
|
|
using Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace ConsoleApp
|
|
{
|
|
public class ConsoleMenu : Manager
|
|
{
|
|
public ConsoleMenu(Manager manager)
|
|
{
|
|
AllRecipes = manager.AllRecipes;
|
|
}
|
|
|
|
public Recipe? ResearchOnRecipe()
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
SearcherRecipe searcherRecipe = new SearcherRecipe();
|
|
RecipeCollection result = AllRecipes.ResearchByName(sb.ToString());
|
|
searcherRecipe.UpdateDisplay(sb.ToString(), result);
|
|
|
|
ConsoleKeyInfo cki;
|
|
|
|
do
|
|
{
|
|
cki = Console.ReadKey(true);
|
|
|
|
switch (cki.Key)
|
|
{
|
|
case ConsoleKey.UpArrow:
|
|
searcherRecipe.SelectPrevioustLine();
|
|
break;
|
|
case ConsoleKey.DownArrow:
|
|
searcherRecipe.SelectNextLine();
|
|
break;
|
|
case ConsoleKey.Backspace:
|
|
if (sb.Length > 0)
|
|
{
|
|
sb.Remove(sb.Length - 1, 1);
|
|
result = AllRecipes.ResearchByName(sb.ToString());
|
|
}
|
|
break;
|
|
default:
|
|
sb.Append(cki.KeyChar);
|
|
result = AllRecipes.ResearchByName(sb.ToString());
|
|
break;
|
|
}
|
|
|
|
searcherRecipe.UpdateDisplay(sb.ToString(), result);
|
|
|
|
} while (cki.Key != ConsoleKey.Enter);
|
|
|
|
return searcherRecipe.CurrentSelected;
|
|
}
|
|
}
|
|
}
|