コード例 #1
0
        private static void GenerateNames()
        {
            var factions = FactionData.Factions.ToList();

            var faction = AnsiConsole.Prompt(
                new SelectionPrompt <string>()
                .Title("Select your faction:")
                .AddChoices(factions.Select(f => f.Name)));

            var numberOfNames = AnsiConsole.Prompt(
                new SelectionPrompt <int>()
                .Title("How many names to generate?")
                .AddChoices(Enumerable.Range(1, 20)));

            var selectedFaction = factions.First(f => f.Name == faction);

            var results = new Table
            {
                Title = new TableTitle($"Names for {selectedFaction.Name}")
            };

            results.AddColumn("Name");

            foreach (var name in selectedFaction.GenerateNames(numberOfNames))
            {
                results.AddRow(name);
            }

            AnsiConsole.Render(results);
        }
コード例 #2
0
        private static Employes CreateEmployees()
        {
            var configurations = Configuration.ValidateConfiguration();

            string name = AnsiConsole.Ask <string>("Ingrese : [green]nombre[/]?");

            string idCard = AnsiConsole.Ask <string>("Ingrese : [green]identificacion[/]?");

            int birthdate = AnsiConsole.Ask <int>("Ingrese : [green]fecha nacimiento[/]?");

            var city = AnsiConsole.Prompt(
                new SelectionPrompt <string>()
                .Title("Ingrese : [green]ciudad[/]?")
                .PageSize(10)
                .AddChoices(Cities));

            string address = AnsiConsole.Ask <string>("Ingrese : [green]direccion[/]?");

            string phone = AnsiConsole.Ask <string>("Ingrese : [green]telefono[/]?");

            string position = AnsiConsole.Ask <string>("Ingrese : [green]cargo[/]?");

salary:
            int salary = AnsiConsole.Ask <int>("Ingrese : [green]salario[/]?");

            if (salary < configurations.Salary)
            {
                Console.WriteLine($"Salario ${salary} no permitido, ingrese un salario mayor o igual a {configurations.Salary}");
                goto salary;
            }

            return(new Employes(name, idCard, birthdate, city, address, phone, position, salary));
        }
コード例 #3
0
ファイル: GameShell.cs プロジェクト: kesac/WorldGM
        private void GameLoop()
        {
            var header = new Rule($"\n[grey]World of {this.Game.World.Name}[/]")
                         .RuleStyle(Style.Parse("white dim"))
                         .LeftAligned();

            AnsiConsole.Write(header);

            AnsiConsole.MarkupLine("[green]You are currently in the city of {0}.[/]", this.Game.HomeCity.Name);
            AnsiConsole.MarkupLine("[green]There are {0} members in your guild.[/]", this.Game.GuildMembers.Count);

            string input = string.Empty;

            while (input != "exit")
            {
                AnsiConsole.Write(new Rule());

                input = AnsiConsole.Prompt(this.IngameMenu).ToLower();

                if (input == "save")
                {
                    this.SaveGame();
                }
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            var WorkPath = "";

            if (args.Length > 0 && Directory.Exists(args[0]))
            {
                WorkPath = args[0];
                Console.WriteLine($"Current WorkPath: {WorkPath}");
            }

            methods = new Dictionary <string, Func <IExecutor> >
            {
                { nameof(FolderRestructurer), () => new FolderRestructurer(WorkPath) },
                { nameof(SanitySanitizer), () => new SanitySanitizer(WorkPath) }
            };

            var resultInspect = AnsiConsole.Prompt(
                new MultiSelectionPrompt <KeyValuePair <string, Func <IExecutor> > >()
                .Title("Please select the Method you want to run")
                .PageSize(10)
                .AddChoices(methods.ToArray())
                .UseConverter(c => c.Key));

            foreach (var item in resultInspect)
            {
                Console.WriteLine($"{item.Key}");
                item.Value().Run();
            }
        }
        public void CollectInput(ScaffolderContext context)
        {
            var option = AnsiConsole.Prompt(
                new SelectionPrompt <string>()
                .Title("Which type of endpoint would you like to add?")
                .AddChoices(new[] {
                Create,
                Update,
                Delete,
                CreateSubEndpoint,
                UpdateSubEndpoint,
                DeleteSubEndpoint
            }));

            var commandEndpointTypes = option switch
            {
                Create => CommandEndpointTypes.Create,
                Update => CommandEndpointTypes.Update,
                Delete => CommandEndpointTypes.Delete,
                CreateSubEndpoint => CommandEndpointTypes.CreateSubEndpoint,
                UpdateSubEndpoint => CommandEndpointTypes.UpdateSubEndpoint,
                DeleteSubEndpoint => CommandEndpointTypes.DeleteSubEndpoint,
                _ => throw new Exception($"Invalid option {option}"),
            };

            context.Variables.Set(Constants.CommandEndpointType, commandEndpointTypes);
        }
コード例 #6
0
        private async Task <bool> RunContinuously(ProjectionInput input, DocumentStore store)
        {
            var shards = input.BuildShards(store);

            if (input.InteractiveFlag)
            {
                var all = store.Options.Projections.All.Where(x => x.Lifecycle != ProjectionLifecycle.Live).SelectMany(x => x.AsyncProjectionShards(store))
                          .Select(x => x.Name.Identity).ToArray();

                var prompt = new MultiSelectionPrompt <string>()
                             .Title("Choose projection shards to run continuously")
                             .AddChoices(all);

                var selections = AnsiConsole.Prompt(prompt);
                shards = store.Options.Projections.All.SelectMany(x => x.AsyncProjectionShards(store))
                         .Where(x => selections.Contains(x.Name.Identity)).ToList();
            }


            if (!shards.Any())
            {
                Console.WriteLine(input.ProjectionFlag.IsEmpty()
                    ? "No projections are registered with an asynchronous life cycle."
                    : $"No projection or projection shards match the requested filter '{input.ProjectionFlag}'");

                Console.WriteLine();
                WriteProjectionTable(store);

                return(true);
            }

            var assembly = Assembly.GetEntryAssembly();

            AssemblyLoadContext.GetLoadContext(assembly).Unloading += context => Shutdown();

            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                Shutdown();
                eventArgs.Cancel = true;
            };

            var shutdownMessage = "Press CTRL + C to quit";

            Console.WriteLine(shutdownMessage);


            var daemon = store.BuildProjectionDaemon();

            daemon.Tracker.Subscribe(new ProjectionWatcher(_completion.Task, shards));

            foreach (var shard in shards)
            {
                await daemon.StartShard(shard, _cancellation.Token);
            }


            await _completion.Task;

            return(false);
        }
コード例 #7
0
        private static IExample GetExampleFromPromptChoice(IServiceScope serviceScope)
        {
            var choice = AnsiConsole.Prompt(
                new TextPrompt <int>("Which example do you want to run (0 for exit) ?")
                .InvalidChoiceMessage("[red]That's not a valid choice[/]")
                .DefaultValue(0)
                .AddChoice(1)
                .AddChoice(2)
                .AddChoice(3)
                .AddChoice(4));

            if (choice == 0)
            {
                if (AnsiConsole.Capabilities.SupportLinks)
                {
                    var link = @"https://github.com/aimenux/SpectreDemo";
                    AnsiConsole.MarkupLine($"[link={link}]Click to go to github repo[/]!");
                }

                return(null);
            }

            var examples = serviceScope.ServiceProvider.GetServices <IExample>().ToList();

            return(examples.SingleOrDefault(x => x.GetType().Name.EndsWith($"{choice}")));
        }
コード例 #8
0
        private bool ReadActiveServices()
        {
            var useForDownload = AnsiConsole.Confirm("Do you want to use pdbMate to add downloads to your usenet client?");

            if (useForDownload)
            {
                var allowedQualities = AnsiConsole.Prompt(
                    new MultiSelectionPrompt <string>()
                    .Title("What [green]video quality[/] do you want to download?")
                    .InstructionsText(
                        "[grey](Press [blue]<space>[/] to toggle a quality, " +
                        "[green]<enter>[/] to accept)[/]")
                    .AddChoices(new[] {
                    "1080p", "2160p"
                }));

                var keepOnlyHighestQuality = AnsiConsole.Confirm("When downloading from usenet, only keep the highest quality of the same release?");
                var downloadFavoriteActors = AnsiConsole.Confirm("Add downloads based on your favorite actors?");
                var downloadFavoriteSites  = AnsiConsole.Confirm("Add downloads based on your favorite sites?");

                if (!downloadFavoriteActors && !downloadFavoriteSites)
                {
                    AnsiConsole.MarkupLine($"[red]You do not want to add downloads based on your [bold]favorite actors OR sites[/] - pdbMate would not add any downloads - let's start from the beginning.[/]");
                    ReadActiveServices();
                }

                appSettings.UsenetDownload.AllowedQualities       = allowedQualities;
                appSettings.UsenetDownload.KeepOnlyHighestQuality = keepOnlyHighestQuality;
                appSettings.UsenetDownload.DownloadFavoriteSites  = downloadFavoriteSites;
                appSettings.UsenetDownload.DownloadFavoriteActors = downloadFavoriteActors;
            }

            return(useForDownload);
        }
コード例 #9
0
        public static async Task Main(string[] args)
        {
            AnsiConsole.Write(new FigletText("QuickBullet").LeftAligned());

            await GenerateSettingsFile();

            GenerateConfigsFolder();

            GenerateWordlistsFolder();

            Microsoft.Playwright.Program.Main(new string[] { "install" });

            if (args.Any())
            {
                await Parser.Default.ParseArguments <RunOptions>(args).WithParsedAsync(RunAsync);
            }
            else
            {
                var configFiles = GetAllConfigFiles();

                var wordlistsFiles = GetAllWordlistsFiles();

                var config = AnsiConsole.Prompt(new SelectionPrompt <string>()
                                                .Title("Select config:")
                                                .AddChoices(configFiles.Select(c => Path.GetFileNameWithoutExtension(c))));

                var wordlists = AnsiConsole.Prompt(new SelectionPrompt <string>()
                                                   .Title("Select wordlists:")
                                                   .AddChoices(wordlistsFiles.Select(c => Path.GetFileNameWithoutExtension(c))));

                var runOptions = new RunOptions
                {
                    ConfigFile   = Path.Combine(ConfigsFolder, $"{config}.loli"),
                    WordlistFile = Path.Combine(WordlistsFolder, $"{wordlists}.txt")
                };

                runOptions.ProxiesFile = AnsiConsole.Ask("proxies file", "none");

                runOptions.ProxiesType = runOptions.ProxiesFile.Equals("none") ? string.Empty : AnsiConsole.Prompt(new SelectionPrompt <string>()
                                                                                                                   .Title("proxies type")
                                                                                                                   .AddChoices(new string[] { "http", "socks4", "socks5" }));

                runOptions.Skip = AnsiConsole.Ask("skip", -1);

                var bots = AnsiConsole.Ask("bots", 1);

                while (bots > 200)
                {
                    AnsiConsole.MarkupLine("[red]The number of bots must be less than 200[/]");

                    bots = AnsiConsole.Ask("bots", 1);
                }

                runOptions.Bots = bots;

                runOptions.Verbose = AnsiConsole.Ask("verbose:", false);

                await RunAsync(runOptions);
            }
        }
コード例 #10
0
        private static string AskFruit()
        {
            AnsiConsole.WriteLine();
            AnsiConsole.Render(new Rule("[yellow]Lists[/]").RuleStyle("grey").LeftAligned());

            var favorites = AnsiConsole.Prompt(
                new MultiSelectionPrompt <string>()
                .PageSize(10)
                .Title("What are your [green]favorite fruits[/]?")
                .AddChoices(new[]
            {
                "Apple", "Apricot", "Avocado", "Banana", "Blackcurrant", "Blueberry",
                "Cherry", "Cloudberry", "Cocunut", "Date", "Dragonfruit", "Durian",
                "Egg plant", "Elderberry", "Fig", "Grape", "Guava", "Honeyberry",
                "Jackfruit", "Jambul", "Kiwano", "Kiwifruit", "Lime", "Lylo",
                "Lychee", "Melon", "Mulberry", "Nectarine", "Orange", "Olive"
            }));

            var fruit = favorites.Count == 1 ? favorites[0] : null;

            if (string.IsNullOrWhiteSpace(fruit))
            {
                fruit = AnsiConsole.Prompt(
                    new SelectionPrompt <string>()
                    .Title("Ok, but if you could only choose [green]one[/]?")
                    .AddChoices(favorites));
            }

            AnsiConsole.MarkupLine("Your selected: [yellow]{0}[/]", fruit);
            return(fruit);
        }
コード例 #11
0
        private void ReadApiKey()
        {
            var apikey = AnsiConsole.Prompt(
                new TextPrompt <string>($"Enter your [green]apikey[/] for {appSettings.PdbApi.BaseUrl}:")
                .PromptStyle("green")
                .ValidationErrorMessage("[red]That's not a valid apikey[/]")
                .Validate(apikey =>
            {
                if (apikey.Length != 32)
                {
                    return(ValidationResult.Error("[red]The apikey must be 32 characters long[/]"));
                }

                if (!IsApiKeyValid(apikey))
                {
                    return(ValidationResult.Error($"[red]Failed to connect to {appSettings.PdbApi.BaseUrl} with your apikey[/]"));
                }

                return(ValidationResult.Success());
            }));

            appSettings.PdbApi.ApiKey = apikey;
            pdbApiService.setOptions(Options.Create(new PdbApiServiceOptions()
            {
                BaseUrl = appSettings.PdbApi.BaseUrl,
                Apikey  = appSettings.PdbApi.ApiKey
            }));

            AnsiConsole.MarkupLine("[green]Successfully[/] connected with your apikey");
        }
コード例 #12
0
            private string SelectCsProj()
            {
                var csprojFiles = FileSystem.Directory.GetFiles(".", "*.csproj");

                if (csprojFiles.Length == 1)
                {
                    return(csprojFiles.First());
                }

                if (csprojFiles.Length == 0)
                {
                    AnsiConsole.Write(new Markup($"[bold red]Can't find a project file in current directory![/]"));
                    AnsiConsole.WriteLine();
                    AnsiConsole.Write(new Markup($"[bold red]Please run Sergen in a folder that contains the Asp.Net Core project.[/]"));
                    AnsiConsole.WriteLine();
                    return(null);
                }

                AnsiConsole.WriteLine();
                AnsiConsole.Write(new Spectre.Console.Rule($"[bold orange1]Please select an Asp.Net Core project file[/]")
                {
                    Alignment = Justify.Left
                });
                AnsiConsole.WriteLine();
                var selections = new SelectionPrompt <string>()
                                 .PageSize(10)
                                 .MoreChoicesText("[grey](Move up and down to reveal more project files)[/]")
                                 .AddChoices(csprojFiles);

                return(AnsiConsole.Prompt(selections));
            }
コード例 #13
0
            private (IEnumerable <TableName> selectedTables, List <TableName> tableNames) SelectedTables(ISqlConnections sqlConnections, string connectionKey)
            {
                ISchemaProvider  schemaProvider;
                List <TableName> tableNames;

                using (var connection = sqlConnections.NewByKey(connectionKey))
                {
                    schemaProvider = SchemaHelper.GetSchemaProvider(connection.GetDialect().ServerType);
                    tableNames     = schemaProvider.GetTableNames(connection).ToList();
                }

                var tables = tableNames.Select(x => x.Tablename).ToList();

                var selectedTableNames = AnsiConsole.Prompt(
                    new MultiSelectionPrompt <string>()
                    .Title("[steelblue1]Select tables for code generation (single/multiple)[/]")
                    .PageSize(10)
                    .MoreChoicesText("[grey](Move up and down to reveal more tables)[/]")
                    .InstructionsText(
                        "[grey](Press [blue]<space>[/] to select/unselect, " +
                        "[green]<enter>[/] to accept)[/]")
                    .AddChoices(tables));

                var selectedTables = tableNames.Where(s => selectedTableNames.Contains(s.Tablename));

                return(selectedTables, tableNames);
            }
コード例 #14
0
ファイル: GameShell.cs プロジェクト: kesac/WorldGM
        public void Start()
        {
            System.Console.Clear();

            var header = new Rule("[grey]WorldGM v0.1[/]")
                         .RuleStyle(Style.Parse("white dim"))
                         .LeftAligned();

            AnsiConsole.Write(header);

            var choice = AnsiConsole.Prompt(this.MainMenu);

            if (choice == "New")
            {
                this.GenerateNewWorld();
            }
            else if (choice == "Load")
            {
                this.LoadExistingWorld();
            }
            else
            {
                // Exit
            }
        }
コード例 #15
0
        private void ReadSabnzbd()
        {
            var hostname = AnsiConsole.Prompt(
                new TextPrompt <string>($"Enter [green]hostname[/] for sabnzbd (e.g. localhost):")
                .PromptStyle("green")
                .ValidationErrorMessage("[red]That's not a valid hostname[/]")
                .Validate(hostname =>
            {
                if (hostname.Contains(':'))
                {
                    return(ValidationResult.Error("[red]Do not provide http or the port in the hostname[/]"));
                }

                return(ValidationResult.Success());
            }));

            var useSsl = AnsiConsole.Confirm("Using SSL to connect?");

            hostname = $"http{(useSsl ? "s" : "")}://" + hostname;

            var port = AnsiConsole.Prompt(
                new TextPrompt <int>($"Enter [green]port[/] for sabnzbd (e.g. 8080):")
                .PromptStyle("green")
                .ValidationErrorMessage("[red]That's not a valid port[/]")
                .Validate(port =>
            {
                if (port == 0)
                {
                    return(ValidationResult.Error("[red]Port 0 is not a valid port[/]"));
                }

                return(ValidationResult.Success());
            }));

            hostname = hostname + ":" + port + "/sabnzbd/api";

            var apikey = AnsiConsole.Prompt(
                new TextPrompt <string>($"Enter [green]apikey[/] for sabnzbd:")
                .PromptStyle("green")
                .ValidationErrorMessage("[red]That's not a valid apikey[/]")
                .Validate(apikey =>
            {
                if (apikey.Length != 32)
                {
                    return(ValidationResult.Error("[red]The apikey must be 32 characters long[/]"));
                }

                return(ValidationResult.Success());
            }));

            if (!IsConnectionSabnzbdSuccessful(hostname, apikey))
            {
                AnsiConsole.MarkupLine($"[red]Cound not connect to sabnzbd on url: {hostname} - let's start from the beginning.[/]");
                ReadDownloadClient();
            }

            appSettings.Sabnzbd.Url    = hostname;
            appSettings.Sabnzbd.ApiKey = apikey;
        }
コード例 #16
0
 private static PlayerAction GetPlayerAction(PlayerAction[] choices, Player player)
 {
     return(AnsiConsole.Prompt(new SelectionPrompt <PlayerAction>()
                               .Title($"[bold blue]Action for {player}[/]")
                               .AddChoices(choices)
                               .HighlightStyle(new Style(Color.Green, decoration: Decoration.Bold))
                               ));
 }
コード例 #17
0
        private void ReadNzbget()
        {
            var hostname = AnsiConsole.Prompt(
                new TextPrompt <string>($"Enter [green]hostname[/] for nzbget (e.g. localhost):")
                .PromptStyle("green")
                .ValidationErrorMessage("[red]That's not a valid hostname[/]")
                .Validate(hostname =>
            {
                if (hostname.Contains(':'))
                {
                    return(ValidationResult.Error("[red]Do not provide http or the port in the hostname[/]"));
                }

                return(ValidationResult.Success());
            }));

            var useSsl = AnsiConsole.Confirm("Using SSL to connect?");

            var port = AnsiConsole.Prompt(
                new TextPrompt <int>($"Enter [green]port[/] for sabnzbd (e.g. 8080):")
                .PromptStyle("green")
                .ValidationErrorMessage("[red]That's not a valid port[/]")
                .Validate(port =>
            {
                if (port == 0)
                {
                    return(ValidationResult.Error("[red]Port 0 is not a valid port[/]"));
                }

                return(ValidationResult.Success());
            }));

            var useAuth = AnsiConsole.Confirm("Do you need to specify username and password for accessing nzbget?");

            var username = "";
            var password = "";

            if (useAuth)
            {
                username = AnsiConsole.Prompt(new TextPrompt <string>($"Enter [green]username[/] for nzbget:")
                                              .PromptStyle("green").AllowEmpty());

                password = AnsiConsole.Prompt(new TextPrompt <string>($"Enter [green]password[/] for nzbget:")
                                              .PromptStyle("green").AllowEmpty());
            }

            if (!IsConnectionNzbgetSuccessful(hostname, port, username, password, useSsl))
            {
                AnsiConsole.MarkupLine($"[red]Cound not connect to nzbget on url: {hostname} - let's start from the beginning.[/]");
                ReadDownloadClient();
            }

            appSettings.Nzbget.Username = username;
            appSettings.Nzbget.Password = password;
            appSettings.Nzbget.Hostname = hostname;
            appSettings.Nzbget.Port     = port;
            appSettings.Nzbget.UseHttps = useSsl;
        }
コード例 #18
0
        public string ShowCategories()
        {
            var select = AnsiConsole.Prompt(
                new SelectionPrompt <string>()
                .Title("Please choose an option:")
                .PageSize(10)
                .MoreChoicesText("[grey](Move up and down to reveal more options)[/]")
                .AddChoice("Cables & Connectors")
                .AddChoice("Components")
                .AddChoice("Peripherals")
                .AddChoice("Displays")
                .AddChoice("Networking")
                .AddChoice("Desktop & Laptop Systems")
                .AddChoice("Finalise Order")
                .AddChoice("Exit"));
            var catChoice = "";

            switch (select)
            {
            case "Cables & Connectors":     // Case should use single quotes
                catChoice = "1";
                break;

            case "Components":
                catChoice = "2";
                break;

            case "Peripherals":
                catChoice = "3";
                break;

            case "Displays":
                catChoice = "4";
                break;

            case "Networking":
                catChoice = "5";
                break;

            case "Desktop & Laptop Systems":
                catChoice = "6";
                break;

            case "Finalise Order":
                this.FinaliseOrder(this.ShowOrder());
                Console.WriteLine("Order closed, press any key to return to main menu");
                catChoice = "X";
                Console.ReadKey();
                break;

            default:
                Console.WriteLine("Order cancelled, press any key to return to main menu");
                Console.ReadKey();
                catChoice = "X";
                break;
            }
            return(catChoice);
        }
コード例 #19
0
        public static T Choose <T>(IEnumerable <T> items, string title)
        {
            var selection = new SelectionPrompt <T>()
                            .Title(title)
                            .PageSize(10)
                            .AddChoices(items);

            return(AnsiConsole.Prompt(selection));
        }
コード例 #20
0
        public static string ReadPasswordFromConsole()
        {
            string password = AnsiConsole.Prompt(
                new TextPrompt <string>("Enter [green]password[/]")
                .PromptStyle("red")
                .Secret());

            return(password);
        }
コード例 #21
0
 public static string GetMainMenuChoice()
 {
     return(AnsiConsole.Prompt(
                new SelectionPrompt <string>()
                .Title("[green]What would you like to do[/]?")
                .PageSize(5)
                .MoreChoicesText("[grey](Move up and down to reveal more choices)[/]")
                .AddChoices("Extract game data", "Parse extracted game data", "Install High-Res patch",
                            "Uninstall High-Res patch", "Launch Arcanum.exe")));
 }
コード例 #22
0
        public override Answer ask()
        {
            var response = AnsiConsole.Prompt(
                new TextPrompt <string>(Question)
                .InvalidChoiceMessage("[red]Please answer yes or no[/]")
                .AddChoice("yes")
                .AddChoice("no"));

            return(new SingleChoiceAnswer(this, "voterName", response == "yes"));
        }
コード例 #23
0
 public static string AskSport()
 {
     return(AnsiConsole.Prompt(
                new TextPrompt <string>("What's your [green]favorite sport[/]?")
                .InvalidChoiceMessage("[red]That's not a sport![/]")
                .DefaultValue("Sport?")
                .AddChoice("Soccer")
                .AddChoice("Hockey")
                .AddChoice("Basketball")));
 }
コード例 #24
0
        private static string PromptForSecret(string title, int?minLength = null)
        {
            Assert.False(title.EndsWith(':'));

            return(AnsiConsole.Prompt(
                       new TextPrompt <string>($"{title}:")
                       .Secret()
                       .Validate(x => minLength == null || x.Length >= minLength,
                                 message: $"Secret must be at least {minLength} characters long")));
        }
コード例 #25
0
        public string GetOption(string title, string[] options)
        {
            Console.Clear();
            var choice = AnsiConsole.Prompt(
                new SelectionPrompt <string>()
                .Title(title)
                .PageSize(10)
                .AddChoices(options));

            return(choice);
        }
コード例 #26
0
        private static string AskExampleType()
        {
            var exampleTypes = ExampleType.List.Select(e => e.Name);

            return(AnsiConsole.Prompt(
                       new SelectionPrompt <string>()
                       .Title("What [green]type of example[/] do you want to create?")
                       .PageSize(50)
                       .AddChoices(exampleTypes)
                       ));
        }
コード例 #27
0
        private static string AskSport()
        {
            AnsiConsole.WriteLine();
            AnsiConsole.Render(new Rule("[yellow]Choices[/]").RuleStyle("grey").LeftAligned());

            return(AnsiConsole.Prompt(
                       new TextPrompt <string>("What's your [green]favorite sport[/]?")
                       .InvalidChoiceMessage("[red]That's not a valid fruit[/]")
                       .DefaultValue("Lol")
                       .AddChoice("Soccer")
                       .AddChoice("Hockey")
                       .AddChoice("Basketball")));
        }
コード例 #28
0
        public override Answer ask()
        {
            var prompt = new TextPrompt <string>(Question)
                         .InvalidChoiceMessage("[red]That's not a valid option[/]");

            foreach (var o in Options)
            {
                prompt.AddChoice(o);
            }
            var response = AnsiConsole.Prompt(prompt);

            return(new MultipleChoiceAnswer(this, "voterName", response));
        }
コード例 #29
0
ファイル: Setup.cs プロジェクト: thomasrosted/MuteLight
        public static async Task Lights(Config config, HueConnector hueConnector)
        {
            var lights = await hueConnector.GetLights();

            var selectedlights = AnsiConsole.Prompt(
                new MultiSelectionPrompt <string>()
                .Title("Select the [green]lights[/] that you wish to be updated when mute state changes.")
                .Required()
                .PageSize(10)
                .AddChoices(lights.Select(x => $"{x.Id}: {x.Name} in {x.GroupString}")));

            config.Hue.Lights = selectedlights.Select(x => x.Split(':').First()).ToList();
        }
コード例 #30
0
    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));
    }