- Requires NuGet package Spectre.Console
- Emojis
| using Spectre.Console; | |
| using System.Text; | |
| namespace BirthDay; | |
| internal partial class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| // 1) Force UTF-8 so emojis aren’t mangled into question marks | |
| Console.OutputEncoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); | |
| Console.InputEncoding = Encoding.UTF8; | |
| string[] lyrics = | |
| [ | |
| ":musical_note: Happy birthday to you", | |
| ":musical_note: Happy birthday to you", | |
| ":musical_note: Happy birthday dear Karen", | |
| ":musical_note: Happy birthday to you! :clinking_glasses:" | |
| ]; | |
| AnsiConsole.MarkupLine(":birthday_cake: [magenta]Let's sing Happy Birthday to Karen![/] :birthday_cake:"); | |
| foreach (var line in lyrics) | |
| { | |
| AnsiConsole.MarkupLine(line); // <-- Spectre parses :shortcodes: here | |
| Thread.Sleep(1500); | |
| } | |
| AnsiConsole.MarkupLine(":clinking_glasses: Wishing Karen a fantastic year ahead! :clinking_glasses:"); | |
| SpectreConsoleHelpers.ExitPrompt(); | |
| } | |
| } |
| using Spectre.Console; | |
| namespace TODO; | |
| public static class SpectreConsoleHelpers | |
| { | |
| public static void ExitPrompt() | |
| { | |
| Console.WriteLine(); | |
| AnsiConsole.MarkupLine("[bold cyan]Press any key to exit...[/]"); | |
| Console.ReadLine(); | |
| } | |
| private static void Render(Rule rule) | |
| { | |
| AnsiConsole.Write(rule); | |
| AnsiConsole.WriteLine(); | |
| } | |
| } |