mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-04 10:35:27 +08:00 
			
		
		
		
	Add support for fake input in asciicast recordings
* Fixes a bug with `SelectionPrompt` and page size. * Allow `IAnsiConsoleInput` to return `null`.
This commit is contained in:
		
				
					committed by
					
						
						Phil Scott
					
				
			
			
				
	
			
			
			
						parent
						
							46abadaccb
						
					
				
				
					commit
					450d87f5d3
				
			@@ -0,0 +1,40 @@
 | 
			
		||||
using DocExampleGenerator;
 | 
			
		||||
using Spectre.Console;
 | 
			
		||||
 | 
			
		||||
namespace Generator.Commands.Samples
 | 
			
		||||
{
 | 
			
		||||
    internal class MultiSelectionSample : BaseSample
 | 
			
		||||
    {
 | 
			
		||||
        public override (int Cols, int Rows) ConsoleSize => (base.ConsoleSize.Cols, 14);
 | 
			
		||||
 | 
			
		||||
        public override void Run(IAnsiConsole console)
 | 
			
		||||
        {
 | 
			
		||||
            console.DisplayThenType(AskFruit, "↓↓ ¦¦↑↑ ¦¦ ¦¦↓ ↓↓↓↓↓ ↓↓↓↓ ¦¦↲");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static void AskFruit(IAnsiConsole console)
 | 
			
		||||
        {
 | 
			
		||||
            var favorites = console.Prompt(
 | 
			
		||||
                new MultiSelectionPrompt<string>()
 | 
			
		||||
                    .PageSize(10)
 | 
			
		||||
                    .Title("What are your [green]favorite fruits[/]?")
 | 
			
		||||
                    .MoreChoicesText("[grey](Move up and down to reveal more fruits)[/]")
 | 
			
		||||
                    .InstructionsText("[grey](Press [blue]<space>[/] to toggle a fruit, [green]<enter>[/] to accept)[/]")
 | 
			
		||||
                    .AddChoiceGroup("Berries", new[]
 | 
			
		||||
                    {
 | 
			
		||||
                        "Blackcurrant", "Blueberry", "Cloudberry",
 | 
			
		||||
                        "Elderberry", "Honeyberry", "Mulberry"
 | 
			
		||||
                    })
 | 
			
		||||
                    .AddChoices(new[]
 | 
			
		||||
                    {
 | 
			
		||||
                        "Apple", "Apricot", "Avocado", "Banana",
 | 
			
		||||
                        "Cherry", "Cocunut", "Date", "Dragonfruit", "Durian",
 | 
			
		||||
                        "Egg plant",  "Fig", "Grape", "Guava",
 | 
			
		||||
                        "Jackfruit", "Jambul", "Kiwano", "Kiwifruit", "Lime", "Lylo",
 | 
			
		||||
                        "Lychee", "Melon", "Nectarine", "Orange", "Olive"
 | 
			
		||||
                    }));
 | 
			
		||||
 | 
			
		||||
            console.MarkupLine("Your selected: [yellow]{0}[/]", string.Join(',', favorites));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user