script-launcher/src/PromptConstructor.cs
Marcello Lamonaca aebe1f7aaa
bump dotnet version to net8.0
- bump dotnet verison to .NET 8
- bump tool version to 0.1.5
- fix warnings
2023-11-14 19:10:31 +01:00

68 lines
2.1 KiB
C#

using Spectre.Console;
using System.Globalization;
using System.Text;
namespace ScriptLauncher;
internal static class PromptConstructor
{
const int ScriptListSize = 15;
private static Style SelectionHighlight =>
new(decoration: Decoration.Bold | Decoration.Underline);
private static string FileStyle(FileInfo info, bool brief)
{
var builder = new StringBuilder();
if (!brief)
{
builder.Append(
CultureInfo.InvariantCulture,
$"[blue]{info.DirectoryName}{Path.DirectorySeparatorChar}[/]"
);
}
builder
.Append(
CultureInfo.InvariantCulture,
$"[orangered1]{Path.GetFileNameWithoutExtension(info.Name)}[/]"
)
.Append(CultureInfo.InvariantCulture, $"[greenyellow]{info.Extension}[/]");
return builder.ToString();
}
private static string DirectoryStyle(DirectoryInfo info) => $"[blue]{info}[/]";
public static MultiSelectionPrompt<FileInfo> GetScriptPrompt(FileInfo[] files, bool brief)
{
var prompt = new MultiSelectionPrompt<FileInfo>()
.Title("Select the scripts to execute:")
.NotRequired()
.PageSize(ScriptListSize)
.InstructionsText(
"[grey](Press [blue]<space>[/] to toggle a script, [green]<enter>[/] to accept)[/]"
)
.MoreChoicesText("[grey]Move up and down to reveal more options[/]")
.UseConverter(x => FileStyle(x, brief))
.HighlightStyle(SelectionHighlight)
.AddChoices(files);
return prompt;
}
public static SelectionPrompt<DirectoryInfo> GetDirectoryPrompt(DirectoryInfo[] directories)
{
var prompt = new SelectionPrompt<DirectoryInfo>()
.Title("Select a directory:")
.PageSize(ScriptListSize)
.MoreChoicesText("[grey]Move up and down to reveal more options[/]")
.UseConverter(DirectoryStyle)
.HighlightStyle(SelectionHighlight)
.AddChoices(directories);
return prompt;
}
}