mirror of
https://github.com/dnwSilver/tld.git
synced 2024-11-25 16:42:07 +00:00
✨ Add speaker component.
This commit is contained in:
parent
00e5eadab1
commit
3a85bfbdd3
@ -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
|
||||
{
|
||||
DrawContext DrawContext { get; set; }
|
||||
}
|
||||
|
||||
public record DrawContext(ICanvas Canvas, Position Pencil, Size MaxSize);
|
@ -55,4 +55,6 @@ public abstract class NodeBase : INode
|
||||
}
|
||||
|
||||
#endregion Resizing
|
||||
|
||||
public DrawContext? DrawContext { get; set; }
|
||||
}
|
@ -25,6 +25,8 @@ internal sealed class ComponentCraftsman : CraftsmanBase, IDrawable<IComponent>
|
||||
|
||||
foreach (var line in sketch.Crop(maxSize))
|
||||
{
|
||||
component.DrawContext = new DrawContext(_canvas, pencil, maxSize);
|
||||
|
||||
_canvas.SetPencil(correctedPencil);
|
||||
_canvas.Paint(line);
|
||||
|
||||
|
50
src/TUI/Controls/Components/SpeakerComponent.cs
Normal file
50
src/TUI/Controls/Components/SpeakerComponent.cs
Normal file
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using System.Text;
|
||||
using TUI.Engine;
|
||||
using TUI.Engine.Attributes;
|
||||
using TUI.Engine.Components;
|
||||
|
||||
|
@ -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 };
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
8
src/TUI/Pages/IPage.cs
Normal file
8
src/TUI/Pages/IPage.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace TUI.Pages;
|
||||
|
||||
interface IPage
|
||||
{
|
||||
void Open();
|
||||
void Render();
|
||||
void Bind();
|
||||
}
|
17
src/TUI/Pages/PageBase.cs
Normal file
17
src/TUI/Pages/PageBase.cs
Normal file
@ -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();
|
||||
}
|
33
src/TUI/Pages/WelcomePage.cs
Normal file
33
src/TUI/Pages/WelcomePage.cs
Normal file
@ -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()
|
||||
{
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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<string, Package> Packages = new();
|
||||
|
@ -1,4 +1,3 @@
|
||||
using Pastel;
|
||||
using TUI.Engine;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user