diff --git a/docs/Dependencies.png b/docs/Dependencies.png index 05ca9cd..a83a68d 100644 Binary files a/docs/Dependencies.png and b/docs/Dependencies.png differ diff --git a/src/TUI/Dashboards/DependencyDashboard.cs b/src/TUI/Dashboards/DependencyDashboard.cs index b4c450e..77076b1 100644 --- a/src/TUI/Dashboards/DependencyDashboard.cs +++ b/src/TUI/Dashboards/DependencyDashboard.cs @@ -1,6 +1,5 @@ using System.Diagnostics; using System.Net; -using System.Text; using System.Text.Json; using Pastel; using TUI.Controls; @@ -80,7 +79,7 @@ public class DependencyDashboard : IControl if (currentVersion == null) { - return "".Hint(); + return Icons.NotFound; } var conventionVersion = dependency.Version?.ToVersion(); @@ -98,10 +97,10 @@ public class DependencyDashboard : IControl if (current < convention) { - return current.Major == convention.Major ? textVersion.Warning() : textVersion.Error(); + return current.Major == convention.Major ? textVersion.Primary() : textVersion.Warning(); } - return textVersion.Primary(); + return textVersion.Hint(); } private readonly static Dictionary Packages = new(); @@ -138,7 +137,7 @@ public class DependencyDashboard : IControl var versionWidth = version.Width(); if (versionWidth == 0) { - return ' '.Repeat(ColumnWidth - 1) + "".Hint(); + return ' '.Repeat(ColumnWidth - 1) + Icons.NotFound.Hint(); } return ' '.Repeat(ColumnWidth - versionWidth) + version; @@ -173,37 +172,37 @@ public class DependencyDashboard : IControl { var tags = ""; tags += GetGitApplication(sourceDto); - tags += sourceDto.Tags.Have("public") ? GetIcon("󰞉", "00FFFF") : GetIcon("󰕑", "AFE1AF"); - tags += GetIcon("󰚩", "4285F4", sourceDto.Tags.Have("seo")); - tags += GetIcon("", "FFD700", sourceDto.Tags.Have("auth")); + tags += " "; + tags += sourceDto.Tags.Have("public") ? Icons.NetworkPublic : Icons.NetworkPrivate; + tags += " "; + tags += sourceDto.Tags.Have("seo") ? Icons.SEO : Icons.SEO.Disable(); + tags += " "; + tags += sourceDto.Tags.Have("auth") ? Icons.Auth : Icons.Auth.Disable(); + tags += " "; tags += GetApplicationType(sourceDto); + tags += " "; + return tags; } private static string GetApplicationType(SourceDto sourceDto) { - if (sourceDto.Tags.Have("site")) - return GetIcon("", "BF40BF"); - if (sourceDto.Tags.Have("api")) - return GetIcon("", "7F52FF"); - if (sourceDto.Tags.Have("package")) - return GetIcon("", "CB0000"); - if (sourceDto.Tags.Have("image")) - return GetIcon("󰡨", "086DD7"); + foreach (var application in Icons.Applications) + { + if (sourceDto.Tags.Have(application.Value)) + return application.Key; + } - return GetIcon("", "CB0000"); + return Icons.Undefined; } private static string GetGitApplication(SourceDto sourceDto) => sourceDto.Repo switch { - { } url when url.Contains("gitlab") => GetIcon("", "E24329"), - { } url when url.Contains("github") => GetIcon("", "ADBAC7"), - _ => GetIcon("", "F14E32") + { } url when url.Contains("gitlab") => Icons.GitLab, + { } url when url.Contains("github") => Icons.GitHub, + _ => Icons.Git }; - private static string GetIcon(string icon, string activeColor, bool enabled = true) => - (icon.Pastel(enabled ? activeColor : "71797E") + " ").PadLeft(2); - public void Next() { _table.Next(); diff --git a/src/TUI/Domain/Project.cs b/src/TUI/Domain/Project.cs index 6e068fb..dc08f5b 100644 --- a/src/TUI/Domain/Project.cs +++ b/src/TUI/Domain/Project.cs @@ -1,4 +1,3 @@ -using System.Runtime.CompilerServices; using TUI.Settings; using YamlDotNet.Serialization; diff --git a/src/TUI/Extensions.cs b/src/TUI/Extensions.cs index 79f6926..310da13 100644 --- a/src/TUI/Extensions.cs +++ b/src/TUI/Extensions.cs @@ -1,8 +1,4 @@ -using System.Text.Json.Nodes; using System.Text.RegularExpressions; -using TUI.Domain; -using TUI.Settings; -using TUI.UserInterface; namespace TUI; @@ -19,6 +15,11 @@ public static class Extensions return repeatCount < 0 ? "" : new string(symbol, repeatCount); } + public static string RemoveColors(this string text) + { + return Regex.Replace(text, @"\S\[(\d{0,3}[;m][_]?){0,5}", ""); + } + public static int Width(this string text) { if (string.IsNullOrEmpty(text)) @@ -26,7 +27,7 @@ public static class Extensions return 0; } - var clearText = Regex.Replace(text, @"\S\[(\d{0,3}[;m][_]?){0,5}", ""); + var clearText = text.RemoveColors(); var stringInfo = new System.Globalization.StringInfo(clearText); return stringInfo.LengthInTextElements; } diff --git a/src/TUI/UserInterface/Header.cs b/src/TUI/UserInterface/Header.cs index 8023102..39bebf7 100644 --- a/src/TUI/UserInterface/Header.cs +++ b/src/TUI/UserInterface/Header.cs @@ -7,6 +7,32 @@ public class Header : IControl { public const int LogoWidth = 16; public const int Height = 6; + public const int MaxHeaderBlocksWidth = 16; + + + private readonly Dictionary _hotKeys = new() + { + { "", "select prev" }, + { "", "select next" }, + { "󰬌", "toggle head" }, + { "󰬘", "quit" }, + }; + + private readonly Dictionary _hints = new() + { + { "󰎔", "too new".Info() }, + { "", "so good" }, + { "", "be nice".Primary() }, + { "󰬟", "too old".Warning() } + }; + + private readonly Dictionary _tags = new() + { + { Icons.Auth, "Auth" }, + { Icons.NetworkPublic, "WWW" }, + { Icons.SEO, "SEO" }, + { Icons.GitLab, "VCS" }, + }; public void Render(Position position) { @@ -17,33 +43,27 @@ public class Header : IControl Console.WriteLine(new string(' ', Console.WindowWidth - LogoWidth)); } - RenderHints(); - RenderHotkeys(); + RenderBlock(0, _hints); + RenderBlock(1, _tags); + RenderBlock(2, Icons.Applications); + RenderBlock(3, _hotKeys); RenderLogo(); } - private void RenderHotkeys() + private static void RenderBlock(int blockNumber, Dictionary items) { - Console.SetCursorPosition(30, Theme.Padding); - Console.Write("󰬌 toggle header".Hint()); - Console.SetCursorPosition(30, Theme.Padding + 1); - Console.Write("󰬘 quit".Hint()); - Console.SetCursorPosition(30, Theme.Padding + 2); - Console.Write(" select previous".Hint()); - Console.SetCursorPosition(30, Theme.Padding + 3); - Console.Write(" select next".Hint()); + var leftPadding = Theme.Padding + blockNumber * MaxHeaderBlocksWidth; + + var hotKeyNumber = 0; + foreach (var item in items) + { + Console.SetCursorPosition(leftPadding, Theme.Padding + hotKeyNumber++); + Console.Write((item.Key + " " + item.Value).Hint()); + } } - private void RenderHints() - { - Console.SetCursorPosition(0, Theme.Padding); - Console.WriteLine(' '.Repeat(Theme.Padding) + "󰎔 Too new: ".Hint() + "1.20.0".Info()); - Console.WriteLine(' '.Repeat(Theme.Padding) + " So good: ".Hint() + "1.20.0".Primary()); - Console.WriteLine(' '.Repeat(Theme.Padding) + " Be nice: ".Hint() + "1.20.0".Warning()); - Console.WriteLine(' '.Repeat(Theme.Padding) + "󰬟 Too old: ".Hint() + "1.20.0".Error()); - } - private void RenderLogo() + private static void RenderLogo() { Console.SetCursorPosition(Console.WindowWidth - LogoWidth - Theme.Padding, 0); Console.WriteLine(" ╭━━━━┳╮".Primary() + "╱╱".Hint() + "╭━━━╮ ".Primary()); @@ -52,8 +72,8 @@ public class Header : IControl Console.SetCursorPosition(Console.WindowWidth - LogoWidth - Theme.Padding, 2); Console.WriteLine(" ╰╯┃┃╰┫┃".Primary() + "╱╱╱".Hint() + "┃┃┃┃ ".Primary()); Console.SetCursorPosition(Console.WindowWidth - LogoWidth - Theme.Padding, 3); - Console.WriteLine(" ╱╱".Hint() + "┃┃".Primary() + "╱".Hint() + "┃┃".Primary() + - "╱".Hint() + "╭╮┃┃┃┃ ".Primary()); + Console.WriteLine(" ╱╱".Hint() + "┃┃".Primary() + "╱".Hint() + "┃┃".Primary() + "╱".Hint() + + "╭╮┃┃┃┃ ".Primary()); Console.SetCursorPosition(Console.WindowWidth - LogoWidth - Theme.Padding, 4); Console.WriteLine(" ╱╱╱".Hint() + "┃┃".Primary() + "╱".Hint() + "┃╰━╯┣╯╰╯┃ ".Primary()); Console.SetCursorPosition(Console.WindowWidth - LogoWidth - Theme.Padding, 5); diff --git a/src/TUI/UserInterface/Icons.cs b/src/TUI/UserInterface/Icons.cs new file mode 100644 index 0000000..2e83dfb --- /dev/null +++ b/src/TUI/UserInterface/Icons.cs @@ -0,0 +1,32 @@ +using Pastel; + + +namespace TUI.UserInterface; + +public static class Icons +{ + public static string GitLab => GetIcon("", "E24329"); + public static string GitHub => GetIcon("", "ADBAC7"); + public static string Git => GetIcon("", "F14E32"); + public static string NetworkPublic => GetIcon("󰞉", "00FFFF"); + public static string NetworkPrivate => GetIcon("󰕑"); + public static string Undefined => GetIcon(""); + public static string Site => GetIcon("", "BF40BF"); + public static string Api => GetIcon("", "7F52FF"); + public static string DockerImage => GetIcon("󰡨", "086DD7"); + public static string NpmPackage => GetIcon("", "CB0000"); + public static string SEO => GetIcon("󰚩", "4285F4"); + public static string Auth => GetIcon("", "FFD700"); + public static string NotFound => GetIcon(""); + + public readonly static Dictionary Applications = new() + { + { NpmPackage, "package" }, + { DockerImage, "image" }, + { Site, "site" }, + { Api, "api" }, + }; + + private static string GetIcon(string icon, string? activeColor = null) => + icon.Pastel(activeColor ?? Palette.HintColor); +} \ No newline at end of file diff --git a/src/TUI/UserInterface/Palette.cs b/src/TUI/UserInterface/Palette.cs index 800b627..c561172 100644 --- a/src/TUI/UserInterface/Palette.cs +++ b/src/TUI/UserInterface/Palette.cs @@ -10,12 +10,12 @@ public static class Palette public const string HintColor = "71797E"; public const string ErrorColor = "CA3433"; public const string WarningColor = "EC9706"; - public const string InfoColor = "0E4D92"; + public const string InfoColor = "25799F"; public static string Primary(this string currentText) => currentText.Pastel(PrimaryColor); public static string Hint(this string currentText) => currentText.Pastel(HintColor); + public static string Disable(this string currentText) => currentText.RemoveColors().Pastel(HintColor); public static string Warning(this string currentText) => currentText.Pastel(WarningColor); public static string Error(this string currentText) => currentText.Pastel(ErrorColor); public static string Info(this string currentText) => currentText.Pastel(InfoColor); - } \ No newline at end of file diff --git a/src/TUI/UserInterface/Panel.cs b/src/TUI/UserInterface/Panel.cs index 5b5be1a..be70b0a 100644 --- a/src/TUI/UserInterface/Panel.cs +++ b/src/TUI/UserInterface/Panel.cs @@ -1,7 +1,3 @@ -using System.Text; -using System.Text.Json; -using Pastel; -using TUI.Domain; using TUI.Settings;