diff --git a/src/TUI.Engine/SymbolExtensions.cs b/src/TUI.Engine/SymbolExtensions.cs new file mode 100644 index 0000000..86e6a65 --- /dev/null +++ b/src/TUI.Engine/SymbolExtensions.cs @@ -0,0 +1,24 @@ +using Pastel; +using TUI.Engine.Theme; + +namespace TUI.Engine; + +public static class SymbolExtensions +{ + public static string Colorized(this string symbol) => + !SymbolColors.ContainsKey(symbol) ? symbol.Hint() : symbol.Pastel(SymbolColors[symbol]); + + private static readonly Dictionary SymbolColors = new() + { + { Symbols.Git, "F14E32" }, + { Symbols.Site, "BF40BF" }, + { Symbols.GitLab, "E24329" }, + { Symbols.GitHub, "ADBAC7" }, + { Symbols.NetworkPublic, "00FFFF" }, + { Symbols.Api, "7F52FF" }, + { Symbols.DockerImage, "086DD7" }, + { Symbols.NpmPackage, "CB0000" }, + { Symbols.SEO, "4285F4" }, + { Symbols.Auth, "FFD700" }, + }; +} \ No newline at end of file diff --git a/src/TUI.Engine/Symbols.cs b/src/TUI.Engine/Symbols.cs index 3857193..a96a98f 100644 --- a/src/TUI.Engine/Symbols.cs +++ b/src/TUI.Engine/Symbols.cs @@ -1,6 +1,3 @@ -using Pastel; -using TUI.Engine.Theme; - namespace TUI.Engine; public static class Symbols @@ -35,24 +32,4 @@ public static class Symbols public const string LeftTop = "┌"; public const string RightBottom = "┘"; } -} - -public static class CharExtensions -{ - public static string Colorized(this string symbol) => - !SymbolColors.ContainsKey(symbol) ? symbol.Hint() : symbol.Pastel(SymbolColors[symbol]); - - private static readonly Dictionary SymbolColors = new() - { - { Symbols.Git, "F14E32" }, - { Symbols.Site, "BF40BF" }, - { Symbols.GitLab, "E24329" }, - { Symbols.GitHub, "ADBAC7" }, - { Symbols.NetworkPublic, "00FFFF" }, - { Symbols.Api, "7F52FF" }, - { Symbols.DockerImage, "086DD7" }, - { Symbols.NpmPackage, "CB0000" }, - { Symbols.SEO, "4285F4" }, - { Symbols.Auth, "FFD700" }, - }; } \ No newline at end of file diff --git a/src/TUI/Controls/Components/VersionComponent.cs b/src/TUI/Controls/Components/VersionComponent.cs index 86babe3..bd1bd78 100644 --- a/src/TUI/Controls/Components/VersionComponent.cs +++ b/src/TUI/Controls/Components/VersionComponent.cs @@ -9,23 +9,22 @@ public class VersionComponent : ComponentBase { private readonly VersionType _type; private readonly string _version; - private readonly string? _icon; + private readonly Brand? _brand; - public VersionComponent(VersionType type, string version, string? icon = null) + public VersionComponent(VersionType type, string version, Brand? brand) { _type = type; _version = version; - _icon = icon; + _brand = brand; } protected override Sketch DrawComponent(Size minSize) { var builder = new StringBuilder(); - if (_icon is not null) + if (_brand is not null) { - builder.Append(_icon.Colorized()); - builder.Append(Symbols.Space); + builder.Append(_brand.ColorLogo()); } builder.Append(_version); diff --git a/src/TUI/Controls/Containers/DashboardContainer.cs b/src/TUI/Controls/Containers/DashboardContainer.cs index ac27e73..e083c49 100644 --- a/src/TUI/Controls/Containers/DashboardContainer.cs +++ b/src/TUI/Controls/Containers/DashboardContainer.cs @@ -2,6 +2,7 @@ using TUI.Controls.Components; using TUI.Engine.Attributes.Orientations; using TUI.Engine.Containers; using TUI.Engine.Nodes; +using TUI.Engine.Theme; namespace TUI.Controls.Containers; @@ -12,7 +13,8 @@ public class DashboardContainer : ContainerBase public DashboardContainer() { - var panel = new PanelComponent("Dependencies"); + // var panel = new PanelComponent("Dependencies ".Info() + Symbols.Node.Colorized()); + var panel = new PanelComponent("Dependencies".Info()); _content = new ContentContainer(); _content.SetOrientationVertical(); SetOrientationVertical(); diff --git a/src/TUI/Controls/Containers/DependenciesContainer.cs b/src/TUI/Controls/Containers/DependenciesContainer.cs new file mode 100644 index 0000000..37b9c8f --- /dev/null +++ b/src/TUI/Controls/Containers/DependenciesContainer.cs @@ -0,0 +1,49 @@ +using TUI.Controls.Common; +using TUI.Controls.Components; +using TUI.Domain; +using TUI.Engine.Attributes; +using TUI.Engine.Attributes.Alignments; +using TUI.Engine.Attributes.Orientations; +using TUI.Engine.Components; +using TUI.Engine.Containers; +using TUI.Engine.Nodes; +using TUI.Engine.Theme; + +namespace TUI.Controls.Containers; + +public class DependenciesContainer : ContainerBase +{ + private const int VersionColumnWidth = 10; + private const int TitleColumnWidth = 20; + + private readonly Nodes _dependencies = new(); + + public void AddTitleStub() + { + var size = new Size(TitleColumnWidth, 1); + var title = new StubComponent(size); + title.SetPadding(Level.Normal); + + _dependencies.Add(title); + } + + public void AddTitle(IComponent title) + { + title.SetPadding(Level.Normal); + title.SetFixed(Orientation.Horizontal, TitleColumnWidth); + + _dependencies.Add(title); + } + + public void AddDependency(Dependency dependency) + { + var version = new VersionComponent(VersionType.Convention, dependency.Version, dependency.Brand); + version.SetPadding(Level.Normal); + version.SetAlignment(Horizontal.Right); + version.SetFixed(Orientation.Horizontal, VersionColumnWidth); + + _dependencies.Add(version); + } + + public override Nodes GetNodes() => _dependencies; +} \ No newline at end of file diff --git a/src/TUI/Controls/Containers/DependencyContainer.cs b/src/TUI/Controls/Containers/DependencyContainer.cs deleted file mode 100644 index 22569c7..0000000 --- a/src/TUI/Controls/Containers/DependencyContainer.cs +++ /dev/null @@ -1,29 +0,0 @@ -using TUI.Controls.Common; -using TUI.Controls.Components; -using TUI.Engine; -using TUI.Engine.Attributes; -using TUI.Engine.Attributes.Alignments; -using TUI.Engine.Attributes.Orientations; -using TUI.Engine.Containers; -using TUI.Engine.Nodes; -using TUI.Engine.Theme; - -namespace TUI.Controls.Containers; - -public class DependencyContainer : ContainerBase -{ - private const int VersionColumnWidth = 10; - - public override Nodes GetNodes() - { - var stub = new StubComponent(new Size(20, 1)); - stub.SetPadding(Level.Normal); - - var version = new VersionComponent(VersionType.Convention, "10.20.30", Symbols.Site); - version.SetPadding(Level.Normal); - version.SetAlignment(Horizontal.Right); - version.SetFixed(Orientation.Horizontal, VersionColumnWidth); - - return new Nodes { stub, version, version, }; - } -} \ No newline at end of file diff --git a/src/TUI/Domain/Brand.cs b/src/TUI/Domain/Brand.cs new file mode 100644 index 0000000..0530a0b --- /dev/null +++ b/src/TUI/Domain/Brand.cs @@ -0,0 +1,8 @@ +using Pastel; + +namespace TUI.Controls.Components; + +public record Brand(string Name, string Logo, string Color) +{ + public string ColorLogo() => Logo.Pastel(Color); +}; \ No newline at end of file diff --git a/src/TUI/Domain/Dependency.cs b/src/TUI/Domain/Dependency.cs new file mode 100644 index 0000000..38ff60d --- /dev/null +++ b/src/TUI/Domain/Dependency.cs @@ -0,0 +1,5 @@ +using TUI.Controls.Components; + +namespace TUI.Domain; + +public record Dependency(string Version, Brand Brand); \ No newline at end of file diff --git a/src/TUI/Domain/ProjectDto.cs b/src/TUI/Domain/ProjectDto.cs deleted file mode 100644 index df48aa4..0000000 --- a/src/TUI/Domain/ProjectDto.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Runtime.Serialization; -using TUI.Settings; -using YamlDotNet.Serialization; - - -namespace TUI.Domain; - -[DataContract] -[YamlSerializable] -public class ProjectDto -{ - [YamlMember] - [DataMember] - public string Icon { get; set; } - - [YamlMember] - [DataMember] - public string Name { get; set; } - - [YamlMember] - [DataMember] - public DependencyDto[] Dependencies { get; set; } - - [YamlMember] - [DataMember] - public IList Sources { get; set; } -} \ No newline at end of file diff --git a/src/TUI/Domain/Settings.cs b/src/TUI/Domain/Settings.cs deleted file mode 100644 index 6f03fe8..0000000 --- a/src/TUI/Domain/Settings.cs +++ /dev/null @@ -1,22 +0,0 @@ -using YamlDotNet.Serialization; -using YamlDotNet.Serialization.NamingConventions; - - -namespace TUI.Domain; - -[YamlSerializable] -public class Settings -{ - [YamlMember] - public ProjectDto[] Projects { get; set; } - - public static Settings Init() - { - var deserializer = new DeserializerBuilder() - .WithNamingConvention(UnderscoredNamingConvention.Instance) - .Build(); - - using var sr = new StreamReader("settings.yaml"); - return deserializer.Deserialize(sr.ReadToEnd()); - } -} \ No newline at end of file diff --git a/src/TUI/Pages/DependenciesPage.cs b/src/TUI/Pages/DependenciesPage.cs index f9956e3..bd1862a 100644 --- a/src/TUI/Pages/DependenciesPage.cs +++ b/src/TUI/Pages/DependenciesPage.cs @@ -2,33 +2,66 @@ using System.Diagnostics; using TUI.Controls.Containers; using TUI.Controls.Layouts; using TUI.Controls.Statics; +using TUI.Domain; using TUI.Engine.Rendering.Canvas; +using TUI.Providers.Dependencies; namespace TUI.Pages; -public class DependenciesPage +interface IPage +{ + void Open(); + void Render(); + void Bind(); +} + +public abstract class PageBase : IPage { public void Open() { - Debugger.Log(0, "Event", "Open page dependencies\n"); + Debugger.Log(0, "Event", $"Open page ${GetType().UnderlyingSystemType.Name}\n"); + Bind(); + Render(); + } + public abstract void Render(); + + public abstract void Bind(); +} + +public class DependenciesPage : PageBase +{ + private IEnumerable ConventionDependencies; + + public override void Render() + { ICanvas canvas = new ConsoleCanvas(); var header = new HeaderContainer(); var copyright = new CopyrightComponent(); var dashboard = new DashboardContainer(); - var layout = new DashboardLayout(header, dashboard, copyright); - var dependency = new DependencyContainer(); - dashboard.AddChildren(dependency); - dashboard.AddChildren(dependency); - dashboard.AddChildren(dependency); - dashboard.AddChildren(dependency); + var dependenciesHeader = new DependenciesContainer(); + dependenciesHeader.AddTitleStub(); + + foreach (var conventionDependency in ConventionDependencies) + { + dependenciesHeader.AddDependency(conventionDependency); + } + + dashboard.AddChildren(dependenciesHeader); // CommandLine = new CommandLine(); // DependenciesView = new DependenciesView(); + var layout = new DashboardLayout(header, dashboard, copyright); canvas.Draw(layout); } + public override void Bind() + { + var repo = new DependencyRepository(); + ConventionDependencies = repo.Read("javascript"); + } + // private bool _commandLineInDisplay; // private ProjectDto _currentProjectDto; diff --git a/src/TUI/Providers/Dependencies/DependenciesDto.cs b/src/TUI/Providers/Dependencies/DependenciesDto.cs new file mode 100644 index 0000000..f42b152 --- /dev/null +++ b/src/TUI/Providers/Dependencies/DependenciesDto.cs @@ -0,0 +1,11 @@ +using System.Runtime.Serialization; +using YamlDotNet.Serialization; + +namespace TUI.Providers.Dependencies; + +[DataContract] +[YamlSerializable] +public class DependenciesDto +{ + [DataMember] [YamlMember] public StackDto[] Stacks { get; set; } +} \ No newline at end of file diff --git a/src/TUI/Settings/DependencyDto.cs b/src/TUI/Providers/Dependencies/DependencyDto.cs similarity index 92% rename from src/TUI/Settings/DependencyDto.cs rename to src/TUI/Providers/Dependencies/DependencyDto.cs index b341736..10c0715 100644 --- a/src/TUI/Settings/DependencyDto.cs +++ b/src/TUI/Providers/Dependencies/DependencyDto.cs @@ -1,8 +1,7 @@ using System.Runtime.Serialization; using YamlDotNet.Serialization; - -namespace TUI.Settings; +namespace TUI.Providers.Dependencies; [DataContract] [YamlSerializable] diff --git a/src/TUI/Providers/Dependencies/DependencyRepository.cs b/src/TUI/Providers/Dependencies/DependencyRepository.cs new file mode 100644 index 0000000..9b2845d --- /dev/null +++ b/src/TUI/Providers/Dependencies/DependencyRepository.cs @@ -0,0 +1,43 @@ +using TUI.Controls.Components; +using TUI.Domain; +using YamlDotNet.Serialization; +using YamlDotNet.Serialization.NamingConventions; + +namespace TUI.Providers.Dependencies; + +public class DependencyRepository +{ + private DependenciesDto? _dependenciesDto; + + private DependenciesDto DependenciesDto + { + get + { + if (_dependenciesDto is not null) + { + return _dependenciesDto; + } + + var deserializer = new DeserializerBuilder() + .WithNamingConvention(UnderscoredNamingConvention.Instance) + .Build(); + + using var sr = new StreamReader("dependencies.yaml"); + _dependenciesDto = deserializer.Deserialize(sr.ReadToEnd()); + + return _dependenciesDto; + } + } + + public IEnumerable Read(string stackName) + { + return DependenciesDto.Stacks + .Single(stack => stack.Name == stackName) + .Conventions + .Select(convention => + { + var brand = new Brand(convention.Name, convention.Icon, convention.Color); + return new Dependency(convention.Version, brand); + }); + } +} \ No newline at end of file diff --git a/src/TUI/Providers/Dependencies/HubDto.cs b/src/TUI/Providers/Dependencies/HubDto.cs new file mode 100644 index 0000000..ebb225f --- /dev/null +++ b/src/TUI/Providers/Dependencies/HubDto.cs @@ -0,0 +1,15 @@ +using System.Runtime.Serialization; +using YamlDotNet.Serialization; + +namespace TUI.Providers.Dependencies; + +[DataContract] +[YamlSerializable] +public class HubDto +{ + [YamlMember] [DataMember] public string Origin { get; set; } + + [YamlMember] [DataMember] public string Type { get; set; } + + [YamlMember] [DataMember] public IEnumerable Projects { get; set; } +} \ No newline at end of file diff --git a/src/TUI/Domain/Package.cs b/src/TUI/Providers/Dependencies/Package.cs similarity index 95% rename from src/TUI/Domain/Package.cs rename to src/TUI/Providers/Dependencies/Package.cs index b9d5519..2fb82a9 100644 --- a/src/TUI/Domain/Package.cs +++ b/src/TUI/Providers/Dependencies/Package.cs @@ -2,8 +2,7 @@ using System.Text.Json.Nodes; using System.Text.Json.Serialization; using TUI.Engine; - -namespace TUI.Domain; +namespace TUI.Providers.Dependencies; public class Package { diff --git a/src/TUI/Providers/Dependencies/ProjectDto.cs b/src/TUI/Providers/Dependencies/ProjectDto.cs new file mode 100644 index 0000000..72066e5 --- /dev/null +++ b/src/TUI/Providers/Dependencies/ProjectDto.cs @@ -0,0 +1,16 @@ +using System.Runtime.Serialization; +using YamlDotNet.Serialization; + +namespace TUI.Providers.Dependencies; + +[YamlSerializable] +public class ProjectDto +{ + [DataMember] [YamlMember] public int Id { get; set; } + + [DataMember] [YamlMember] public string Name { get; set; } + + [DataMember] [YamlMember] public string Deps { get; set; } + + [DataMember] [YamlMember] public IEnumerable Tags { get; set; } +} \ No newline at end of file diff --git a/src/TUI/Providers/Dependencies/StackDto.cs b/src/TUI/Providers/Dependencies/StackDto.cs new file mode 100644 index 0000000..9c10cc6 --- /dev/null +++ b/src/TUI/Providers/Dependencies/StackDto.cs @@ -0,0 +1,17 @@ +using System.Runtime.Serialization; +using YamlDotNet.Serialization; + +namespace TUI.Providers.Dependencies; + +[DataContract] +[YamlSerializable] +public class StackDto +{ + [YamlMember] [DataMember] public string Name { get; set; } + + [YamlMember] [DataMember] public string Icon { get; set; } + + [YamlMember] [DataMember] public DependencyDto[] Conventions { get; set; } + + [YamlMember] [DataMember] public IEnumerable Hubs { get; set; } +} \ No newline at end of file diff --git a/src/TUI/Settings/SourceDto.cs b/src/TUI/Settings/SourceDto.cs deleted file mode 100644 index 100db53..0000000 --- a/src/TUI/Settings/SourceDto.cs +++ /dev/null @@ -1,20 +0,0 @@ -using YamlDotNet.Serialization; - - -namespace TUI.Settings; - -[YamlSerializable] -public class SourceDto -{ - [YamlMember] - public string[] Tags { get; set; } - - [YamlMember] - public string Name { get; set; } - - [YamlMember] - public int ProjectId { get; set; } = 0; - - [YamlMember] - public string Repo { get; set; } -} \ No newline at end of file diff --git a/src/TUI/Store/DependenciesStore.cs b/src/TUI/Store/DependenciesStore.cs index 82eb923..d7f4388 100644 --- a/src/TUI/Store/DependenciesStore.cs +++ b/src/TUI/Store/DependenciesStore.cs @@ -1,7 +1,5 @@ using System.Text.Json; -using TUI.Domain; -using TUI.Engine; -using TUI.Settings; +using TUI.Providers.Dependencies; namespace TUI.Store; @@ -9,9 +7,10 @@ public static class DependenciesStore { private readonly static Dictionary Packages = new(); - private static Package DownloadPackage(SourceDto sourceDto) + private static Package DownloadPackage(ProjectDto projectDto) { - var endpoint = sourceDto.Tags.Have("gitlab") ? GetGitlabEndpoint(sourceDto) : sourceDto.Repo; + // var endpoint = projectDto.Tags.Have("gitlab") ? GetGitlabEndpoint(projectDto) : projectDto.Repo; + var endpoint = ""; if (Packages.TryGetValue(endpoint, out var downloadPackage)) return downloadPackage; using HttpClient client = new(); @@ -21,10 +20,11 @@ public static class DependenciesStore return package; } - private static string GetGitlabEndpoint(SourceDto sourceDto) + private static string GetGitlabEndpoint(ProjectDto projectDto) { var token = Environment.GetEnvironmentVariable("TLD_GITLAB_PAT"); - return $"{sourceDto.Repo}/api/v4/projects/{sourceDto.ProjectId}/repository/files/package.json/raw?" + - $"private_token={token}&ref=dev"; + // return $"{projectDto.Repo}/api/v4/projects/{projectDto.ProjectId}/repository/files/package.json/raw?" + + // $"private_token={token}&ref=dev"; + return ""; } } \ No newline at end of file diff --git a/src/TUI/TUI.csproj b/src/TUI/TUI.csproj index 1250cb0..f38e70b 100644 --- a/src/TUI/TUI.csproj +++ b/src/TUI/TUI.csproj @@ -14,7 +14,7 @@ - + Always @@ -30,5 +30,8 @@ + + + diff --git a/src/TUI/UserInterface/Icons.cs b/src/TUI/UserInterface/Icons.cs index 63ceaea..e904383 100644 --- a/src/TUI/UserInterface/Icons.cs +++ b/src/TUI/UserInterface/Icons.cs @@ -1,3 +1,4 @@ +using Pastel; using TUI.Engine; @@ -7,9 +8,9 @@ public static class Icons { public static readonly Dictionary Applications = new() { - { Symbols.NpmPackage, "package" }, - { Symbols.DockerImage, "image" }, - { Symbols.Site, "site" }, + { Symbols.NpmPackage.Colorized(), "package" }, + { Symbols.DockerImage.Colorized(), "image" }, + { Symbols.Site.Pastel("666666"), "site" }, { Symbols.Api, "api" } }; } \ No newline at end of file diff --git a/src/TUI/UserInterface/Panel.cs b/src/TUI/UserInterface/Panel.cs index 157062e..0054752 100644 --- a/src/TUI/UserInterface/Panel.cs +++ b/src/TUI/UserInterface/Panel.cs @@ -1,5 +1,5 @@ using TUI.Engine.Theme; -using TUI.Settings; +using TUI.Providers.Dependencies; namespace TUI.UserInterface; @@ -15,7 +15,7 @@ public static class Panel private static int _marginTop; - public static void RenderRows(SourceDto[] sources, int selectedRowNumber) + public static void RenderRows(ProjectDto[] sources, int selectedRowNumber) { for (var index = 0; index < sources.Length; index++) { diff --git a/tests/TUI.Controls.Tests/VersionComponentTests.cs b/tests/TUI.Controls.Tests/VersionComponentTests.cs index 5822173..66111a5 100644 --- a/tests/TUI.Controls.Tests/VersionComponentTests.cs +++ b/tests/TUI.Controls.Tests/VersionComponentTests.cs @@ -16,7 +16,8 @@ namespace TUI.Engine.Tests [InlineData(VersionType.TooOld, "\u001b[38;2;236;151;6m10.12.33\u001b[0m")] public void DrawSketchVersionTypes(VersionType versionType, string expected) { - var version = new VersionComponent(versionType, "10.12.33"); + var brand = new Brand("Docker", "󰡨", "#1d63ed"); + var version = new VersionComponent(versionType, "10.12.33", brand); var sketch = (version as IComponent).MakeSketch(new Size(10, 2));