Search code examples
c#console-applicationspectre.console

Is there function like Console.ReadKey in Spectre.Console.AnsiConsole?


Hi i was wondering if there is a function like Console.ReadKey() but with use of AnsiConsole from Spectre.Console package for c#, i dont know if i should use regular one from Console namespace?

I tried something like that but i dont know if Console is integrated with AnsiConsole

 AnsiConsole.Write("Press any key to continue");
 Console.ReadKey();

Solution

  • No there is not, perhaps the following would suit your requirement. Change colors to suit you needs.

    private static void Render(Rule rule)
    {
        AnsiConsole.Write(rule);
        AnsiConsole.WriteLine();
    }
    
    private static void ExitPrompt()
    {
        Console.WriteLine();
        Render(new Rule($"[yellow]Press Enter to exit[/]").RuleStyle(Style.Parse("silver")).Centered());
        Console.ReadLine();
    }