Improve formating
This commit is contained in:
@@ -4,4 +4,5 @@ public static class CustomStyles
|
|||||||
{
|
{
|
||||||
public static Style Error { get; } = new Style(foreground: Color.Red);
|
public static Style Error { get; } = new Style(foreground: Color.Red);
|
||||||
public static Style Note { get; } = new(foreground: Color.DarkSlateGray1);
|
public static Style Note { get; } = new(foreground: Color.DarkSlateGray1);
|
||||||
|
public static Style? Hex { get; } = new(foreground: Color.Blue);
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.ComponentModel;
|
using System.Collections;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
using System.Reactive.Threading.Tasks;
|
using System.Reactive.Threading.Tasks;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
@@ -28,19 +29,23 @@ internal sealed class ReadPlcCommand : AsyncCommand<ReadPlcCommand.Settings>
|
|||||||
|
|
||||||
private static IRenderable FormatCellData(VariableRecord record)
|
private static IRenderable FormatCellData(VariableRecord record)
|
||||||
{
|
{
|
||||||
if (record.Value is IRenderable renderable)
|
return record.Value switch
|
||||||
return renderable;
|
|
||||||
|
|
||||||
if (record.Value is Exception ex)
|
|
||||||
return new Text(ex.Message, CustomStyles.Error);
|
|
||||||
|
|
||||||
if (record.Value is byte[] byteArray)
|
|
||||||
{
|
{
|
||||||
var text = string.Join(" ", byteArray.Select(b => $"0x{b:X2}"));
|
IRenderable renderable => renderable,
|
||||||
return new Text(text);
|
Exception ex => new Text(ex.Message, CustomStyles.Error),
|
||||||
}
|
byte[] byteArray => new Text(string.Join(" ", byteArray.Select(b => $"0x{b:X2}")), CustomStyles.Hex),
|
||||||
|
byte => FormatNo(),
|
||||||
|
short =>FormatNo(),
|
||||||
|
ushort =>FormatNo(),
|
||||||
|
int =>FormatNo(),
|
||||||
|
uint =>FormatNo(),
|
||||||
|
long =>FormatNo(),
|
||||||
|
ulong =>FormatNo(),
|
||||||
|
|
||||||
return new Text(record.Value.ToString() ?? "");
|
_ => new Text(record.Value.ToString() ?? "")
|
||||||
|
};
|
||||||
|
|
||||||
|
Markup FormatNo() => new($"[blue]0x{record.Value:X2}[/] {record.Value}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task RunProgram(Settings settings, CancellationToken token)
|
private static async Task RunProgram(Settings settings, CancellationToken token)
|
||||||
|
|||||||
Reference in New Issue
Block a user