add hanatui
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
using HanaTui.Hana;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace HanaTui.Tui;
|
||||
|
||||
/// <summary>
|
||||
/// Startup screen: lists hdbuserstore keys and lets the user pick one.
|
||||
/// Returns the selected key name, or null if the user chose to exit.
|
||||
/// </summary>
|
||||
public static class KeySelectionScreen
|
||||
{
|
||||
public static string? Run()
|
||||
{
|
||||
AnsiConsole.Clear();
|
||||
AnsiConsole.Write(new FigletText("HANA TUI").Color(Color.DodgerBlue1));
|
||||
AnsiConsole.MarkupLine("[dim]SAP HANA Database Manager[/]\n");
|
||||
|
||||
if (!HdbClientLocator.IsAvailable())
|
||||
{
|
||||
AnsiConsole.MarkupLine("[red][[ERROR]][/] hdbsql not found. " +
|
||||
"Ensure the SAP HANA client is installed and on your PATH, " +
|
||||
"or present in [dim]/usr/sap/hdbclient[/] or [dim]/usr/sap/NDB/HDB00/exe[/].");
|
||||
AnsiConsole.MarkupLine("\nPress any key to exit.");
|
||||
Console.ReadKey(intercept: true);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Show client path for reference
|
||||
var clientDir = HdbClientLocator.ClientDirectory;
|
||||
if (clientDir is not null)
|
||||
AnsiConsole.MarkupLine($"[dim]HDB client: {clientDir}[/]\n");
|
||||
|
||||
// Load keys with a spinner
|
||||
List<HdbUserstoreKey> keys = [];
|
||||
|
||||
AnsiConsole.Status()
|
||||
.Spinner(Spinner.Known.Dots)
|
||||
.SpinnerStyle(Style.Parse("blue"))
|
||||
.Start("[blue]Loading hdbuserstore keys...[/]", _ =>
|
||||
{
|
||||
keys = HdbCliRunner.ListKeys();
|
||||
});
|
||||
|
||||
if (keys.Count == 0)
|
||||
{
|
||||
AnsiConsole.MarkupLine("[yellow][[WARN]][/] No hdbuserstore keys found.");
|
||||
AnsiConsole.MarkupLine("You can still enter a key name manually.\n");
|
||||
}
|
||||
|
||||
// Build selection choices
|
||||
var choices = new List<string>();
|
||||
foreach (var k in keys)
|
||||
{
|
||||
var detail = BuildKeyDetail(k);
|
||||
choices.Add(detail);
|
||||
}
|
||||
choices.Add("[dim][ Enter key name manually ][/]");
|
||||
choices.Add("[red][ Exit ][/]");
|
||||
|
||||
var prompt = new SelectionPrompt<string>()
|
||||
.Title("[bold]Select HDBUSERSTORE key:[/]")
|
||||
.PageSize(15)
|
||||
.HighlightStyle(Style.Parse("bold dodgerblue1"))
|
||||
.AddChoices(choices);
|
||||
|
||||
var selected = AnsiConsole.Prompt(prompt);
|
||||
|
||||
if (selected.Contains("Exit"))
|
||||
return null;
|
||||
|
||||
if (selected.Contains("manually"))
|
||||
{
|
||||
var manual = AnsiConsole.Ask<string>("[bold]Enter HDBUSERSTORE key name:[/]").Trim();
|
||||
return string.IsNullOrWhiteSpace(manual) ? null : manual;
|
||||
}
|
||||
|
||||
// Extract the key name from the formatted string (it's always the first word)
|
||||
var keyName = selected.Split(' ')[0].Trim();
|
||||
return keyName;
|
||||
}
|
||||
|
||||
private static string BuildKeyDetail(HdbUserstoreKey k)
|
||||
{
|
||||
var parts = new List<string> { k.Name };
|
||||
|
||||
if (!string.IsNullOrEmpty(k.Host))
|
||||
parts.Add($"[dim]{k.Host}:{k.Port}[/]");
|
||||
if (!string.IsNullOrEmpty(k.Tenant))
|
||||
parts.Add($"[dim]@{k.Tenant}[/]");
|
||||
if (!string.IsNullOrEmpty(k.User))
|
||||
parts.Add($"[dim]user={k.User}[/]");
|
||||
|
||||
return string.Join(" ", parts);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user