@@ -9,18 +9,15 @@ namespace CLARiNET
9
9
{
10
10
class Program
11
11
{
12
- private static ConsoleColor _savedForegroundColor = Console . ForegroundColor ;
13
-
12
+
14
13
static void Main ( string [ ] args )
15
14
{
16
15
Options options = new Options ( ) ;
17
16
string url = "https://{host}/ccx/cc-cloud-repo/collections/" ;
18
17
string host = "" ;
19
- Program . _savedForegroundColor = Console . ForegroundColor ;
20
18
21
19
try
22
20
{
23
- Console . CancelKeyPress += new ConsoleCancelEventHandler ( Cleanup ) ;
24
21
XDocument xDoc = XDocument . Parse ( Resources . WDEnvironments ) ;
25
22
List < XElement > envs = new List < XElement > ( xDoc . Descendants ( XName . Get ( "env" ) ) ) ;
26
23
@@ -120,17 +117,10 @@ static void Main(string[] args)
120
117
if ( options . Password == null )
121
118
{
122
119
Console . WriteLine ( "Enter the password (will not be displayed):\n " ) ;
123
- Console . Write ( "->" ) ;
124
- ConsoleColor color = Console . ForegroundColor ;
125
- Console . CursorVisible = false ;
126
- Console . ForegroundColor = Console . BackgroundColor ;
127
- options . Password = Console . ReadLine ( ) . Trim ( ) ;
128
- Console . WriteLine ( "" ) ;
129
- Console . ForegroundColor = color ;
130
- Console . CursorVisible = true ;
120
+ options . Password = PasswordPrompt ( ) ;
131
121
}
132
122
133
- Console . WriteLine ( "Deploying the CLAR and awaiting the result...\n \n " ) ;
123
+ Console . WriteLine ( "\n \n Deploying the CLAR and awaiting the result...\n \n " ) ;
134
124
135
125
// REST Call
136
126
Byte [ ] bytes = File . ReadAllBytes ( options . ClarFile ) ;
@@ -142,20 +132,32 @@ static void Main(string[] args)
142
132
}
143
133
catch ( Exception ex )
144
134
{
145
- Cleanup ( null , null ) ;
146
135
Console . WriteLine ( ex . Message ) ;
147
136
}
148
- finally
149
- {
150
- Cleanup ( null , null ) ;
151
- }
152
137
}
153
138
154
- protected static void Cleanup ( object sender , ConsoleCancelEventArgs args )
139
+ private static string PasswordPrompt ( )
155
140
{
156
- Console . ForegroundColor = Program . _savedForegroundColor ;
157
- Console . CursorVisible = true ;
158
- }
141
+ string pass = string . Empty ;
142
+ ConsoleKey key ;
143
+ do
144
+ {
145
+ var keyInfo = Console . ReadKey ( intercept : true ) ;
146
+ key = keyInfo . Key ;
147
+
148
+ if ( key == ConsoleKey . Backspace && pass . Length > 0 )
149
+ {
150
+ Console . Write ( "\b \b " ) ;
151
+ pass = pass [ 0 ..^ 1 ] ;
152
+ }
153
+ else if ( ! char . IsControl ( keyInfo . KeyChar ) )
154
+ {
155
+ Console . Write ( "*" ) ;
156
+ pass += keyInfo . KeyChar ;
157
+ }
158
+ } while ( key != ConsoleKey . Enter ) ;
159
+ return pass ;
160
+ }
159
161
160
162
private static void PrintEnvironments ( List < XElement > envs )
161
163
{
0 commit comments