public ProjectInformation?Select() { var examples = _finder.FindExamples(); if (examples.Count == 0) { _console.Markup("[yellow]No examples could be found.[/]"); return(null); } var prompt = new SelectionPrompt <string>(); var groups = examples.GroupBy(ex => ex.Group); if (groups.Count() == 1) { prompt.AddChoices(examples.Select(x => x.Name)); } else { var noGroupExamples = new List <string>(); foreach (var group in groups) { if (string.IsNullOrEmpty(group.Key)) { noGroupExamples.AddRange(group.Select(x => x.Name)); } else { prompt.AddChoiceGroup( group.Key, group.Select(x => x.Name)); } } if (noGroupExamples.Count > 0) { prompt.AddChoices(noGroupExamples); } } var example = AnsiConsole.Prompt(prompt .Title("[yellow]Choose example to run[/]") .MoreChoicesText("[grey](Move up and down to reveal more examples)[/]") .Mode(SelectionMode.Leaf)); return(examples.FirstOrDefault(x => x.Name == example)); }
public static Installation?GetTargetInstallation(string?path, string promptTitle) { var installations = new List <Installation>(); AnsiConsole .Status() .Start("Discovering [green]Escape From Tarkov[/] installations...", _ => { installations = Installation .DiscoverInstallations() .Distinct() .ToList(); }); if (path is not null && Installation.TryDiscoverInstallation(path, out var installation)) { installations.Add(installation); } installations = installations .Distinct() .OrderBy(i => i.Location) .ToList(); switch (installations.Count) { case 0: AnsiConsole.MarkupLine("[yellow]No [green]EscapeFromTarkov[/] installation found, please re-run this installer, passing the installation path as argument.[/]"); return(null); case 1: var first = installations.First(); return(AnsiConsole.Confirm($"Continue with [green]EscapeFromTarkov ({first.Version})[/] in [blue]{first.Location}[/] ?") ? first : null); default: var prompt = new SelectionPrompt <Installation> { Converter = i => i.Location, Title = promptTitle }; prompt.AddChoices(installations); return(AnsiConsole.Prompt(prompt)); } }
private static Installation?GetTargetInstallation(Settings settings) { var installations = new List <Installation>(); AnsiConsole .Status() .Start("Discovering [green]Escape From Tarkov[/] installations...", _ => { installations = Installation .DiscoverInstallations() .Distinct() .ToList(); }); if (settings.Path is not null && Installation.TryDiscoverInstallation(settings.Path, out var installation)) { installations.Add(installation); } installations = installations .Distinct() .OrderBy(i => i.Location) .ToList(); switch (installations.Count) { case 0: AnsiConsole.MarkupLine("[yellow]No [green]EscapeFromTarkov[/] installation found, please re-run this installer, passing the installation path as argument.[/]"); return(null); case 1: return(installations.First()); default: var prompt = new SelectionPrompt <Installation> { Converter = i => i.Location, Title = "Please select where to install the trainer" }; prompt.AddChoices(installations); return(AnsiConsole.Prompt(prompt)); } }
public static string?RenderPrompt(int uxLevel, Selector selector) { if (uxLevel == 0) { DisplayLegacyStyle(selector); return(null); } var prompt = new SelectionPrompt <string>().Title($"Select the {selector.ItemTypeName} you'd like to use") .PageSize(10); var selectorItems = selector.Items.Select(x => (x.Common ? "*" : "") + x.Value); if (selector.Sorted) { selectorItems = selectorItems.OrderBy(x => x); } prompt.AddChoices(selectorItems); var selectedItem = AnsiConsole.Prompt(prompt); if (selectedItem.StartsWith("*")) { selectedItem = selectedItem[1..];