Skip to content

Commit ae0f347

Browse files
committed
v1.0.2
- New password prompt. - Included Test.clar
1 parent 3b4073d commit ae0f347

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

CLARiNET.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<PackageIcon>CLARiNET.ico</PackageIcon>
88
<PackageIconUrl />
99
<ApplicationIcon>CLARiNET.ico</ApplicationIcon>
10-
<Version>1.0.1</Version>
10+
<Version>1.0.2</Version>
1111
</PropertyGroup>
1212

1313
<ItemGroup>

Program.cs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@ namespace CLARiNET
99
{
1010
class Program
1111
{
12-
private static ConsoleColor _savedForegroundColor = Console.ForegroundColor;
13-
12+
1413
static void Main(string[] args)
1514
{
1615
Options options = new Options();
1716
string url = "https://{host}/ccx/cc-cloud-repo/collections/";
1817
string host = "";
19-
Program._savedForegroundColor = Console.ForegroundColor;
2018

2119
try
2220
{
23-
Console.CancelKeyPress += new ConsoleCancelEventHandler(Cleanup);
2421
XDocument xDoc = XDocument.Parse(Resources.WDEnvironments);
2522
List<XElement> envs = new List<XElement>(xDoc.Descendants(XName.Get("env")));
2623

@@ -120,17 +117,10 @@ static void Main(string[] args)
120117
if (options.Password == null)
121118
{
122119
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();
131121
}
132122

133-
Console.WriteLine("Deploying the CLAR and awaiting the result...\n\n");
123+
Console.WriteLine("\n\nDeploying the CLAR and awaiting the result...\n\n");
134124

135125
// REST Call
136126
Byte[] bytes = File.ReadAllBytes(options.ClarFile);
@@ -142,20 +132,32 @@ static void Main(string[] args)
142132
}
143133
catch (Exception ex)
144134
{
145-
Cleanup(null, null);
146135
Console.WriteLine(ex.Message);
147136
}
148-
finally
149-
{
150-
Cleanup(null, null);
151-
}
152137
}
153138

154-
protected static void Cleanup(object sender, ConsoleCancelEventArgs args)
139+
private static string PasswordPrompt()
155140
{
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+
}
159161

160162
private static void PrintEnvironments(List<XElement> envs)
161163
{

Test.clar

6.03 KB
Binary file not shown.

0 commit comments

Comments
 (0)