diff --git a/src/TUI.Engine/Nodes/INode.cs b/src/TUI.Engine/Nodes/INode.cs index 6bdfb87..97e3966 100644 --- a/src/TUI.Engine/Nodes/INode.cs +++ b/src/TUI.Engine/Nodes/INode.cs @@ -1,7 +1,12 @@ +using TUI.Engine.Attributes; using TUI.Engine.Attributes.Resizings; +using TUI.Engine.Rendering.Canvas; namespace TUI.Engine.Nodes; public interface INode : IResizable { -} \ No newline at end of file + DrawContext DrawContext { get; set; } +} + +public record DrawContext(ICanvas Canvas, Position Pencil, Size MaxSize); \ No newline at end of file diff --git a/src/TUI.Engine/Nodes/NodeBase.cs b/src/TUI.Engine/Nodes/NodeBase.cs index bb28979..79a4182 100644 --- a/src/TUI.Engine/Nodes/NodeBase.cs +++ b/src/TUI.Engine/Nodes/NodeBase.cs @@ -55,4 +55,6 @@ public abstract class NodeBase : INode } #endregion Resizing + + public DrawContext? DrawContext { get; set; } } \ No newline at end of file diff --git a/src/TUI.Engine/Rendering/ComponentCraftsman.cs b/src/TUI.Engine/Rendering/ComponentCraftsman.cs index 70f4044..cfb7e4a 100644 --- a/src/TUI.Engine/Rendering/ComponentCraftsman.cs +++ b/src/TUI.Engine/Rendering/ComponentCraftsman.cs @@ -25,6 +25,8 @@ internal sealed class ComponentCraftsman : CraftsmanBase, IDrawable foreach (var line in sketch.Crop(maxSize)) { + component.DrawContext = new DrawContext(_canvas, pencil, maxSize); + _canvas.SetPencil(correctedPencil); _canvas.Paint(line); diff --git a/src/TUI/Controls/Components/SpeakerComponent.cs b/src/TUI/Controls/Components/SpeakerComponent.cs new file mode 100644 index 0000000..1066978 --- /dev/null +++ b/src/TUI/Controls/Components/SpeakerComponent.cs @@ -0,0 +1,50 @@ +using TUI.Engine; +using TUI.Engine.Attributes; +using TUI.Engine.Components; +using TUI.Engine.Nodes; + +namespace TUI.Controls.Components; + +public class SpeakerComponent : ComponentBase +{ + private string _message = ""; + + private Position? _pencil; + + private SpeakerComponent() + { + } + + public static SpeakerComponent Instance { get; } = new(); + + protected override Sketch DrawComponent(Size minSize) + { + return new Sketch(_message); + } + + private void Clear() + { + _message = new string(' ', DrawContext.MaxSize.Width); + DrawContext.Canvas.Draw(Instance, _pencil, DrawContext.MaxSize); + } + + public void Shout(string emoji, string message) + { + if (DrawContext is null) + { + return; + } + + _pencil ??= DrawContext.Pencil with { }; + + Clear(); + _message = emoji + Symbols.Space + message; + DrawContext.Canvas.Draw(Instance, _pencil, DrawContext.MaxSize); + + Task.Delay(2000).ContinueWith(_ => + { + Clear(); + return Task.CompletedTask; + }); + } +} \ No newline at end of file diff --git a/src/TUI/Controls/Components/VersionComponent.cs b/src/TUI/Controls/Components/VersionComponent.cs index bd1bd78..23d6e70 100644 --- a/src/TUI/Controls/Components/VersionComponent.cs +++ b/src/TUI/Controls/Components/VersionComponent.cs @@ -1,5 +1,4 @@ using System.Text; -using TUI.Engine; using TUI.Engine.Attributes; using TUI.Engine.Components; diff --git a/src/TUI/Controls/Containers/FooterContainer.cs b/src/TUI/Controls/Containers/FooterContainer.cs index 90c98d5..132e7fb 100644 --- a/src/TUI/Controls/Containers/FooterContainer.cs +++ b/src/TUI/Controls/Containers/FooterContainer.cs @@ -1,3 +1,4 @@ +using TUI.Controls.Components; using TUI.Controls.Statics; using TUI.Engine.Attributes.Alignments; using TUI.Engine.Components; @@ -10,12 +11,15 @@ namespace TUI.Controls.Containers; public class FooterContainer : ContainerBase { private readonly INode _breadcrumbs; + private readonly INode _speaker; - public FooterContainer(IComponent breadcrumbs) + public FooterContainer(IComponent? breadcrumbs) { breadcrumbs.SetAlignment(Horizontal.Left); breadcrumbs.SetPaddingLeft(Level.Normal); _breadcrumbs = breadcrumbs; + + _speaker = SpeakerComponent.Instance; } public override Nodes GetNodes() @@ -23,6 +27,6 @@ public class FooterContainer : ContainerBase var copyright = new CopyrightComponent(); copyright.SetAlignment(Horizontal.Right); copyright.SetPaddingRight(Level.Normal); - return new Nodes { _breadcrumbs, copyright }; + return new Nodes { _breadcrumbs, _speaker, copyright }; } } \ No newline at end of file diff --git a/src/TUI/Controls/Layouts/DashboardLayout.cs b/src/TUI/Controls/Layouts/DashboardLayout.cs index f8e75e6..20124f1 100644 --- a/src/TUI/Controls/Layouts/DashboardLayout.cs +++ b/src/TUI/Controls/Layouts/DashboardLayout.cs @@ -1,6 +1,4 @@ -using TUI.Engine.Attributes.Alignments; using TUI.Engine.Attributes.Orientations; -using TUI.Engine.Components; using TUI.Engine.Containers; using TUI.Engine.Nodes; diff --git a/src/TUI/Pages/DependenciesPage.cs b/src/TUI/Pages/DependenciesPage.cs index 985f2b9..0977680 100644 --- a/src/TUI/Pages/DependenciesPage.cs +++ b/src/TUI/Pages/DependenciesPage.cs @@ -1,37 +1,11 @@ -using System.Diagnostics; using TUI.Controls.Components; using TUI.Controls.Containers; using TUI.Controls.Layouts; -using TUI.Controls.Statics; -using TUI.Domain; -using TUI.Engine; using TUI.Engine.Rendering.Canvas; -using TUI.Providers.Dependencies; using TUI.Store; namespace TUI.Pages; -interface IPage -{ - void Open(); - void Render(); - void Bind(); -} - -public abstract class PageBase : IPage -{ - public void Open() - { - 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 DependenciesStore _store; diff --git a/src/TUI/Pages/IPage.cs b/src/TUI/Pages/IPage.cs new file mode 100644 index 0000000..3a9b32a --- /dev/null +++ b/src/TUI/Pages/IPage.cs @@ -0,0 +1,8 @@ +namespace TUI.Pages; + +interface IPage +{ + void Open(); + void Render(); + void Bind(); +} \ No newline at end of file diff --git a/src/TUI/Pages/PageBase.cs b/src/TUI/Pages/PageBase.cs new file mode 100644 index 0000000..2dbce48 --- /dev/null +++ b/src/TUI/Pages/PageBase.cs @@ -0,0 +1,17 @@ +using System.Diagnostics; + +namespace TUI.Pages; + +public abstract class PageBase : IPage +{ + public void Open() + { + Debugger.Log(0, "Event", $"Open page ${GetType().UnderlyingSystemType.Name}\n"); + Bind(); + Render(); + } + + public abstract void Render(); + + public abstract void Bind(); +} \ No newline at end of file diff --git a/src/TUI/Pages/WelcomePage.cs b/src/TUI/Pages/WelcomePage.cs new file mode 100644 index 0000000..169c276 --- /dev/null +++ b/src/TUI/Pages/WelcomePage.cs @@ -0,0 +1,33 @@ +using TUI.Controls.Common; +using TUI.Controls.Components; +using TUI.Controls.Containers; +using TUI.Controls.Layouts; +using TUI.Controls.Statics; +using TUI.Engine.Attributes; +using TUI.Engine.Rendering.Canvas; + +namespace TUI.Pages; + +public class WelcomePage : PageBase +{ + public override void Render() + { + ICanvas canvas = new ConsoleCanvas(); + + var header = new StubComponent(new Size(1, 1)); + + var logo = new LogoComponent(); + + var breadCrumbs = new BreadCrumbsComponent(); + + var footer = new FooterContainer(breadCrumbs); + + var layout = new DashboardLayout(header, logo, footer); + + canvas.Draw(layout); + } + + public override void Bind() + { + } +} \ No newline at end of file diff --git a/src/TUI/Program.cs b/src/TUI/Program.cs index 775f06f..8852137 100644 --- a/src/TUI/Program.cs +++ b/src/TUI/Program.cs @@ -6,9 +6,12 @@ Console.CursorVisible = false; // var settings = Settings.Init(); +var welcomePage = new WelcomePage(); +welcomePage.Open(); +Thread.Sleep(2000); + var dependenciesPage = new DependenciesPage(); dependenciesPage.Open(); - // display.OpenDeps(settings.Projects[0]); var key = new ConsoleKeyInfo('1', ConsoleKey.NoName, false, false, false); diff --git a/src/TUI/Store/DependenciesStore.cs b/src/TUI/Store/DependenciesStore.cs index e32d540..166f638 100644 --- a/src/TUI/Store/DependenciesStore.cs +++ b/src/TUI/Store/DependenciesStore.cs @@ -1,3 +1,4 @@ +using TUI.Controls.Components; using TUI.Domain; using TUI.Providers.Dependencies; @@ -12,8 +13,12 @@ public class DependenciesStore public void Bind() { var repo = new DependencyRepository(); + ConventionDependencies = repo.ReadConventions("javascript"); + SpeakerComponent.Instance.Shout("🤔", "Prepare javascript conventions"); + Projects = repo.ReadProjects("javascript"); + SpeakerComponent.Instance.Shout("🤩", "Prepare javascript projects"); } // private readonly static Dictionary Packages = new(); diff --git a/src/TUI/UserInterface/Icons.cs b/src/TUI/UserInterface/Icons.cs index 1819575..07e7509 100644 --- a/src/TUI/UserInterface/Icons.cs +++ b/src/TUI/UserInterface/Icons.cs @@ -1,4 +1,3 @@ -using Pastel; using TUI.Engine;