Skip to content

Commit 91ec418

Browse files
committed
[edit] split StatusBar into ConnectionStatusBar header and StatusBar footer
1 parent 5855ee2 commit 91ec418

9 files changed

Lines changed: 62 additions & 36 deletions

File tree

src/EtcdTerminal.App/Engine/Menu.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using EtcdTerminal;
2+
using EtcdTerminal.App.Modules;
23
using System.Text.RegularExpressions;
34

45
namespace EtcdTerminal.App.Engine;
@@ -7,7 +8,6 @@ public static class Menu
78
{
89
private const string _arrow = " ❯ ";
910
private const string _emptyIndent = " ";
10-
private const string _navHint = "(\u2191/\u2193 navigate, Enter confirm, Esc back)";
1111
private const string _clearAnsi = "\x1b[J";
1212

1313
public static string? Show(string title, IEnumerable<string> choices, Func<string, string>? displayConverter = null)
@@ -50,10 +50,10 @@ public static class Menu
5050
Console.WriteLine();
5151
}
5252

53-
Console.WriteLine();
54-
Console.ForegroundColor = ConsoleColor.DarkGray;
55-
Console.Write(_navHint);
56-
Console.ResetColor();
53+
var menuEnd = Console.CursorTop;
54+
StatusBar.Render();
55+
Console.CursorTop = menuEnd;
56+
Console.CursorLeft = 0;
5757

5858
while (true)
5959
{
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using EtcdTerminal;
2+
using EtcdTerminal.Models;
3+
using Spectre.Console;
4+
5+
namespace EtcdTerminal.App.Modules;
6+
7+
public static class ConnectionStatusBar
8+
{
9+
public static void Render(EtcdConnectionConfig config)
10+
{
11+
var dot = "[green]●[/]";
12+
var connStr = config.ConnectionString.Length > 50
13+
? config.ConnectionString[..50] + "..."
14+
: config.ConnectionString;
15+
var auth = config.IsAuthenticationEnabled
16+
? $" [grey]│[/] [yellow]{config.Username}[/]"
17+
: "";
18+
var bg = new Style(background: Color.FromHex("1b1c1e"));
19+
20+
AnsiConsole.Write(new Rule(" ") { Style = bg, Border = BoxBorder.None });
21+
AnsiConsole.Write(new Rule($" {dot} [bold cyan]{config.Name}[/] [grey]│[/] [grey]{connStr}[/]{auth} ")
22+
{
23+
Style = bg,
24+
Border = BoxBorder.None
25+
});
26+
AnsiConsole.Write(new Rule(" ") { Style = bg, Border = BoxBorder.None });
27+
AnsiConsole.WriteLine();
28+
}
29+
}
Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
using EtcdTerminal;
2-
using EtcdTerminal.Models;
3-
using Spectre.Console;
4-
51
namespace EtcdTerminal.App.Modules;
62

73
public static class StatusBar
84
{
9-
public static void Render(EtcdConnectionConfig config)
5+
public static void Render()
106
{
11-
var dot = "[green]●[/]";
12-
var connStr = config.ConnectionString.Length > 50
13-
? config.ConnectionString[..50] + "..."
14-
: config.ConnectionString;
15-
var auth = config.IsAuthenticationEnabled
16-
? $" [grey]│[/] [yellow]{config.Username}[/]"
17-
: "";
18-
var bg = new Style(background: Color.FromHex("1b1c1e"));
7+
var bgSeq = "\x1b[48;2;27;28;30m";
8+
var fgSeq = "\x1b[38;2;210;210;210m";
9+
var resetSeq = "\x1b[0m";
10+
var fill = new string(' ', Console.WindowWidth);
11+
var hintText = " (\u2191/\u2193 navigate, Enter confirm, Esc back) ";
12+
var hintLine = (hintText + fill)[..Console.WindowWidth];
13+
14+
Console.CursorTop = Console.WindowHeight - 3;
15+
Console.CursorLeft = 0;
16+
Console.Write(bgSeq + fill + resetSeq);
17+
18+
Console.CursorTop = Console.WindowHeight - 2;
19+
Console.CursorLeft = 0;
20+
Console.Write(bgSeq + fgSeq + hintLine + resetSeq);
1921

20-
AnsiConsole.Write(new Rule(" ") { Style = bg, Border = BoxBorder.None });
21-
AnsiConsole.Write(new Rule($" {dot} [bold cyan]{config.Name}[/] [grey]│[/] [grey]{connStr}[/]{auth} ")
22-
{
23-
Style = bg,
24-
Border = BoxBorder.None
25-
});
26-
AnsiConsole.Write(new Rule(" ") { Style = bg, Border = BoxBorder.None });
27-
AnsiConsole.WriteLine();
22+
Console.CursorTop = Console.WindowHeight - 1;
23+
Console.CursorLeft = 0;
24+
Console.Write(bgSeq + fill + resetSeq);
2825
}
2926
}

src/EtcdTerminal.App/Screens/KeyBrowseScreen.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ private async Task MainLoopAsync()
201201
private void Render()
202202
{
203203
AnsiConsole.Clear();
204-
StatusBar.Render(_config);
204+
ConnectionStatusBar.Render(_config);
205205

206206
Console.Write(new string(' ', LinePadding));
207207
RenderSearchBar();
@@ -290,7 +290,7 @@ private async Task EditKeyAsync()
290290
return;
291291

292292
AnsiConsole.Clear();
293-
StatusBar.Render(_config);
293+
ConnectionStatusBar.Render(_config);
294294
AnsiConsole.MarkupLine($"Editing key: [cyan]{Markup.Escape(_selectedKey.Key)}[/]");
295295
AnsiConsole.MarkupLine($"Current value: [green]{Markup.Escape(TruncateText(_selectedKey.Value, EditValueMaxLength))}[/]");
296296
Console.WriteLine();
@@ -303,7 +303,7 @@ private async Task EditKeyAsync()
303303
var result = await _etcdClient.UpdateKeyAsync(_selectedKey.Key, newValue);
304304

305305
AnsiConsole.Clear();
306-
StatusBar.Render(_config);
306+
ConnectionStatusBar.Render(_config);
307307

308308
if (result)
309309
{
@@ -326,7 +326,7 @@ private async Task DeleteKeyAsync()
326326
return;
327327

328328
AnsiConsole.Clear();
329-
StatusBar.Render(_config);
329+
ConnectionStatusBar.Render(_config);
330330
AnsiConsole.MarkupLine($"Delete key: [red]{Markup.Escape(_selectedKey.Key)}[/]");
331331
Console.WriteLine();
332332

@@ -338,7 +338,7 @@ private async Task DeleteKeyAsync()
338338
var result = await _etcdClient.DeleteKeyAsync(_selectedKey.Key);
339339

340340
AnsiConsole.Clear();
341-
StatusBar.Render(_config);
341+
ConnectionStatusBar.Render(_config);
342342

343343
if (result)
344344
{

src/EtcdTerminal.App/Screens/KeyCreateScreen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public sealed class KeyCreateScreen(IEtcdClient _etcdClient)
1616
public async Task ShowAsync(EtcdConnectionConfig config)
1717
{
1818
AnsiConsole.Clear();
19-
StatusBar.Render(config);
19+
ConnectionStatusBar.Render(config);
2020

2121
var key = Prompt.Ask(EnterKeyPrompt);
2222

src/EtcdTerminal.App/Screens/MainScreen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public async Task ShowAsync(EtcdConnectionConfig config)
1919
while (true)
2020
{
2121
AnsiConsole.Clear();
22-
StatusBar.Render(config);
22+
ConnectionStatusBar.Render(config);
2323

2424
var choice = Menu.Show(
2525
"",

src/EtcdTerminal.App/Screens/PermissionViewScreen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public sealed class PermissionViewScreen(IEtcdClient _etcdClient)
1414
public async Task ShowAsync(EtcdConnectionConfig config)
1515
{
1616
AnsiConsole.Clear();
17-
StatusBar.Render(config);
17+
ConnectionStatusBar.Render(config);
1818

1919
await AnsiConsole.Status()
2020
.StartAsync(LoadingPermissions, async ctx =>

src/EtcdTerminal.App/Screens/RoleManagementScreen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public async Task ShowAsync(EtcdConnectionConfig config)
3434
while (true)
3535
{
3636
AnsiConsole.Clear();
37-
StatusBar.Render(config);
37+
ConnectionStatusBar.Render(config);
3838

3939
var choice = Menu.Show(Title, new[]
4040
{

src/EtcdTerminal.App/Screens/UserManagementScreen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public async Task ShowAsync(EtcdConnectionConfig config)
3939
while (true)
4040
{
4141
AnsiConsole.Clear();
42-
StatusBar.Render(config);
42+
ConnectionStatusBar.Render(config);
4343

4444
var choice = Menu.Show(Title, new[]
4545
{

0 commit comments

Comments
 (0)