diff --git a/src/BitzArt.Console/Menus/ConsoleMenu.cs b/src/BitzArt.Console/Menus/ConsoleMenu.cs index ea9b310..c50e94c 100644 --- a/src/BitzArt.Console/Menus/ConsoleMenu.cs +++ b/src/BitzArt.Console/Menus/ConsoleMenu.cs @@ -21,9 +21,24 @@ public Task RunAsync() protected virtual void Render() { AnsiConsole.Clear(); + OnBeforeDisplay(); + Display(); + OnDisplayed(); + } + + protected virtual void OnBeforeDisplay() + { + } + + protected virtual void Display() + { AnsiConsoleMenu.WriteTitle(Title!); } + protected virtual void OnDisplayed() + { + } + public async Task RunAsync() where TConsoleMenu : class { var navigationManager = App!.Services.GetRequiredService(); diff --git a/src/BitzArt.Console/Menus/ConsoleSelectionMenu.cs b/src/BitzArt.Console/Menus/ConsoleSelectionMenu.cs index 0885ebc..a04fea3 100644 --- a/src/BitzArt.Console/Menus/ConsoleSelectionMenu.cs +++ b/src/BitzArt.Console/Menus/ConsoleSelectionMenu.cs @@ -5,6 +5,7 @@ namespace BitzArt.Console; public abstract class ConsoleSelectionMenu : ConsoleMenu { protected virtual List SelectionItems { get; set; } = []; + private bool _exiting = false; public void AddSubmenu(string? selectionName = null) where TMenu : class @@ -22,28 +23,33 @@ protected override void Render() { while(true) { - AnsiConsole.Clear(); - - var selectionPrompt = new SelectionPrompt().Title($"[green]{Title}[/]"); + if (_exiting) break; + base.Render(); + } + } - selectionPrompt.AddChoices(SelectionItems); + protected override void Display() + { + var selectionPrompt = new SelectionPrompt().Title($"[green]{Title}[/]"); - var backSelectionOption = IsMainMenu!.Value ? ConsoleSelectionMenuItem.ExitItem : ConsoleSelectionMenuItem.BackItem; - selectionPrompt.AddChoice(backSelectionOption); + selectionPrompt.AddChoices(SelectionItems); - var selected = selectionPrompt.Show(AnsiConsole.Console); + var backSelectionOption = IsMainMenu!.Value ? ConsoleSelectionMenuItem.ExitItem : ConsoleSelectionMenuItem.BackItem; + selectionPrompt.AddChoice(backSelectionOption); - if (selected.IsExit) - { - OnExit(); - return; - } + var selected = selectionPrompt.Show(AnsiConsole.Console); - OnBeforeSelectionInvoke(selected); - InvokeSelection(selected); - OnSelection(selected); - OnAfterSelectionInvoked(selected); + if (selected.IsExit) + { + _exiting = true; + OnExit(); + return; } + + OnBeforeSelectionInvoke(selected); + InvokeSelection(selected); + OnSelection(selected); + OnAfterSelectionInvoked(selected); } public virtual void OnBeforeSelectionInvoke(ConsoleSelectionMenuItem selection)