Use Spectre for fs options command.

This commit is contained in:
2021-09-13 18:15:14 +01:00
parent ed4d2f9c11
commit 01dddb0508

View File

@@ -41,6 +41,7 @@ using Aaru.CommonTypes.Interfaces;
using Aaru.Console;
using Aaru.Core;
using JetBrains.Annotations;
using Spectre.Console;
namespace Aaru.Commands.Filesystem
{
@@ -54,10 +55,29 @@ namespace Aaru.Commands.Filesystem
MainClass.PrintCopyright();
if(debug)
AaruConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
{
IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings
{
Out = new AnsiConsoleOutput(System.Console.Error)
});
AaruConsole.DebugWriteLineEvent += (format, objects) =>
{
if(objects is null)
stderrConsole.MarkupLine(format);
else
stderrConsole.MarkupLine(format, objects);
};
}
if(verbose)
AaruConsole.VerboseWriteLineEvent += System.Console.WriteLine;
AaruConsole.WriteEvent += (format, objects) =>
{
if(objects is null)
AnsiConsole.Markup(format);
else
AnsiConsole.Markup(format, objects);
};
AaruConsole.DebugWriteLine("List-Options command", "--debug={0}", debug);
AaruConsole.DebugWriteLine("List-Options command", "--verbose={0}", verbose);
@@ -74,13 +94,20 @@ namespace Aaru.Commands.Filesystem
if(options.Count == 0)
continue;
AaruConsole.WriteLine("\tOptions for {0}:", kvp.Value.Name);
AaruConsole.WriteLine("\t\t{0,-16} {1,-16} {2,-8}", "Name", "Type", "Description");
var table = new Table
{
Title = new TableTitle($"Options for {kvp.Value.Name}:")
};
table.AddColumn("Name");
table.AddColumn("Type");
table.AddColumn("Description");
foreach((string name, Type type, string description) option in options.OrderBy(t => t.name))
AaruConsole.WriteLine("\t\t{0,-16} {1,-16} {2,-8}", option.name, TypeToString(option.type),
option.description);
table.AddRow(Markup.Escape(option.name), $"[italic]{TypeToString(option.type)}[/]",
Markup.Escape(option.description));
AnsiConsole.Render(table);
AaruConsole.WriteLine();
}