♻️ Refactor icons.

This commit is contained in:
Kolosov Alexandr 2023-08-10 18:55:22 +05:00
parent 44eb08f5e8
commit 440fd4d5d4
8 changed files with 104 additions and 57 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 228 KiB

After

Width:  |  Height:  |  Size: 491 KiB

View File

@ -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<Project>
if (currentVersion == null)
{
return "".Hint();
return Icons.NotFound;
}
var conventionVersion = dependency.Version?.ToVersion();
@ -98,10 +97,10 @@ public class DependencyDashboard : IControl<Project>
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<string, Package> Packages = new();
@ -138,7 +137,7 @@ public class DependencyDashboard : IControl<Project>
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<Project>
{
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();

View File

@ -1,4 +1,3 @@
using System.Runtime.CompilerServices;
using TUI.Settings;
using YamlDotNet.Serialization;

View File

@ -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;
}

View File

@ -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<string, string> _hotKeys = new()
{
{ "", "select prev" },
{ "", "select next" },
{ "󰬌", "toggle head" },
{ "󰬘", "quit" },
};
private readonly Dictionary<string, string> _hints = new()
{
{ "󰎔", "too new".Info() },
{ "", "so good" },
{ "", "be nice".Primary() },
{ "󰬟", "too old".Warning() }
};
private readonly Dictionary<string, string> _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<string, string> 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);

View File

@ -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<string, string> Applications = new()
{
{ NpmPackage, "package" },
{ DockerImage, "image" },
{ Site, "site" },
{ Api, "api" },
};
private static string GetIcon(string icon, string? activeColor = null) =>
icon.Pastel(activeColor ?? Palette.HintColor);
}

View File

@ -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);
}

View File

@ -1,7 +1,3 @@
using System.Text;
using System.Text.Json;
using Pastel;
using TUI.Domain;
using TUI.Settings;