Order in Tab instead TabViewModel, Utf8 char handling
This commit is contained in:
@@ -87,7 +87,7 @@ public static class DeclarativePropertyExtensions
|
||||
public static IDeclarativeProperty<TResult?> CombineLatest<T1, T2, TResult>(
|
||||
this IDeclarativeProperty<T1> prop1,
|
||||
IDeclarativeProperty<T2> prop2,
|
||||
Func<T1, T2, Task<TResult>> func,
|
||||
Func<T1, T2, Task<TResult?>> func,
|
||||
Action<TResult?>? setValueHook = null)
|
||||
=> new CombineLatestProperty<T1,T2,TResult?>(prop1, prop2, func, setValueHook);
|
||||
|
||||
@@ -96,7 +96,7 @@ public static class DeclarativePropertyExtensions
|
||||
|
||||
public static IDeclarativeProperty<TResult?> CombineAll<T, TResult>(
|
||||
this IEnumerable<IDeclarativeProperty<T>> sources,
|
||||
Func<IEnumerable<T>, Task<TResult>> combiner,
|
||||
Func<IEnumerable<T>, Task<TResult?>> combiner,
|
||||
Action<TResult?>? setValueHook = null)
|
||||
=> new CombineAllProperty<T,TResult?>(sources, combiner, setValueHook);
|
||||
}
|
||||
14
src/Library/TerminalUI/Color/SpecialColors.cs
Normal file
14
src/Library/TerminalUI/Color/SpecialColors.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace TerminalUI.Color;
|
||||
|
||||
public class SpecialColor : IColor
|
||||
{
|
||||
private SpecialColor(){}
|
||||
public ColorType Type => ColorType.Unknown;
|
||||
public string ToConsoleColor() => throw new NotImplementedException();
|
||||
|
||||
public IColor AsForeground() => this;
|
||||
|
||||
public IColor AsBackground() => this;
|
||||
|
||||
public static SpecialColor None { get; } = new();
|
||||
}
|
||||
@@ -36,12 +36,16 @@ public class DotnetDriver : IConsoleDriver
|
||||
|
||||
public virtual void SetForegroundColor(IColor foreground)
|
||||
{
|
||||
if (foreground == SpecialColor.None) return;
|
||||
|
||||
if (foreground is not ConsoleColor consoleColor) throw new NotSupportedException();
|
||||
Console.ForegroundColor = consoleColor.Color;
|
||||
}
|
||||
|
||||
public virtual void SetBackgroundColor(IColor background)
|
||||
{
|
||||
if (background == SpecialColor.None) return;
|
||||
|
||||
if (background is not ConsoleColor consoleColor) throw new NotSupportedException();
|
||||
Console.BackgroundColor = consoleColor.Color;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ public sealed class XTermDriver : DotnetDriver
|
||||
|
||||
public override void SetBackgroundColor(IColor background)
|
||||
{
|
||||
if (background == SpecialColor.None) return;
|
||||
|
||||
if (background is ConsoleColor consoleColor)
|
||||
{
|
||||
Console.BackgroundColor = consoleColor.Color;
|
||||
@@ -41,6 +43,8 @@ public sealed class XTermDriver : DotnetDriver
|
||||
|
||||
public override void SetForegroundColor(IColor foreground)
|
||||
{
|
||||
if (foreground == SpecialColor.None) return;
|
||||
|
||||
if (foreground is ConsoleColor consoleColor)
|
||||
{
|
||||
Console.ForegroundColor = consoleColor.Color;
|
||||
|
||||
@@ -13,10 +13,10 @@ public partial class ProgressBar<T> : View<ProgressBar<T>, T>
|
||||
int Minimum,
|
||||
int Maximum,
|
||||
int Value,
|
||||
char? LeftCap,
|
||||
char? RightCap,
|
||||
char? Fill,
|
||||
char? Unfilled,
|
||||
SelectiveChar? LeftCap,
|
||||
SelectiveChar? RightCap,
|
||||
SelectiveChar? Fill,
|
||||
SelectiveChar? Unfilled,
|
||||
IColor? UnfilledForeground,
|
||||
IColor? UnfilledBackground);
|
||||
|
||||
@@ -49,10 +49,10 @@ public partial class ProgressBar<T> : View<ProgressBar<T>, T>
|
||||
var background = Background ?? (_theme ?? theme)?.BackgroundColor ?? renderContext.Background;
|
||||
var unfilledForeground = (_theme ?? theme)?.UnfilledForeground ?? renderContext.Foreground;
|
||||
var unfilledBackground = (_theme ?? theme)?.UnfilledBackground ?? renderContext.Background;
|
||||
var unfilledCharacter = (_theme ?? theme)?.UnfilledCharacter ?? ApplicationContext?.EmptyCharacter ?? ' ';
|
||||
var fillCharacter = (_theme ?? theme)?.FilledCharacter ?? '█';
|
||||
var leftCap = (_theme ?? theme)?.LeftCap;
|
||||
var rightCap = (_theme ?? theme)?.RightCap;
|
||||
var unfilledCharacterS = (_theme ?? theme)?.UnfilledCharacter ?? new SelectiveChar(ApplicationContext?.EmptyCharacter ?? ' ');
|
||||
var fillCharacterS = (_theme ?? theme)?.FilledCharacter ?? new SelectiveChar('█');
|
||||
var leftCapS = (_theme ?? theme)?.LeftCap;
|
||||
var rightCapS = (_theme ?? theme)?.RightCap;
|
||||
|
||||
var renderState = new RenderState(
|
||||
position,
|
||||
@@ -60,15 +60,21 @@ public partial class ProgressBar<T> : View<ProgressBar<T>, T>
|
||||
Minimum,
|
||||
Maximum,
|
||||
Value,
|
||||
leftCap,
|
||||
rightCap,
|
||||
fillCharacter,
|
||||
unfilledCharacter,
|
||||
leftCapS,
|
||||
rightCapS,
|
||||
fillCharacterS,
|
||||
unfilledCharacterS,
|
||||
unfilledForeground,
|
||||
unfilledBackground);
|
||||
|
||||
if (!renderContext.ForceRerender && !NeedsRerender(renderState)) return false;
|
||||
|
||||
var utf8Support = ApplicationContext!.SupportUtf8Output;
|
||||
var unfilledCharacter = unfilledCharacterS.GetChar(utf8Support);
|
||||
var fillCharacter = fillCharacterS.GetChar(utf8Support);
|
||||
var leftCap = leftCapS?.GetChar(utf8Support);
|
||||
var rightCap = rightCapS?.GetChar(utf8Support);
|
||||
|
||||
_lastRenderState = renderState;
|
||||
var driver = renderContext.ConsoleDriver;
|
||||
|
||||
@@ -90,17 +96,18 @@ public partial class ProgressBar<T> : View<ProgressBar<T>, T>
|
||||
if (ApplicationContext!.SupportUtf8Output)
|
||||
{
|
||||
var remained = progressWidth - progressQuotientWidth;
|
||||
var t = _theme ?? theme;
|
||||
transientChar = remained switch
|
||||
{
|
||||
< 0.125 => unfilledCharacter,
|
||||
< 0.250 => (_theme ?? theme)?.Fraction1Per8Character ?? '\u258F',
|
||||
< 0.375 => (_theme ?? theme)?.Fraction2Per8Character ?? '\u258E',
|
||||
< 0.500 => (_theme ?? theme)?.Fraction3Per8Character ?? '\u258D',
|
||||
< 0.675 => (_theme ?? theme)?.Fraction4Per8Character ?? '\u258C',
|
||||
< 0.750 => (_theme ?? theme)?.Fraction5Per8Character ?? '\u258B',
|
||||
< 0.875 => (_theme ?? theme)?.Fraction6Per8Character ?? '\u258A',
|
||||
< 0_001 => (_theme ?? theme)?.Fraction7Per8Character ?? '\u2589',
|
||||
_ => (_theme ?? theme)?.FractionFull ?? '\u2588',
|
||||
< 0.250 => (t?.Fraction1Per8Character ?? new SelectiveChar('\u258F', ' ')).GetChar(utf8Support),
|
||||
< 0.375 => (t?.Fraction2Per8Character ?? new SelectiveChar('\u258E', ' ')).GetChar(utf8Support),
|
||||
< 0.500 => (t?.Fraction3Per8Character ?? new SelectiveChar('\u258D', ' ')).GetChar(utf8Support),
|
||||
< 0.675 => (t?.Fraction4Per8Character ?? new SelectiveChar('\u258C', ' ')).GetChar(utf8Support),
|
||||
< 0.750 => (t?.Fraction5Per8Character ?? new SelectiveChar('\u258B', ' ')).GetChar(utf8Support),
|
||||
< 0.875 => (t?.Fraction6Per8Character ?? new SelectiveChar('\u258A', ' ')).GetChar(utf8Support),
|
||||
< 0_001 => (t?.Fraction7Per8Character ?? new SelectiveChar('\u2589', ' ')).GetChar(utf8Support),
|
||||
_ => (t?.FractionFull ?? new SelectiveChar('\u2588', ' ')).GetChar(utf8Support),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,24 +10,26 @@ public sealed partial class Rectangle<T> : View<Rectangle<T>, T>, IDisplayView
|
||||
private record RenderState(
|
||||
Position Position,
|
||||
Size Size,
|
||||
IColor? Fill);
|
||||
IColor? Color);
|
||||
|
||||
private RenderState? _lastRenderState;
|
||||
|
||||
[Notify] private IColor? _fill;
|
||||
protected override Size CalculateSize() => new(Width ?? 0, Height ?? 0);
|
||||
|
||||
protected override bool DefaultRenderer(in RenderContext renderContext, Position position, Size size)
|
||||
{
|
||||
var renderState = new RenderState(position, size, Fill);
|
||||
if ((!renderContext.ForceRerender && !NeedsRerender(renderState)) || Fill is null) return false;
|
||||
var color = Background ?? renderContext.Background;
|
||||
var renderState = new RenderState(position, size, color);
|
||||
if (!renderContext.ForceRerender && !NeedsRerender(renderState)) return false;
|
||||
_lastRenderState = renderState;
|
||||
|
||||
var driver = renderContext.ConsoleDriver;
|
||||
|
||||
var s = new string('█', size.Width);
|
||||
driver.SetBackgroundColor(Fill);
|
||||
driver.SetForegroundColor(Fill);
|
||||
var s = new string(' ', size.Width);
|
||||
driver.ResetColor();
|
||||
if (color is not null)
|
||||
{
|
||||
driver.SetForegroundColor(color);
|
||||
}
|
||||
|
||||
var height = size.Height;
|
||||
for (var i = 0; i < height; i++)
|
||||
|
||||
21
src/Library/TerminalUI/Models/SelectiveChar.cs
Normal file
21
src/Library/TerminalUI/Models/SelectiveChar.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace TerminalUI.Models;
|
||||
|
||||
public readonly struct SelectiveChar
|
||||
{
|
||||
public readonly char Utf8Char;
|
||||
public readonly char AsciiChar;
|
||||
|
||||
public SelectiveChar(char c)
|
||||
{
|
||||
Utf8Char = c;
|
||||
AsciiChar = c;
|
||||
}
|
||||
|
||||
public SelectiveChar(char utf8Char, char asciiChar)
|
||||
{
|
||||
Utf8Char = utf8Char;
|
||||
AsciiChar = asciiChar;
|
||||
}
|
||||
|
||||
public char GetChar(bool enableUtf8) => enableUtf8 ? Utf8Char : AsciiChar;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using TerminalUI.Color;
|
||||
using TerminalUI.Models;
|
||||
|
||||
namespace TerminalUI.Styling.Controls;
|
||||
|
||||
@@ -8,16 +9,16 @@ public interface IProgressBarTheme
|
||||
IColor? BackgroundColor { get; init; }
|
||||
IColor? UnfilledForeground { get; init; }
|
||||
IColor? UnfilledBackground { get; init; }
|
||||
char? FilledCharacter { get; init; }
|
||||
char? UnfilledCharacter { get; init; }
|
||||
char? Fraction1Per8Character { get; init; }
|
||||
char? Fraction2Per8Character { get; init; }
|
||||
char? Fraction3Per8Character { get; init; }
|
||||
char? Fraction4Per8Character { get; init; }
|
||||
char? Fraction5Per8Character { get; init; }
|
||||
char? Fraction6Per8Character { get; init; }
|
||||
char? Fraction7Per8Character { get; init; }
|
||||
char? FractionFull { get; init; }
|
||||
char? LeftCap { get; init; }
|
||||
char? RightCap { get; init; }
|
||||
SelectiveChar? FilledCharacter { get; init; }
|
||||
SelectiveChar? UnfilledCharacter { get; init; }
|
||||
SelectiveChar? Fraction1Per8Character { get; init; }
|
||||
SelectiveChar? Fraction2Per8Character { get; init; }
|
||||
SelectiveChar? Fraction3Per8Character { get; init; }
|
||||
SelectiveChar? Fraction4Per8Character { get; init; }
|
||||
SelectiveChar? Fraction5Per8Character { get; init; }
|
||||
SelectiveChar? Fraction6Per8Character { get; init; }
|
||||
SelectiveChar? Fraction7Per8Character { get; init; }
|
||||
SelectiveChar? FractionFull { get; init; }
|
||||
SelectiveChar? LeftCap { get; init; }
|
||||
SelectiveChar? RightCap { get; init; }
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using TerminalUI.Color;
|
||||
using TerminalUI.Models;
|
||||
|
||||
namespace TerminalUI.Styling.Controls;
|
||||
|
||||
@@ -28,16 +29,16 @@ public class ProgressBarTheme : IProgressBarTheme
|
||||
public IColor? BackgroundColor { get; init; }
|
||||
public IColor? UnfilledForeground { get; init; }
|
||||
public IColor? UnfilledBackground { get; init; }
|
||||
public char? FilledCharacter { get; init; }
|
||||
public char? UnfilledCharacter { get; init; }
|
||||
public char? Fraction1Per8Character { get; init; }
|
||||
public char? Fraction2Per8Character { get; init; }
|
||||
public char? Fraction3Per8Character { get; init; }
|
||||
public char? Fraction4Per8Character { get; init; }
|
||||
public char? Fraction5Per8Character { get; init; }
|
||||
public char? Fraction6Per8Character { get; init; }
|
||||
public char? Fraction7Per8Character { get; init; }
|
||||
public char? FractionFull { get; init; }
|
||||
public char? LeftCap { get; init; }
|
||||
public char? RightCap { get; init; }
|
||||
public SelectiveChar? FilledCharacter { get; init; }
|
||||
public SelectiveChar? UnfilledCharacter { get; init; }
|
||||
public SelectiveChar? Fraction1Per8Character { get; init; }
|
||||
public SelectiveChar? Fraction2Per8Character { get; init; }
|
||||
public SelectiveChar? Fraction3Per8Character { get; init; }
|
||||
public SelectiveChar? Fraction4Per8Character { get; init; }
|
||||
public SelectiveChar? Fraction5Per8Character { get; init; }
|
||||
public SelectiveChar? Fraction6Per8Character { get; init; }
|
||||
public SelectiveChar? Fraction7Per8Character { get; init; }
|
||||
public SelectiveChar? FractionFull { get; init; }
|
||||
public SelectiveChar? LeftCap { get; init; }
|
||||
public SelectiveChar? RightCap { get; init; }
|
||||
}
|
||||
Reference in New Issue
Block a user