fix core dump on export option

This commit is contained in:
2026-05-20 11:26:44 +02:00
parent 4874bf096c
commit 76064fa822
3 changed files with 59 additions and 60 deletions
+31 -17
View File
@@ -14,6 +14,21 @@ public static class OperationForms
// Shared helpers
// -------------------------------------------------------------------------
/// <summary>
/// A choice item that keeps the real value separate from the display label.
/// The display label is pre-escaped plain text — never interpreted as markup.
/// </summary>
private sealed class SchemaChoice
{
public string Display { get; init; } = "";
public string? Value { get; init; } // null = cancel, "" = manual entry
public static readonly SchemaChoice Manual = new() { Display = "[ Enter manually ]", Value = "" };
public static readonly SchemaChoice Cancel = new() { Display = "[ Cancel ]", Value = null };
public override string ToString() => Display;
}
/// <summary>
/// Fetches the schema list with a spinner, then shows an arrow-key picker.
/// Returns the selected schema, or null if cancelled.
@@ -38,36 +53,35 @@ public static class OperationForms
if (error is not null)
AnsiConsole.MarkupLine($"[yellow][[WARN]] Could not fetch schemas: {Markup.Escape(error)}[/]");
// Use sentinel strings as values so no markup leaks into choice labels
const string manualSentinel = "__MANUAL__";
const string cancelSentinel = "__CANCEL__";
// Build typed choices. Display is plain text; ToString() is what SelectionPrompt shows.
var choices = schemas
.Select(s => new SchemaChoice { Display = s, Value = s })
.ToList();
choices.Add(SchemaChoice.Manual);
choices.Add(SchemaChoice.Cancel);
var choiceValues = new List<string>(schemas) { manualSentinel, cancelSentinel };
var prompt = new SelectionPrompt<string>()
// UseConverter returns Display which is already plain text.
// We also set the prompt to NOT interpret converter output as markup by
// escaping it — belt-and-suspenders.
var prompt = new SelectionPrompt<SchemaChoice>()
.Title($"[bold]{Markup.Escape(title)}[/]")
.PageSize(15)
.HighlightStyle(Style.Parse("bold dodgerblue1"))
.UseConverter(v => v switch
{
manualSentinel => "[ Enter manually ]",
cancelSentinel => "[ Cancel ]",
_ => Markup.Escape(v),
})
.AddChoices(choiceValues);
.UseConverter(c => Markup.Escape(c.Display))
.AddChoices(choices);
var selected = AnsiConsole.Prompt(prompt);
if (selected == cancelSentinel)
return null;
if (selected.Value is null)
return null; // Cancel
if (selected == manualSentinel)
if (selected.Value == "")
{
var manual = AnsiConsole.Ask<string>("Enter schema name:").Trim();
return string.IsNullOrWhiteSpace(manual) ? null : manual;
}
return selected.Trim();
return selected.Value;
}
private static int PickThreads(string label = "Number of threads")