|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +using System.Reflection; |
| 5 | + |
| 6 | +namespace WinApp.Cli.Helpers; |
| 7 | + |
| 8 | +/// <summary> |
| 9 | +/// Provides banner display functionality for the CLI. |
| 10 | +/// ASCII art is pre-computed for optimal startup performance. |
| 11 | +/// </summary> |
| 12 | +internal static class BannerHelper |
| 13 | +{ |
| 14 | + // Stylized "winapp" text in block letters |
| 15 | + private static readonly string[] TitleBlockArt = |
| 16 | + { |
| 17 | + @"▄▄ ▀▀ ", |
| 18 | + @" ▀█▄ ██ ██ ██ ████▄ ▀▀█▄ ████▄ ████▄ ", |
| 19 | + @" ▄█▀ ██ █ ██ ██ ██ ██ ▄█▀██ ██ ██ ██ ██ ", |
| 20 | + @"▄█▀ ██▀██ ██▄ ██ ██ ▀█▄██ ████▀ ████▀ ", |
| 21 | + @" ██ ██ ", |
| 22 | + @" ▀▀ ▀▀ ", |
| 23 | + }; |
| 24 | + |
| 25 | + // Simple ASCII fallback for the title |
| 26 | + private static readonly string[] TitleAsciiArt = |
| 27 | + { |
| 28 | + @" _ ", |
| 29 | + @" __ _(_)_ __ __ _ _ __ _ __ ", |
| 30 | + @" \ \ /\ / / | '_ \ / _` | '_ \| '_ \ ", |
| 31 | + @" \ V V /| | | | | (_| | |_) | |_) | ", |
| 32 | + @" \_/\_/ |_|_| |_|\__,_| .__/| .__/ ", |
| 33 | + @" |_| |_| ", |
| 34 | + }; |
| 35 | + |
| 36 | + // ANSI color codes for gradient effect (Blue -> Purple, Windows-themed) |
| 37 | + private static readonly string[] GradientColors = |
| 38 | + { |
| 39 | + "\x1b[38;5;39m", // Bright Blue |
| 40 | + "\x1b[38;5;33m", // Blue |
| 41 | + "\x1b[38;5;63m", // Blue-Purple |
| 42 | + "\x1b[38;5;99m", // Purple |
| 43 | + "\x1b[38;5;135m", // Light Purple |
| 44 | + "\x1b[38;5;141m", // Lavender |
| 45 | + }; |
| 46 | + |
| 47 | + private const string ResetColor = "\x1b[0m"; |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// Displays the CLI banner with version information. |
| 51 | + /// </summary> |
| 52 | + public static void DisplayBanner() |
| 53 | + { |
| 54 | + var useColor = UiSymbols.UseEmoji; // Same check - modern terminals support both |
| 55 | + var version = GetVersionString(); |
| 56 | + |
| 57 | + Console.WriteLine(); |
| 58 | + |
| 59 | + if (useColor) |
| 60 | + { |
| 61 | + DisplayColorBanner(version); |
| 62 | + } |
| 63 | + else |
| 64 | + { |
| 65 | + DisplayPlainBanner(version); |
| 66 | + } |
| 67 | + |
| 68 | + Console.WriteLine(); |
| 69 | + } |
| 70 | + |
| 71 | + private static void DisplayColorBanner(string version) |
| 72 | + { |
| 73 | + var titleLines = TitleBlockArt; |
| 74 | + |
| 75 | + // Display each line with a gradient color |
| 76 | + for (int i = 0; i < titleLines.Length; i++) |
| 77 | + { |
| 78 | + var color = GradientColors[i % GradientColors.Length]; |
| 79 | + Console.WriteLine($" {color}{titleLines[i]}{ResetColor}"); |
| 80 | + } |
| 81 | + |
| 82 | + Console.WriteLine(); |
| 83 | + Console.WriteLine($" \x1b[90mWindows App Development CLI · Version {version}{ResetColor}"); |
| 84 | + } |
| 85 | + |
| 86 | + private static void DisplayPlainBanner(string version) |
| 87 | + { |
| 88 | + foreach (var line in TitleAsciiArt) |
| 89 | + { |
| 90 | + Console.WriteLine($" {line}"); |
| 91 | + } |
| 92 | + |
| 93 | + Console.WriteLine(); |
| 94 | + Console.WriteLine($" Windows App Development CLI - Version {version}"); |
| 95 | + } |
| 96 | + |
| 97 | + /// <summary> |
| 98 | + /// Gets the version string from the assembly. |
| 99 | + /// </summary> |
| 100 | + private static string GetVersionString() |
| 101 | + { |
| 102 | + var assembly = Assembly.GetExecutingAssembly(); |
| 103 | + |
| 104 | + // Try to get informational version first (includes git info if available) |
| 105 | + var infoVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion; |
| 106 | + if (!string.IsNullOrEmpty(infoVersion)) |
| 107 | + { |
| 108 | + // Remove git hash suffix if present (e.g., "0.1.8+abc123" -> "0.1.8") |
| 109 | + var plusIndex = infoVersion.IndexOf('+'); |
| 110 | + return plusIndex >= 0 ? infoVersion[..plusIndex] : infoVersion; |
| 111 | + } |
| 112 | + |
| 113 | + // Fall back to assembly version |
| 114 | + var version = assembly.GetName().Version; |
| 115 | + return version != null ? $"{version.Major}.{version.Minor}.{version.Build}" : "0.0.0"; |
| 116 | + } |
| 117 | +} |
0 commit comments