@@ -9,14 +9,34 @@ namespace EtcdTerminal.App.Screens;
99
1010public sealed class InstanceSelectionScreen ( IConnectionConfigRepository _configRepo , IEtcdClient _etcdClient )
1111{
12+ private const string InstanceAdded = "[green]Instance added successfully![/]" ;
13+ private const string InstanceRemoved = "[green]Instance removed successfully![/]" ;
14+ private const string ConnectedSuccess = "[green]Connected successfully![/]" ;
15+ private const string NameEmpty = "[red]Instance name cannot be empty.[/]" ;
16+ private const string InvalidConnStr = "[red]Invalid connection string. Must be a valid http or https URL.[/]" ;
17+ private const string ConsoleClientDesc = "[grey]Console client for etcd v3+[/]" ;
18+ private const string ManageConnections = "Manage Connections" ;
19+ private const string AddInstance = "Add Instance" ;
20+ private const string RemoveInstance = "Remove Instance" ;
21+ private const string Exit = "Exit" ;
22+ private const string SelectInstance = "Select etcd instance:" ;
23+ private const string SelectInstanceToRemove = "Select instance to remove:" ;
24+ private const string EnterInstanceName = "Enter instance name:" ;
25+ private const string EnterConnStr = "Enter connection string:" ;
26+ private const string DefaultConnStr = "http://localhost:2379" ;
27+ private const string UseSsl = "Use SSL?" ;
28+ private const string EnterUsername = "Enter username (optional, leave empty for none):" ;
29+ private const string EnterPassword = "Enter password:" ;
30+ private const string Connecting = "Connecting..." ;
31+
1232 public async Task < EtcdConnectionConfig ? > ShowAsync ( )
1333 {
1434 while ( true )
1535 {
1636 AnsiConsole . Clear ( ) ;
1737 AnsiConsole . Write ( new FigletText ( "etcd-terminal" ) . Color ( Color . OrangeRed1 ) . Centered ( ) ) ;
1838 AnsiConsole . MarkupLineInterpolated ( $ "[grey]Version: { GetVersion ( ) } [/]") ;
19- AnsiConsole . MarkupLine ( "[grey]Console client for etcd v3+[/]" ) ;
39+ AnsiConsole . MarkupLine ( ConsoleClientDesc ) ;
2040
2141 var instances = _configRepo . LoadInstances ( ) ;
2242
@@ -25,11 +45,11 @@ public sealed class InstanceSelectionScreen(IConnectionConfigRepository _configR
2545 if ( choice is null )
2646 return null ;
2747
28- if ( choice == "Manage Connections" )
48+ if ( choice == ManageConnections )
2949 {
3050 ManageConfigs ( instances ) ;
3151 }
32- else if ( choice == " Exit" )
52+ else if ( choice == Exit )
3353 {
3454 return null ;
3555 }
@@ -40,12 +60,12 @@ public sealed class InstanceSelectionScreen(IConnectionConfigRepository _configR
4060 try
4161 {
4262 await AnsiConsole . Status ( )
43- . StartAsync ( " Connecting..." , async ctx =>
63+ . StartAsync ( Connecting , async ctx =>
4464 {
4565 await _etcdClient . ConnectAsync ( selected ) ;
4666 } ) ;
4767
48- AnsiConsole . MarkupLine ( "[green]Connected successfully![/]" ) ;
68+ AnsiConsole . MarkupLine ( ConnectedSuccess ) ;
4969
5070 return selected ;
5171 }
@@ -65,10 +85,10 @@ await AnsiConsole.Status()
6585 {
6686 var choices = new List < string > ( ) ;
6787 choices . AddRange ( instances . Select ( i => i . Name ) ) ;
68- choices . Add ( "Manage Connections" ) ;
69- choices . Add ( " Exit" ) ;
88+ choices . Add ( ManageConnections ) ;
89+ choices . Add ( Exit ) ;
7090
71- return Menu . Show ( "Select etcd instance:" , choices , c =>
91+ return Menu . Show ( SelectInstance , choices , c =>
7292 {
7393 var instance = instances . FirstOrDefault ( i => i . Name == c ) ;
7494
@@ -82,29 +102,29 @@ private void ManageConfigs(IReadOnlyList<EtcdConnectionConfig> instances)
82102 {
83103 AnsiConsole . Clear ( ) ;
84104
85- var manageChoices = new List < string > { "Add Instance" } ;
105+ var manageChoices = new List < string > { AddInstance } ;
86106
87107 if ( instances . Count > 0 )
88- manageChoices . Add ( "Remove Instance" ) ;
108+ manageChoices . Add ( RemoveInstance ) ;
89109
90- var action = Menu . Show ( "Manage Connections" , manageChoices ) ;
110+ var action = Menu . Show ( ManageConnections , manageChoices ) ;
91111
92112 if ( action is null )
93113 return ;
94114
95- if ( action == "Add Instance" )
115+ if ( action == AddInstance )
96116 {
97117 AddInstanceInteractive ( ) ;
98118 }
99- else if ( action == "Remove Instance" )
119+ else if ( action == RemoveInstance )
100120 {
101121 RemoveInstanceInteractive ( instances ) ;
102122 }
103123 }
104124
105125 private void AddInstanceInteractive ( )
106126 {
107- var name = Prompt . Ask ( "Enter instance name:" ) ;
127+ var name = Prompt . Ask ( EnterInstanceName ) ;
108128
109129 if ( name is null )
110130 return ;
@@ -113,33 +133,33 @@ private void AddInstanceInteractive()
113133
114134 if ( string . IsNullOrWhiteSpace ( name ) )
115135 {
116- AnsiConsole . MarkupLine ( "[red]Instance name cannot be empty.[/]" ) ;
136+ AnsiConsole . MarkupLine ( NameEmpty ) ;
117137 AnsiConsole . MarkupLine ( Prompt . PressAnyKeyMarkup ) ;
118138 Console . ReadKey ( true ) ;
119139
120140 return ;
121141 }
122142
123- var connectionString = Prompt . Ask ( "Enter connection string:" , "http://localhost:2379" ) ;
143+ var connectionString = Prompt . Ask ( EnterConnStr , DefaultConnStr ) ;
124144
125145 if ( connectionString is null )
126146 return ;
127147
128148 if ( ! Uri . TryCreate ( connectionString , UriKind . Absolute , out var uri ) || uri . Scheme is not ( "http" or "https" ) )
129149 {
130- AnsiConsole . MarkupLine ( "[red]Invalid connection string. Must be a valid http or https URL.[/]" ) ;
150+ AnsiConsole . MarkupLine ( InvalidConnStr ) ;
131151 AnsiConsole . MarkupLine ( Prompt . PressAnyKeyMarkup ) ;
132152 Console . ReadKey ( true ) ;
133153
134154 return ;
135155 }
136156
137- var useSsl = Prompt . Confirm ( "Use SSL?" ) ;
157+ var useSsl = Prompt . Confirm ( UseSsl ) ;
138158
139159 if ( useSsl is null )
140160 return ;
141161
142- var username = Prompt . Ask ( "Enter username (optional, leave empty for none):" ) ;
162+ var username = Prompt . Ask ( EnterUsername ) ;
143163
144164 if ( username is null )
145165 return ;
@@ -148,7 +168,7 @@ private void AddInstanceInteractive()
148168
149169 if ( ! string . IsNullOrEmpty ( username ) )
150170 {
151- password = Prompt . Secret ( "Enter password:" ) ;
171+ password = Prompt . Secret ( EnterPassword ) ;
152172
153173 if ( password is null )
154174 return ;
@@ -165,14 +185,14 @@ private void AddInstanceInteractive()
165185
166186 _configRepo . AddInstance ( config ) ;
167187
168- AnsiConsole . MarkupLine ( "[green]Instance added successfully![/]" ) ;
188+ AnsiConsole . MarkupLine ( InstanceAdded ) ;
169189 AnsiConsole . MarkupLine ( Prompt . PressAnyKeyMarkup ) ;
170190 Console . ReadKey ( true ) ;
171191 }
172192
173193 private void RemoveInstanceInteractive ( IReadOnlyList < EtcdConnectionConfig > instances )
174194 {
175- var nameToRemove = Menu . Show ( "Select instance to remove:" , instances . Select ( i => i . Name ) ) ;
195+ var nameToRemove = Menu . Show ( SelectInstanceToRemove , instances . Select ( i => i . Name ) ) ;
176196
177197 if ( nameToRemove is null )
178198 return ;
@@ -183,7 +203,7 @@ private void RemoveInstanceInteractive(IReadOnlyList<EtcdConnectionConfig> insta
183203 {
184204 _configRepo . RemoveInstance ( nameToRemove ) ;
185205
186- AnsiConsole . MarkupLine ( "[green]Instance removed successfully![/]" ) ;
206+ AnsiConsole . MarkupLine ( InstanceRemoved ) ;
187207 }
188208
189209 AnsiConsole . MarkupLine ( Prompt . PressAnyKeyMarkup ) ;
0 commit comments