TerminalUI theming, Commands panel

This commit is contained in:
2023-08-15 20:23:58 +02:00
parent b792639635
commit d175c7bf7e
27 changed files with 604 additions and 77 deletions

View File

@@ -0,0 +1,63 @@
using TerminalUI.Color;
using TerminalUI.ConsoleDrivers;
using TerminalUI.Controls;
using TerminalUI.Models;
namespace TerminalUI.Examples.Controls;
public class ProgressBarExamples
{
private readonly IApplicationContext _applicationContext;
private static readonly IConsoleDriver _driver;
static ProgressBarExamples()
{
_driver = new DotnetDriver();
_driver.Init();
}
public ProgressBarExamples(IApplicationContext applicationContext)
{
_applicationContext = applicationContext;
}
public void LoadingExample()
{
var progressBar = CreateProgressBar<object>(0);
for (var i = 0; i < 100; i++)
{
progressBar.Value = i;
RenderProgressBar(progressBar, new Position(0, 0));
Thread.Sleep(100);
}
}
public void PaletteExample()
{
RenderProgressBar(CreateProgressBar<object>(100), new Position(0, 0));
for (var i = 0; i < 10; i++)
{
RenderProgressBar(CreateProgressBar<object>(10 * (i + 1)), new Position(0, i + 1));
}
}
private ProgressBar<T> CreateProgressBar<T>(int percent) =>
new()
{
Value = percent,
Attached = true,
ApplicationContext = _applicationContext
};
private void RenderProgressBar<T>(ProgressBar<T> progressBar, Position position)
{
var renderContext = new RenderContext(
_driver,
true,
null,
null,
new()
);
progressBar.Render(renderContext, position, new Size(10, 1));
}
}

View File

@@ -0,0 +1,22 @@
using TerminalUI.Controls;
namespace TerminalUI.Examples.Mocks;
public class MockRenderEngine : IRenderEngine
{
public void RequestRerender(IView view)
{
}
public void VisibilityChanged(IView view)
{
}
public void AddViewToPermanentRenderGroup(IView view)
{
}
public void Run()
{
}
}

View File

@@ -0,0 +1,32 @@
// See https://aka.ms/new-console-template for more information
using Microsoft.Extensions.DependencyInjection;
using TerminalUI;
using TerminalUI.Color;
using TerminalUI.DependencyInjection;
using TerminalUI.Examples.Controls;
using TerminalUI.Examples.Mocks;
using TerminalUI.Styling;
using TerminalUI.Styling.Controls;
Console.OutputEncoding = System.Text.Encoding.UTF8;
var services = new ServiceCollection()
.AddTerminalUi()
.AddSingleton<IRenderEngine, MockRenderEngine>();
IServiceProvider provider = services.BuildServiceProvider();
var applicationContext = provider.GetRequiredService<IApplicationContext>();
applicationContext.Theme = new Theme
{
ControlThemes = new ControlThemes
{
ProgressBar = new ProgressBarTheme
{
ForegroundColor = ConsoleColors.Foregrounds.Blue
}
}
};
Console.CursorVisible = false;
new ProgressBarExamples(applicationContext).LoadingExample();
Console.CursorVisible = true;

View File

@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\TerminalUI.DependencyInjection\TerminalUI.DependencyInjection.csproj" />
<ProjectReference Include="..\TerminalUI\TerminalUI.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
</ItemGroup>
</Project>