using Spectre.Console; namespace AnchorCli; internal static class SetupTui { public static void Run() { var config = AnchorConfig.Load(); AnsiConsole.Write(new Rule("[cornflowerblue]anchor setup[/]").LeftJustified()); AnsiConsole.WriteLine(); // ── API Key ─────────────────────────────────────────────────── string maskedKey = config.ApiKey.Length > 8 ? config.ApiKey[..4] + new string('*', config.ApiKey.Length - 8) + config.ApiKey[^4..] : config.ApiKey.Length > 0 ? "****" : "[dim](not set)[/]"; AnsiConsole.MarkupLine($" Current API key: [dim]{Markup.Escape(maskedKey)}[/]"); string newKey = AnsiConsole.Prompt( new TextPrompt(" New API key [dim](Enter to keep)[/]:") .AllowEmpty() .Secret('*')); if (!string.IsNullOrWhiteSpace(newKey)) config.ApiKey = newKey.Trim(); AnsiConsole.WriteLine(); // ── Model ───────────────────────────────────────────────────── AnsiConsole.MarkupLine($" Current model: [cyan]{Markup.Escape(config.Model)}[/]"); var models = new List<(string Value, string Description)> { ("qwen/qwen3.5-397b-a17b", "smart, expensive"), ("qwen/qwen3.5-35b-a3b", "cheapest"), ("qwen/qwen3.5-27b", "fast"), ("qwen/qwen3.5-122b-a10b", "smart"), ("Custom...", "") }; string selectedModel = AnsiConsole.Prompt( new SelectionPrompt<(string Value, string Description)>() .Title(" Select a model:") .UseConverter(m => m.Value + (string.IsNullOrEmpty(m.Description) ? "" : $" [dim]({m.Description})[/]")) .AddChoices(models)) .Value; if (selectedModel == "Custom...") { string customModel = AnsiConsole.Prompt( new TextPrompt(" Enter custom model name:") .AllowEmpty()); if (!string.IsNullOrWhiteSpace(customModel)) config.Model = customModel.Trim(); } else { config.Model = selectedModel; } // ── Save ────────────────────────────────────────────────────── AnsiConsole.WriteLine(); config.Save(); AnsiConsole.MarkupLine("[green]✓ Config saved.[/]"); } }