From ee490fb84ef7902007cfebbe85be28453e2967f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=9A=D0=BE=D0=BB=D0=BE=D1=81=D0=BE=D0=B2?= Date: Tue, 29 Aug 2023 09:40:28 +0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20command=20line.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/TUI/Controls/Copyright.cs | 2 +- src/TUI/Controls/Dashboard.cs | 44 ++++++++--------- src/TUI/Controls/Display.cs | 36 +++++++++++--- src/TUI/Controls/IControl.cs | 4 +- src/TUI/Controls/Table.cs | 27 +++-------- src/TUI/Dashboards/DependencyDashboard.cs | 54 +++++++++------------ src/TUI/Domain/NewFile1.txt | 53 +++++++++++++++++++++ src/TUI/Domain/Package.cs | 17 ++----- src/TUI/Domain/Settings.cs | 6 +-- src/TUI/Extensions.cs | 12 ++--- src/TUI/Program.cs | 58 +++++++++++++++++------ src/TUI/Settings/DependencyDto.cs | 2 +- src/TUI/TUI.csproj | 32 ++++++------- src/TUI/UserInterface/CommandLine.cs | 17 +++++++ src/TUI/UserInterface/Header.cs | 25 +++++----- src/TUI/UserInterface/Icons.cs | 20 ++++---- src/TUI/UserInterface/Palette.cs | 37 ++++++++++++--- src/TUI/UserInterface/Panel.cs | 28 +++++------ 18 files changed, 294 insertions(+), 180 deletions(-) create mode 100644 src/TUI/Domain/NewFile1.txt create mode 100644 src/TUI/UserInterface/CommandLine.cs diff --git a/src/TUI/Controls/Copyright.cs b/src/TUI/Controls/Copyright.cs index 0100952..5faf29f 100644 --- a/src/TUI/Controls/Copyright.cs +++ b/src/TUI/Controls/Copyright.cs @@ -5,7 +5,7 @@ namespace TUI.Controls; public class Copyright : IControl { - public void Render(string author, Position position) + public void Render(string author, Position position, int? height = 0) { const string icon = "© "; Console.SetCursorPosition(position.Left - icon.Width(), position.Top); diff --git a/src/TUI/Controls/Dashboard.cs b/src/TUI/Controls/Dashboard.cs index 69ae5bb..581061e 100644 --- a/src/TUI/Controls/Dashboard.cs +++ b/src/TUI/Controls/Dashboard.cs @@ -6,39 +6,42 @@ namespace TUI.Controls; public class Dashboard : IControl { - public void Render(string title, Position position) + public bool IsFocused { get; set; } + + public void Render(string title, Position position, int? height = 0) { Console.SetCursorPosition(position.Left, position.Top); - RenderTopLine(title); + RenderTopLine(title, IsFocused); - var marginTop = Theme.BorderWidth + Theme.Padding + position.Top; - var dashboardHeight = Console.WindowHeight - Theme.BorderWidth; + var marginTop = position.Top; - for (var top = marginTop; top < dashboardHeight; top++) - { - RenderMiddleLine(); - } + var dashboardHeight = height == 0 ? Console.WindowHeight - marginTop : height + Theme.Padding * 2; - RenderBottomLine(); + for (var top = marginTop; + top < dashboardHeight + marginTop - Theme.BorderWidth * 2 - Theme.Padding * 2; + top++) + RenderMiddleLine(IsFocused); + + RenderBottomLine(IsFocused); } - private static void RenderMiddleLine() + private static void RenderMiddleLine(bool isFocused) { - Console.Write("│".Primary()); + Console.Write("│".Primary(isFocused)); Console.Write(new string(' ', Console.WindowWidth - Theme.BorderWidth * 2)); - Console.WriteLine("│".Primary()); + Console.WriteLine("│".Primary(isFocused)); } - private static void RenderBottomLine() + private static void RenderBottomLine(bool isFocused) { var lineWidth = Console.WindowWidth - Theme.BorderWidth * 2; - Console.Write("└".Primary()); - Console.Write('─'.Repeat(lineWidth).Primary()); - Console.WriteLine("┘".Primary()); + Console.Write("└".Primary(isFocused)); + Console.Write('─'.Repeat(lineWidth).Primary(isFocused)); + Console.WriteLine("┘".Primary(isFocused)); } - private static void RenderTopLine(string title) + private static void RenderTopLine(string title, bool isFocused) { var lineWidth = (Console.WindowWidth - title.Width() - Theme.BorderWidth * 2 - Theme.Padding * 2) / @@ -48,13 +51,10 @@ public class Dashboard : IControl topLine.Append("┌"); topLine.Append('─'.Repeat(lineWidth)); topLine.AppendFormat("{0}{1}{0}", ' '.Repeat(Theme.Padding), title); - if (title.Width() % 2 == 1) - { - topLine.Append('─'); - } + if (title.Width() % 2 == 1) topLine.Append('─'); topLine.Append('─'.Repeat(lineWidth)); topLine.Append("┐"); - Console.WriteLine(topLine.ToString().Primary()); + Console.WriteLine(topLine.ToString().Primary(isFocused)); } } \ No newline at end of file diff --git a/src/TUI/Controls/Display.cs b/src/TUI/Controls/Display.cs index bd819a1..3bff348 100644 --- a/src/TUI/Controls/Display.cs +++ b/src/TUI/Controls/Display.cs @@ -7,33 +7,43 @@ namespace TUI.Controls; public class Display { - private bool _headerInDisplay = true; - public readonly Header Header; + public readonly CommandLine CommandLine; public readonly Copyright Copyright; public readonly DependencyDashboard DependencyDashboard; + public readonly Header Header; + private bool _commandLineInDisplay; + private Project _currentProject; + private bool _headerInDisplay = true; public Display() { Header = new Header(); Copyright = new Copyright(); + CommandLine = new CommandLine(); DependencyDashboard = new DependencyDashboard(); - Render(); } + public string FocusedElement { get; set; } = ""; + public void OpenDeps(Project project) { _currentProject = project; var dashboardPosition = new Position(0, Header.Height); + DependencyDashboard.IsFocused = true; + CommandLine.IsFocused = false; DependencyDashboard.Render(_currentProject, dashboardPosition); } - private void ResizeDependencies(bool full) + private void ResizeDependencies() { - var dashboardPosition = new Position(0, full ? 0 : Header.Height); + var topPosition = 0; + topPosition += _commandLineInDisplay ? CommandLine.Height : 0; + topPosition += _headerInDisplay ? Header.Height : 0; + var dashboardPosition = new Position(0, topPosition); DependencyDashboard.Render(_currentProject, dashboardPosition); } @@ -58,7 +68,7 @@ public class Display Header.Render(headerPosition); } - ResizeDependencies(!_headerInDisplay); + ResizeDependencies(); } public void Next() @@ -70,4 +80,18 @@ public class Display { DependencyDashboard.Previous(); } + + public void OpenCommandLine() + { + var commandLinePosition = new Position(0, _headerInDisplay ? Header.Height : 0); + CommandLine.IsFocused = true; + DependencyDashboard.IsFocused = false; + FocusedElement = nameof(CommandLine); + CommandLine.Render(commandLinePosition); + _commandLineInDisplay = true; + ResizeDependencies(); + Console.SetCursorPosition(commandLinePosition.Left + Theme.Padding + Theme.BorderWidth + 2, + commandLinePosition.Top + Theme.BorderWidth); + Console.CursorVisible = true; + } } \ No newline at end of file diff --git a/src/TUI/Controls/IControl.cs b/src/TUI/Controls/IControl.cs index 6fda601..231c82b 100644 --- a/src/TUI/Controls/IControl.cs +++ b/src/TUI/Controls/IControl.cs @@ -7,5 +7,7 @@ public interface IControl public interface IControl { - void Render(TProps props, Position position); + // bool IsFocused { get; } + + void Render(TProps props, Position position, int? height); } \ No newline at end of file diff --git a/src/TUI/Controls/Table.cs b/src/TUI/Controls/Table.cs index 353ca3e..1bf1249 100644 --- a/src/TUI/Controls/Table.cs +++ b/src/TUI/Controls/Table.cs @@ -11,23 +11,20 @@ public record TableProps(IEnumerable HeaderCells, public class Table : IControl { + private readonly Dictionary _rows = new(); private Position _position; private int _selectedRowId; - public void Render(TableProps props, Position position) + public void Render(TableProps props, Position position, int? height = 0) { _position = position; Console.SetCursorPosition(_position.Left, _position.Top); Console.Write(' '.Repeat(props.TitleWidth)); foreach (var headerCell in props.HeaderCells) - { Console.Write(' '.Repeat(props.ColumnWidth - headerCell.Width()) + headerCell); - } } - private readonly Dictionary _rows = new(); - public void RenderRow(int rowId, string rowText, string? bgColor = default) { var padRight = ' '.Repeat(Console.WindowWidth - rowText.Width() - Theme.BorderWidth * 2); @@ -39,10 +36,7 @@ public class Table : IControl public void Next() { - if (_selectedRowId >= _rows.Count) - { - return; - } + if (_selectedRowId >= _rows.Count) return; RemoveHoverFromCurrentRow(); RenderRow(++_selectedRowId, _rows[_selectedRowId], Palette.HoverColor); @@ -50,23 +44,14 @@ public class Table : IControl private void RemoveHoverFromCurrentRow() { - if (_rows.TryGetValue(_selectedRowId, out var row)) - { - RenderRow(_selectedRowId, row); - } + if (_rows.TryGetValue(_selectedRowId, out var row)) RenderRow(_selectedRowId, row); } public void Previous() { - if (_selectedRowId == 0) - { - Next(); - } + if (_selectedRowId == 0) Next(); - if (_selectedRowId == 1) - { - return; - } + if (_selectedRowId == 1) return; RemoveHoverFromCurrentRow(); RenderRow(--_selectedRowId, _rows[_selectedRowId], Palette.HoverColor); diff --git a/src/TUI/Dashboards/DependencyDashboard.cs b/src/TUI/Dashboards/DependencyDashboard.cs index 77076b1..f5603da 100644 --- a/src/TUI/Dashboards/DependencyDashboard.cs +++ b/src/TUI/Dashboards/DependencyDashboard.cs @@ -15,13 +15,20 @@ public class DependencyDashboard : IControl private const int TitleWidth = 25; private const int ColumnWidth = 10; + private readonly static Dictionary Packages = new(); + private readonly Dashboard _dashboard = new(); + private readonly Table _table = new(); - public void Render(Project project, Position position) + public bool IsFocused { - var dashboard = new Dashboard(); - dashboard.Render(project.Icon, position); + get => _dashboard.IsFocused; + set => _dashboard.IsFocused = value; + } + public void Render(Project project, Position position, int? height = 0) + { + _dashboard.Render(project.Icon + " Dependencies", position); var header = project.Dependencies.Select(GetConventionVersion).ToArray(); var rows = project.Sources.Select(GetTitle).ToArray(); @@ -77,10 +84,7 @@ public class DependencyDashboard : IControl { var currentVersion = package.ParseVersion(dependency.Name); - if (currentVersion == null) - { - return Icons.NotFound; - } + if (currentVersion == null) return Icons.NotFound; var conventionVersion = dependency.Version?.ToVersion(); return PaintingVersion(currentVersion, conventionVersion); @@ -90,30 +94,20 @@ public class DependencyDashboard : IControl { var textVersion = current.ToString(); - if (current > convention) - { - return textVersion.Info(); - } + if (current > convention) return textVersion.Info(); if (current < convention) - { return current.Major == convention.Major ? textVersion.Primary() : textVersion.Warning(); - } return textVersion.Hint(); } - private readonly static Dictionary Packages = new(); - private static Package DownloadPackage(SourceDto sourceDto) { - if (Packages.TryGetValue(sourceDto.Repo, out var downloadPackage)) - { - return downloadPackage; - } + var endpoint = sourceDto.Tags.Have("gitlab") ? GetGitlabEndpoint(sourceDto) : sourceDto.Repo; + if (Packages.TryGetValue(endpoint, out var downloadPackage)) return downloadPackage; using HttpClient client = new(); - var endpoint = sourceDto.Tags.Have("gitlab") ? GetGitlabEndpoint(sourceDto) : sourceDto.Repo; var json = client.GetStringAsync(endpoint).GetAwaiter().GetResult(); var package = JsonSerializer.Deserialize(json); Packages.Add(endpoint, package); @@ -135,10 +129,7 @@ public class DependencyDashboard : IControl private static string RenderCurrentVersion(string version) { var versionWidth = version.Width(); - if (versionWidth == 0) - { - return ' '.Repeat(ColumnWidth - 1) + Icons.NotFound.Hint(); - } + if (versionWidth == 0) return ' '.Repeat(ColumnWidth - 1) + Icons.NotFound.Hint(); return ' '.Repeat(ColumnWidth - versionWidth) + version; } @@ -188,20 +179,21 @@ public class DependencyDashboard : IControl private static string GetApplicationType(SourceDto sourceDto) { foreach (var application in Icons.Applications) - { if (sourceDto.Tags.Have(application.Value)) return application.Key; - } return Icons.Undefined; } - private static string GetGitApplication(SourceDto sourceDto) => sourceDto.Repo switch + private static string GetGitApplication(SourceDto sourceDto) { - { } url when url.Contains("gitlab") => Icons.GitLab, - { } url when url.Contains("github") => Icons.GitHub, - _ => Icons.Git - }; + return sourceDto.Repo switch + { + { } url when url.Contains("gitlab") => Icons.GitLab, + { } url when url.Contains("github") => Icons.GitHub, + _ => Icons.Git + }; + } public void Next() { diff --git a/src/TUI/Domain/NewFile1.txt b/src/TUI/Domain/NewFile1.txt new file mode 100644 index 0000000..66c489e --- /dev/null +++ b/src/TUI/Domain/NewFile1.txt @@ -0,0 +1,53 @@ + + 󰘳 1 󱓟 releases  select prev + 󰘳 2 󰧑 competencies  select next + 󰘳 3  dependencies 󰬌 toggle head + 󰘳 4 󰬘 quit + + 󰎔 too new  Auth  package +  so good 󰞉 WWW 󰡨 image +  be nice 󰚩 SEO  site + 󰬟 too old  VCS  api + + 󰦖 wait 󰲽 build 󱓞 release + 󱔢 reopen 󱞈 testing 󰶯 hotfix + 󱞇 in progress 󰦕 done  publish + 󱞇 review 󱄊 cancel + +   releases 󱓟  Fact  2023 +   releases 󱓟  Fact +   releases 󱓟  Planned +   releases 󱓟  Planned  2024-12-31 xfirm +   competencies 󰧑 +   growth zone 󰶼 +   dependencies  + +┌──────────────────────────────────────────────────────────────────────── Planned release ─────────────────────────────────────────────────────────────────┐ +│ 2024-12-31 4/11 xfirm [############# ] //green - done, blue - test, pink review/build, orange WIP +│ 2024-12-31 xfirm 4/11 [###############.......] //green - done, blue - test, pink review/build +│ 2024-12-31 xfirm 4/11 [############..........] //green - done, blue - test, pink review/build +│ 2024-12-31 xfirm 4/11 [############..........] //green - done, blue - test, pink review/build +│ 2024-12-31 xfirm 4/11 [############..........] //green - done, blue - test, pink review/build +│ 2024-12-31 xfirm 4/11 [############..........] //green - done, blue - test, pink review/build +│ 2024-12-31 xfirm 4/11 [############..........] //green - done, blue - test, pink review/build +└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ +┌──────────────────────────────────────────────────────────────────────── checkperson-site ────────────────────────────────────────────────────────────────┐ +│ 󰨑 󰦖  ELK-3628 Create new menu. 󰵮 Petrov A. 󰙨 Ivanov I. +│ 󰨑 󰦕  XF-12 Change input hover. 󰵮 Ivanov I. 󰙨 Petrov A., Petrov B. +│ 󰨑 󱞇  ELK-3628 Crete new project with menu, profile, issues and # 󰵮 Ivanov I. 󰙨 Petrov A., Petrov B. +└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ + +┌─────────────────────────────────────────────────────────────────────────── Actual releases 2023 ─────────────────────────────────────────────────────────┐ +│ Jan Feb Mar Apl May Jun Jul Aug Sep Oct Nov Dec +│ ├─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ +│ LK 󱓞 󱓞  󱓞 󱓞  󱓞 󱓞  󱓞 󱓞  󱓞 󱓞  󱓞 󱓞  󱓞 󱓞 󱓞  󱓞 󱓞  󱓞 󱓞  󱓞 󱓞  󱓞 󱓞 +│ CP 󱓞  󱓞  󱓞  󱓞    󱓞  󱓞  󱓞  󱓞  󱓞  󱓞  󱓞 +│ RR 󰶯 󰶯  󰶯 󰶯  󰶯 󰶯  󰶯 󰶯  󰶯 󰶯  󰶯 󰶯  󰶯 󰶯  󰶯 󰶯  󰶯 󰶯  󰶯 󰶯  󰶯 󰶯  󰶯 󰶯 +└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ + + + + + + + diff --git a/src/TUI/Domain/Package.cs b/src/TUI/Domain/Package.cs index b7f7f87..c56d4a3 100644 --- a/src/TUI/Domain/Package.cs +++ b/src/TUI/Domain/Package.cs @@ -17,25 +17,16 @@ public class Package public Version? ParseVersion(string? dependencyName) { - if (dependencyName == null) - { - return null; - } + if (dependencyName == null) return null; JsonNode? version = null; var lowerDependencyName = dependencyName.ToLower(); Dependencies?.TryGetPropertyValue(lowerDependencyName, out version); - - if (version == null) - { - Engines?.TryGetPropertyValue(lowerDependencyName, out version); - } - if (version == null) - { - DevDependencies?.TryGetPropertyValue(lowerDependencyName, out version); - } + if (version == null) Engines?.TryGetPropertyValue(lowerDependencyName, out version); + + if (version == null) DevDependencies?.TryGetPropertyValue(lowerDependencyName, out version); return version?.GetValue().ToVersion(); } diff --git a/src/TUI/Domain/Settings.cs b/src/TUI/Domain/Settings.cs index 0a4c676..41085f8 100644 --- a/src/TUI/Domain/Settings.cs +++ b/src/TUI/Domain/Settings.cs @@ -7,6 +7,9 @@ namespace TUI.Domain; [YamlSerializable] public class Settings { + [YamlMember] + public Project[] Projects { get; set; } + public static Settings Init() { var deserializer = new DeserializerBuilder() @@ -16,7 +19,4 @@ public class Settings using var sr = new StreamReader("settings.yaml"); return deserializer.Deserialize(sr.ReadToEnd()); } - - [YamlMember] - public Project[] Projects { get; set; } } \ No newline at end of file diff --git a/src/TUI/Extensions.cs b/src/TUI/Extensions.cs index 310da13..196eb4a 100644 --- a/src/TUI/Extensions.cs +++ b/src/TUI/Extensions.cs @@ -1,3 +1,4 @@ +using System.Globalization; using System.Text.RegularExpressions; @@ -17,18 +18,15 @@ public static class Extensions public static string RemoveColors(this string text) { - return Regex.Replace(text, @"\S\[(\d{0,3}[;m][_]?){0,5}", ""); + return Regex.Replace(text, @"\S\[(\d{0,3}[;m]_?){0,5}", ""); } - + public static int Width(this string text) { - if (string.IsNullOrEmpty(text)) - { - return 0; - } + if (string.IsNullOrEmpty(text)) return 0; var clearText = text.RemoveColors(); - var stringInfo = new System.Globalization.StringInfo(clearText); + var stringInfo = new StringInfo(clearText); return stringInfo.LengthInTextElements; } diff --git a/src/TUI/Program.cs b/src/TUI/Program.cs index ed56ff6..5ea9cc9 100644 --- a/src/TUI/Program.cs +++ b/src/TUI/Program.cs @@ -1,5 +1,5 @@ using TUI.Controls; -using Settings = TUI.Domain.Settings; +using TUI.Domain; Console.Clear(); @@ -10,23 +10,53 @@ var settings = Settings.Init(); var display = new Display(); display.OpenDeps(settings.Projects[0]); -var hotKey = ConsoleKey.NoName; +var key = new ConsoleKeyInfo('1', ConsoleKey.NoName, false, false, false); +var waitCommand = true; do { - switch (hotKey) + if (key.Key == ConsoleKey.Q && !display.CommandLine.IsFocused) { - case ConsoleKey.DownArrow: - display.Next(); - break; - case ConsoleKey.UpArrow: - display.Previous(); - break; - case ConsoleKey.E: - display.ToggleHeader(); - break; + waitCommand = false; + continue; } - hotKey = Console.ReadKey(intercept: true).Key; -} while (hotKey != ConsoleKey.Q); + if (display.CommandLine.IsFocused) + { + switch (key.Key) + { + case ConsoleKey.Escape: + display.CommandLine.IsFocused = false; + break; + default: + Console.Write(key.KeyChar); + + break; + } + } + else + { + switch (key.KeyChar) + { + case ':': + display.OpenCommandLine(); + break; + } + + switch (key.Key) + { + case ConsoleKey.DownArrow: + display.Next(); + break; + case ConsoleKey.UpArrow: + display.Previous(); + break; + case ConsoleKey.E: + display.ToggleHeader(); + break; + } + } + + key = Console.ReadKey(true); +} while (waitCommand); Console.Clear(); \ No newline at end of file diff --git a/src/TUI/Settings/DependencyDto.cs b/src/TUI/Settings/DependencyDto.cs index 53d770c..b341736 100644 --- a/src/TUI/Settings/DependencyDto.cs +++ b/src/TUI/Settings/DependencyDto.cs @@ -13,7 +13,7 @@ public class DependencyDto [DataMember] [YamlMember] public string? Name { get; set; } - + [DataMember] [YamlMember] public string? Icon diff --git a/src/TUI/TUI.csproj b/src/TUI/TUI.csproj index 05b1ebc..8e11941 100644 --- a/src/TUI/TUI.csproj +++ b/src/TUI/TUI.csproj @@ -1,22 +1,22 @@ - - Exe - net7.0 - enable - enable - 0.1.0 - + + Exe + net7.0 + enable + enable + 0.1.0 + - - - - + + + + - - - Always - - + + + Always + + diff --git a/src/TUI/UserInterface/CommandLine.cs b/src/TUI/UserInterface/CommandLine.cs new file mode 100644 index 0000000..20969fb --- /dev/null +++ b/src/TUI/UserInterface/CommandLine.cs @@ -0,0 +1,17 @@ +using TUI.Controls; + + +namespace TUI.UserInterface; + +public class CommandLine : Dashboard +{ + public const int Height = 3; + + public void Render(Position position) + { + base.Render("Command", position, Height); + + Console.SetCursorPosition(position.Left + Theme.BorderWidth + Theme.Padding, position.Top + Theme.BorderWidth); + Console.Write(">"); + } +} \ No newline at end of file diff --git a/src/TUI/UserInterface/Header.cs b/src/TUI/UserInterface/Header.cs index 39bebf7..bda1a3f 100644 --- a/src/TUI/UserInterface/Header.cs +++ b/src/TUI/UserInterface/Header.cs @@ -9,15 +9,6 @@ public class Header : IControl 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() }, @@ -26,22 +17,28 @@ public class Header : IControl { "󰬟", "too old".Warning() } }; + + private readonly Dictionary _hotKeys = new() + { + { "", "select prev" }, + { "", "select next" }, + { "󰬌", "toggle head" }, + { "󰬘", "quit" } + }; + private readonly Dictionary _tags = new() { { Icons.Auth, "Auth" }, { Icons.NetworkPublic, "WWW" }, { Icons.SEO, "SEO" }, - { Icons.GitLab, "VCS" }, + { Icons.GitLab, "VCS" } }; public void Render(Position position) { Console.SetCursorPosition(position.Left, position.Top); - for (var i = 1; i <= Height; i++) - { - Console.WriteLine(new string(' ', Console.WindowWidth - LogoWidth)); - } + for (var i = 1; i <= Height; i++) Console.WriteLine(new string(' ', Console.WindowWidth - LogoWidth)); RenderBlock(0, _hints); RenderBlock(1, _tags); diff --git a/src/TUI/UserInterface/Icons.cs b/src/TUI/UserInterface/Icons.cs index 2e83dfb..fb6976c 100644 --- a/src/TUI/UserInterface/Icons.cs +++ b/src/TUI/UserInterface/Icons.cs @@ -5,6 +5,14 @@ namespace TUI.UserInterface; public static class Icons { + public readonly static Dictionary Applications = new() + { + { NpmPackage, "package" }, + { DockerImage, "image" }, + { Site, "site" }, + { Api, "api" } + }; + public static string GitLab => GetIcon("", "E24329"); public static string GitHub => GetIcon("", "ADBAC7"); public static string Git => GetIcon("", "F14E32"); @@ -19,14 +27,8 @@ public static class Icons public static string Auth => GetIcon("", "FFD700"); public static string NotFound => GetIcon(""); - public readonly static Dictionary Applications = new() + private static string GetIcon(string icon, string? activeColor = null) { - { NpmPackage, "package" }, - { DockerImage, "image" }, - { Site, "site" }, - { Api, "api" }, - }; - - private static string GetIcon(string icon, string? activeColor = null) => - icon.Pastel(activeColor ?? Palette.HintColor); + return 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 c561172..8cc3f6f 100644 --- a/src/TUI/UserInterface/Palette.cs +++ b/src/TUI/UserInterface/Palette.cs @@ -12,10 +12,35 @@ public static class Palette public const string WarningColor = "EC9706"; 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); + public static string Primary(this string currentText, bool isFocused = true) + { + return isFocused + ? currentText.Pastel(PrimaryColor) + : Hint(currentText); + } + + public static string Hint(this string currentText) + { + return currentText.Pastel(HintColor); + } + + public static string Disable(this string currentText) + { + return currentText.RemoveColors().Pastel(HintColor); + } + + public static string Warning(this string currentText) + { + return currentText.Pastel(WarningColor); + } + + public static string Error(this string currentText) + { + return currentText.Pastel(ErrorColor); + } + + public static string Info(this string currentText) + { + return currentText.Pastel(InfoColor); + } } \ No newline at end of file diff --git a/src/TUI/UserInterface/Panel.cs b/src/TUI/UserInterface/Panel.cs index be70b0a..9bba507 100644 --- a/src/TUI/UserInterface/Panel.cs +++ b/src/TUI/UserInterface/Panel.cs @@ -11,6 +11,9 @@ public static class Panel private const int TagCount = 5; private const int TagWidth = 2; + + private static int _marginTop; + public static void RenderRows(SourceDto[] sources, int selectedRowNumber) { for (var index = 0; index < sources.Length; index++) @@ -28,20 +31,18 @@ public static class Panel } for (var index = 0; index < sources.Length; index++) - { Console.SetCursorPosition(TitleWidth, 6 + index + _marginTop + BorderWidth + Theme.Padding); - // var source = sources[index]; - // var package = DownloadPackage(source); - // var resultText = package.Dependencies.React; - // resultText = new string(' ', ColumnWidth - resultText.Width()) + resultText; - // if (selectedRowNumber == index + 1) - // { - // resultText = resultText.PastelBg("292928"); - // } - // - // Console.Write(resultText); - } + // var source = sources[index]; + // var package = DownloadPackage(source); + // var resultText = package.Dependencies.React; + // resultText = new string(' ', ColumnWidth - resultText.Width()) + resultText; + // if (selectedRowNumber == index + 1) + // { + // resultText = resultText.PastelBg("292928"); + // } + // + // Console.Write(resultText); // for (var index = 0; index < sources.Length; index++) // { // var loading = true; @@ -74,9 +75,6 @@ public static class Panel // } } - - private static int _marginTop; - // private static Package DownloadPackage(Source source) // { // if (Packages.TryGetValue(source.Repo, out var downloadPackage))