Skip to content

Commit f46cece

Browse files
committed
[r] consolidate prompt and menu markup strings into named constants
1 parent 9e79716 commit f46cece

8 files changed

Lines changed: 37 additions & 29 deletions

File tree

src/EtcdTerminal.App/Engine/Menu.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ namespace EtcdTerminal.App.Engine;
66
public static class Menu
77
{
88
private const string _arrow = " ❯ ";
9+
private const string _emptyIndent = " ";
10+
private const string _navHint = "(\u2191/\u2193 navigate, Enter confirm, Esc back)";
11+
private const string _clearAnsi = "\x1b[J";
912

1013
public static string? Show(string title, IEnumerable<string> choices, Func<string, string>? displayConverter = null)
1114
{
@@ -34,7 +37,7 @@ public static class Menu
3437

3538
for (var i = 0; i < items.Count; i++)
3639
{
37-
Console.Write(i == 0 ? _arrow : " ");
40+
Console.Write(i == 0 ? _arrow : _emptyIndent);
3841

3942
if (i == 0)
4043
Console.ForegroundColor = ConsoleColor.Yellow;
@@ -49,7 +52,7 @@ public static class Menu
4952

5053
Console.WriteLine();
5154
Console.ForegroundColor = ConsoleColor.DarkGray;
52-
Console.Write("(\u2191/\u2193 navigate, Enter confirm, Esc back)");
55+
Console.Write(_navHint);
5356
Console.ResetColor();
5457

5558
while (true)
@@ -62,12 +65,12 @@ public static class Menu
6265
case ConsoleKey.Escape:
6366
Console.CursorTop = menuStart;
6467
Console.CursorLeft = 0;
65-
Console.Write("\x1b[J");
68+
Console.Write(_clearAnsi);
6669
return null;
6770
case ConsoleKey.Enter:
6871
Console.CursorTop = menuStart;
6972
Console.CursorLeft = 0;
70-
Console.Write("\x1b[J");
73+
Console.Write(_clearAnsi);
7174
return items[index];
7275
case ConsoleKey.UpArrow:
7376
index = (index - 1 + items.Count) % items.Count;
@@ -81,7 +84,7 @@ public static class Menu
8184

8285
Console.CursorTop = firstItemTop + oldIndex;
8386
Console.CursorLeft = 0;
84-
Console.Write(" ");
87+
Console.Write(_emptyIndent);
8588

8689
WriteTruncated(plain[oldIndex]);
8790

src/EtcdTerminal.App/Engine/Prompt.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ namespace EtcdTerminal.App.Engine;
66

77
public static class Prompt
88
{
9+
private const string PromptFormat = "[bold]{0}[/] ";
10+
private const string ConfirmFormat = "[bold]{0}[/] [grey][y/N][/] ";
11+
public const string PressAnyKeyMarkup = "[grey]Press any key to continue...[/]";
12+
913
public static string? Ask(string prompt)
1014
{
11-
AnsiConsole.Markup($"[bold]{Markup.Escape(prompt)}[/] ");
15+
AnsiConsole.Markup(PromptFormat, Markup.Escape(prompt));
1216

1317
return ReadLine();
1418
}
1519

1620
public static string? Ask(string prompt, string defaultValue)
1721
{
18-
AnsiConsole.Markup($"[bold]{Markup.Escape(prompt)}[/] ");
22+
AnsiConsole.Markup(PromptFormat, Markup.Escape(prompt));
1923

2024
var input = ReadLine(defaultValue);
2125

@@ -24,14 +28,14 @@ public static class Prompt
2428

2529
public static string? Secret(string prompt)
2630
{
27-
AnsiConsole.Markup($"[bold]{Markup.Escape(prompt)}[/] ");
31+
AnsiConsole.Markup(PromptFormat, Markup.Escape(prompt));
2832

2933
return ReadSecret();
3034
}
3135

3236
public static bool? Confirm(string prompt)
3337
{
34-
AnsiConsole.Markup($"[bold]{Markup.Escape(prompt)}[/] [grey][y/N][/] ");
38+
AnsiConsole.Markup(ConfirmFormat, Markup.Escape(prompt));
3539

3640
while (true)
3741
{

src/EtcdTerminal.App/Screens/InstanceSelectionScreen.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ await AnsiConsole.Status()
5454
AnsiConsole.MarkupLine($"[red]Failed to connect: {ex.Message}[/]");
5555
AnsiConsole.WriteLine();
5656

57-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
57+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
5858
Console.ReadKey(true);
5959
}
6060
}
@@ -114,7 +114,7 @@ private void AddInstanceInteractive()
114114
if (string.IsNullOrWhiteSpace(name))
115115
{
116116
AnsiConsole.MarkupLine("[red]Instance name cannot be empty.[/]");
117-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
117+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
118118
Console.ReadKey(true);
119119

120120
return;
@@ -128,7 +128,7 @@ private void AddInstanceInteractive()
128128
if (!Uri.TryCreate(connectionString, UriKind.Absolute, out var uri) || uri.Scheme is not ("http" or "https"))
129129
{
130130
AnsiConsole.MarkupLine("[red]Invalid connection string. Must be a valid http or https URL.[/]");
131-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
131+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
132132
Console.ReadKey(true);
133133

134134
return;
@@ -166,7 +166,7 @@ private void AddInstanceInteractive()
166166
_configRepo.AddInstance(config);
167167

168168
AnsiConsole.MarkupLine("[green]Instance added successfully![/]");
169-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
169+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
170170
Console.ReadKey(true);
171171
}
172172

@@ -186,7 +186,7 @@ private void RemoveInstanceInteractive(IReadOnlyList<EtcdConnectionConfig> insta
186186
AnsiConsole.MarkupLine("[green]Instance removed successfully![/]");
187187
}
188188

189-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
189+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
190190
Console.ReadKey(true);
191191
}
192192

src/EtcdTerminal.App/Screens/KeyBrowseScreen.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ private async Task EditKeyAsync()
291291
}
292292

293293
Console.WriteLine();
294-
AnsiConsole.Markup("[grey]Press any key to continue...[/]");
294+
AnsiConsole.Markup(Prompt.PressAnyKeyMarkup);
295295
Console.ReadKey(true);
296296
}
297297

@@ -326,7 +326,7 @@ private async Task DeleteKeyAsync()
326326
}
327327

328328
Console.WriteLine();
329-
AnsiConsole.Markup("[grey]Press any key to continue...[/]");
329+
AnsiConsole.Markup(Prompt.PressAnyKeyMarkup);
330330
Console.ReadKey(true);
331331
}
332332

src/EtcdTerminal.App/Screens/KeyCreateScreen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public async Task ShowAsync(EtcdConnectionConfig config)
3030
else
3131
AnsiConsole.MarkupLine("[red]Key already exists or could not be created.[/]");
3232

33-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
33+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
3434
Console.ReadKey(true);
3535
}
3636
}

src/EtcdTerminal.App/Screens/PermissionViewScreen.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using EtcdTerminal;
2+
using EtcdTerminal.App.Engine;
23
using EtcdTerminal.App.Modules;
34
using EtcdTerminal.Models;
45
using Spectre.Console;
@@ -52,7 +53,7 @@ await AnsiConsole.Status()
5253
}
5354
});
5455

55-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
56+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
5657
Console.ReadKey(true);
5758
}
5859
}

src/EtcdTerminal.App/Screens/RoleManagementScreen.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private async Task ListRolesAsync()
7878
}
7979
}
8080

81-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
81+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
8282
Console.ReadKey(true);
8383
}
8484

@@ -96,7 +96,7 @@ private async Task CreateRoleAsync()
9696
else
9797
AnsiConsole.MarkupLine("[red]Failed to create role (may already exist).[/]");
9898

99-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
99+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
100100
Console.ReadKey(true);
101101
}
102102

@@ -119,7 +119,7 @@ private async Task DeleteRoleAsync()
119119
else
120120
AnsiConsole.MarkupLine("[red]Failed to delete role.[/]");
121121

122-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
122+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
123123
Console.ReadKey(true);
124124
}
125125

@@ -157,7 +157,7 @@ private async Task GrantPermissionAsync()
157157
AnsiConsole.MarkupLine("[red]Failed to grant permission.[/]");
158158
}
159159

160-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
160+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
161161
Console.ReadKey(true);
162162
}
163163

@@ -195,7 +195,7 @@ private async Task RevokePermissionAsync()
195195
AnsiConsole.MarkupLine("[red]Failed to revoke permission.[/]");
196196
}
197197

198-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
198+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
199199
Console.ReadKey(true);
200200
}
201201
}

src/EtcdTerminal.App/Screens/UserManagementScreen.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private async Task ListUsersAsync()
7575
AnsiConsole.Write(table);
7676
}
7777

78-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
78+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
7979
Console.ReadKey(true);
8080
}
8181

@@ -98,7 +98,7 @@ private async Task CreateUserAsync()
9898
else
9999
AnsiConsole.MarkupLine("[red]Failed to create user.[/]");
100100

101-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
101+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
102102
Console.ReadKey(true);
103103
}
104104

@@ -121,7 +121,7 @@ private async Task DeleteUserAsync()
121121
else
122122
AnsiConsole.MarkupLine("[red]Failed to delete user.[/]");
123123

124-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
124+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
125125
Console.ReadKey(true);
126126
}
127127

@@ -144,7 +144,7 @@ private async Task ChangePasswordAsync()
144144
else
145145
AnsiConsole.MarkupLine("[red]Failed to change password.[/]");
146146

147-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
147+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
148148
Console.ReadKey(true);
149149
}
150150

@@ -170,7 +170,7 @@ private async Task AssignRoleAsync()
170170
AnsiConsole.MarkupLine("[red]Failed to assign role.[/]");
171171
}
172172

173-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
173+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
174174
Console.ReadKey(true);
175175
}
176176

@@ -196,7 +196,7 @@ private async Task RevokeRoleAsync()
196196
AnsiConsole.MarkupLine("[red]Failed to remove role.[/]");
197197
}
198198

199-
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
199+
AnsiConsole.MarkupLine(Prompt.PressAnyKeyMarkup);
200200
Console.ReadKey(true);
201201
}
202202
}

0 commit comments

Comments
 (0)