mirror of
https://github.com/m-lamonaca/script-launcher.git
synced 2025-04-08 11:06:26 +00:00
Add style to selection prompt
This commit is contained in:
parent
723677a72d
commit
7c512fa63f
1 changed files with 24 additions and 6 deletions
|
@ -47,11 +47,13 @@ static void RootCommand(
|
||||||
if (multiple)
|
if (multiple)
|
||||||
{
|
{
|
||||||
var prompt = new MultiSelectionPrompt<FileInfo>()
|
var prompt = new MultiSelectionPrompt<FileInfo>()
|
||||||
.Title("Select scripts")
|
.Title("Select a script the scripts to execute:")
|
||||||
.NotRequired()
|
.NotRequired()
|
||||||
.PageSize(ScriptListSize)
|
.PageSize(ScriptListSize)
|
||||||
.MoreChoicesText("[grey]Move up and down to reveal more options[/]")
|
.MoreChoicesText("[grey]Move up and down to reveal more options[/]")
|
||||||
.InstructionsText("[grey](Press [blue]<space>[/] to toggle a script, [green]<enter>[/] to accept)[/]")
|
.InstructionsText("[grey](Press [blue]<space>[/] to toggle a script, [green]<enter>[/] to accept)[/]")
|
||||||
|
.UseConverter(PromptDecorator.GetStyledOption)
|
||||||
|
.HighlightStyle(PromptDecorator.SelectionHighlight)
|
||||||
.AddChoices(files);
|
.AddChoices(files);
|
||||||
|
|
||||||
var scripts = AnsiConsole.Prompt(prompt);
|
var scripts = AnsiConsole.Prompt(prompt);
|
||||||
|
@ -61,9 +63,11 @@ static void RootCommand(
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var prompt = new SelectionPrompt<FileInfo>()
|
var prompt = new SelectionPrompt<FileInfo>()
|
||||||
.Title("Select a script")
|
.Title("Select a script to execute:")
|
||||||
.PageSize(ScriptListSize)
|
.PageSize(ScriptListSize)
|
||||||
.MoreChoicesText("[grey]Move up and down to reveal more options[/]")
|
.MoreChoicesText("[grey]Move up and down to reveal more options[/]")
|
||||||
|
.UseConverter(PromptDecorator.GetStyledOption)
|
||||||
|
.HighlightStyle(PromptDecorator.SelectionHighlight)
|
||||||
.AddChoices(files);
|
.AddChoices(files);
|
||||||
|
|
||||||
var script = AnsiConsole.Prompt(prompt);
|
var script = AnsiConsole.Prompt(prompt);
|
||||||
|
@ -72,6 +76,20 @@ static void RootCommand(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static class PromptDecorator
|
||||||
|
{
|
||||||
|
internal static string GetStyledOption(FileInfo info)
|
||||||
|
{
|
||||||
|
var directory = $"[blue]{info.DirectoryName ?? "."}{Path.DirectorySeparatorChar}[/]";
|
||||||
|
var filename = $"[orangered1]{Path.GetFileNameWithoutExtension(info.Name)}[/]";
|
||||||
|
var extension = $"[greenyellow]{Path.GetExtension(info.Name)}[/]";
|
||||||
|
|
||||||
|
return $"{directory}{filename}{extension}";
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static Style SelectionHighlight => new Style(decoration: Decoration.Bold | Decoration.Underline);
|
||||||
|
}
|
||||||
|
|
||||||
static class ScriptExecutor
|
static class ScriptExecutor
|
||||||
{
|
{
|
||||||
internal static void Exec(FileInfo file, bool elevated)
|
internal static void Exec(FileInfo file, bool elevated)
|
||||||
|
@ -146,16 +164,16 @@ readonly struct ScriptFinder
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
internal readonly FileInfo[] GetScriptFiles(string extension)
|
internal readonly IEnumerable<FileInfo> GetScriptFiles(string extension)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var filenames = Directory.GetFiles(RootFolder, $"*.{extension}", _options);
|
var filenames = Directory.GetFiles(RootFolder, $"*.{extension}", _options);
|
||||||
return filenames.Select(x => new FileInfo(x)).ToArray();
|
return filenames.Select(x => new FileInfo(x));
|
||||||
}
|
}
|
||||||
catch (UnauthorizedAccessException)
|
catch (UnauthorizedAccessException)
|
||||||
{
|
{
|
||||||
return Array.Empty<FileInfo>();
|
return Enumerable.Empty<FileInfo>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue