From d7d2fcd0a6e8ca25d4b94bc5fc316b0ef5de186c 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: Fri, 14 Jun 2024 16:45:30 +0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=85=20Catch=20error=20and=20render.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/TUI.Engine/Symbols.cs | 2 ++ .../Controls/Components/VersionComponent.cs | 8 +++-- .../Controls/Components/VersionExtensions.cs | 28 ++++++++++++++++++ src/TUI/Controls/Components/VersionType.cs | 2 +- .../Components/VersionTypeExtensions.cs | 16 ---------- .../Containers/DependenciesContainer.cs | 18 +++++++++++- src/TUI/Pages/DependenciesPage.cs | 29 ++++++++++++------- src/TUI/Store/DependenciesStore.cs | 6 ++-- 8 files changed, 76 insertions(+), 33 deletions(-) create mode 100644 src/TUI/Controls/Components/VersionExtensions.cs delete mode 100644 src/TUI/Controls/Components/VersionTypeExtensions.cs diff --git a/src/TUI.Engine/Symbols.cs b/src/TUI.Engine/Symbols.cs index b88094e..654907f 100644 --- a/src/TUI.Engine/Symbols.cs +++ b/src/TUI.Engine/Symbols.cs @@ -18,6 +18,8 @@ public static class Symbols public const string Seo = "󰚩"; public const string Auth = ""; public const string NotFound = ""; + public const string Error = ""; + public const string Download = ""; public static class Lines { diff --git a/src/TUI/Controls/Components/VersionComponent.cs b/src/TUI/Controls/Components/VersionComponent.cs index 0f4408b..d8016d4 100644 --- a/src/TUI/Controls/Components/VersionComponent.cs +++ b/src/TUI/Controls/Components/VersionComponent.cs @@ -1,7 +1,9 @@ using System.Text; using TUI.Domain; +using TUI.Engine; using TUI.Engine.Attributes; using TUI.Engine.Components; +using TUI.Engine.Theme; namespace TUI.Controls.Components; @@ -25,16 +27,18 @@ public class VersionComponent : ComponentBase { var builder = new StringBuilder(); - // builder.Append(_type.ToString()); if (_brand is not null) { builder.Append(_brand.ColorLogo()); } + builder.Append(_type.ToImage().Warning()); + builder.Append(Symbols.Space); builder.Append(_version); var sketch = builder.ToString(); return new Sketch(_status.Colorize(sketch)); } -} \ No newline at end of file +} + diff --git a/src/TUI/Controls/Components/VersionExtensions.cs b/src/TUI/Controls/Components/VersionExtensions.cs new file mode 100644 index 0000000..5de4afa --- /dev/null +++ b/src/TUI/Controls/Components/VersionExtensions.cs @@ -0,0 +1,28 @@ +using TUI.Engine.Theme; + +namespace TUI.Controls.Components; + +public static class VersionExtensions +{ + public static string ToImage(this VersionType versionType) + => + versionType switch + { + VersionType.Alpha => "󰀫", + VersionType.Beta => "󰂡", + VersionType.Candidate => "󰑣", + VersionType.Canary => "󱗆", + VersionType.Next => "󰒭", + _ => "" + }; + + public static string Colorize(this VersionStatus versionStatus, string value) => + versionStatus switch + { + VersionStatus.TooOld => value.Warning(), + VersionStatus.ToNew => value.Info(), + VersionStatus.SoGood => value.Hint(), + VersionStatus.BeNice => value.Main(), + _ => value + }; +} \ No newline at end of file diff --git a/src/TUI/Controls/Components/VersionType.cs b/src/TUI/Controls/Components/VersionType.cs index 786c668..a7fac98 100644 --- a/src/TUI/Controls/Components/VersionType.cs +++ b/src/TUI/Controls/Components/VersionType.cs @@ -9,4 +9,4 @@ public enum VersionType Alpha, Beta, Next, -} \ No newline at end of file +} diff --git a/src/TUI/Controls/Components/VersionTypeExtensions.cs b/src/TUI/Controls/Components/VersionTypeExtensions.cs deleted file mode 100644 index 519815b..0000000 --- a/src/TUI/Controls/Components/VersionTypeExtensions.cs +++ /dev/null @@ -1,16 +0,0 @@ -using TUI.Engine.Theme; - -namespace TUI.Controls.Components; - -public static class VersionTypeExtensions -{ - public static string Colorize(this VersionStatus versionStatus, string value) => - versionStatus switch - { - VersionStatus.TooOld => value.Warning(), - VersionStatus.ToNew => value.Info(), - VersionStatus.SoGood => value.Hint(), - VersionStatus.BeNice => value.Main(), - _ => value - }; -} \ No newline at end of file diff --git a/src/TUI/Controls/Containers/DependenciesContainer.cs b/src/TUI/Controls/Containers/DependenciesContainer.cs index 23393c9..ecf373f 100644 --- a/src/TUI/Controls/Containers/DependenciesContainer.cs +++ b/src/TUI/Controls/Containers/DependenciesContainer.cs @@ -16,7 +16,7 @@ public class DependenciesContainer : ContainerBase { public readonly Project? Project; - private const int VersionColumnWidth = 10; + private const int VersionColumnWidth = 11; private const int TitleColumnWidth = 25; @@ -70,6 +70,22 @@ public class DependenciesContainer : ContainerBase _dependencies.Add(stub); } + public void AddError() + { + var size = new Size(25, 1); + var stub = new StubComponent(size, (Symbols.Error + Symbols.Space + " Something went wrong").Error()); + stub.SetPadding(Level.Normal); + stub.SetAlignment(Horizontal.Right); + stub.SetFixed(Orientation.Horizontal, 25); + + if (Project is not null && Project.Legacy) + { + stub.StyleContext = new StyleContext(Palette.DisableColor); + } + + _dependencies.Add(stub); + } + public void AddDependency(Dependency dependency, VersionStatus status = VersionStatus.BeNice) { var version = new VersionComponent(dependency.Version, dependency.Brand, status, dependency.Type); diff --git a/src/TUI/Pages/DependenciesPage.cs b/src/TUI/Pages/DependenciesPage.cs index f2b7f5e..c558011 100644 --- a/src/TUI/Pages/DependenciesPage.cs +++ b/src/TUI/Pages/DependenciesPage.cs @@ -62,20 +62,27 @@ public class DependenciesPage : PageBase var project = projectDependencies.Project; var actualDependencies = _store.ActualDependencies(project).ToArray(); - foreach (var conventionDependency in _store.ConventionDependencies) + if (!actualDependencies.Any()) { - var actualDependency = actualDependencies.SingleOrDefault( - dependency => string.Equals(dependency.Brand.Name, conventionDependency.Brand.Name, - StringComparison.CurrentCultureIgnoreCase)); - - if (actualDependency is null) + projectDependencies.AddError(); + } + else + { + foreach (var conventionDependency in _store.ConventionDependencies) { - projectDependencies.AddDependencyStub(); - continue; + var actualDependency = actualDependencies.SingleOrDefault( + dependency => string.Equals(dependency.Brand.Name, conventionDependency.Brand.Name, + StringComparison.CurrentCultureIgnoreCase)); + + if (actualDependency is null) + { + projectDependencies.AddDependencyStub(); + continue; + } + + var versionType = actualDependency.Comparison(conventionDependency); + projectDependencies.AddDependency(actualDependency, versionType); } - - var versionType = actualDependency.Comparison(conventionDependency); - projectDependencies.AddDependency(actualDependency, versionType); } Render(); diff --git a/src/TUI/Store/DependenciesStore.cs b/src/TUI/Store/DependenciesStore.cs index 6c0c431..8d4b8a9 100644 --- a/src/TUI/Store/DependenciesStore.cs +++ b/src/TUI/Store/DependenciesStore.cs @@ -1,5 +1,6 @@ using TUI.Controls.Components; using TUI.Domain; +using TUI.Engine; using TUI.Engine.Theme; using TUI.Providers.Dependencies; @@ -15,14 +16,15 @@ public class DependenciesStore public IEnumerable ActualDependencies(Project project) { - SpeakerComponent.Instance.Shout("", $"Fetch actual dependencies for project {project.Name.Main()}"); + SpeakerComponent.Instance.Shout(Symbols.Download.Info(), $"Fetch actual dependencies for project {project.Name.Main + ()}"); try { return Repository.ReadActual(project); } catch { - SpeakerComponent.Instance.Shout("", $"Fetch failed for project{project.Name}"); + SpeakerComponent.Instance.Shout(Symbols.Error.Error(), $"Fetch failed for project{project.Name}"); return new List(); } }