Skip to content

Commit

Permalink
removed unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasduft committed Mar 2, 2024
1 parent 9c68967 commit 061b039
Showing 1 changed file with 0 additions and 52 deletions.
52 changes: 0 additions & 52 deletions src/releasy/Utils/ConsoleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,56 +62,4 @@ public static string[] ReadMultilineInput(string prompt)

return lines.ToArray();
}

public static string ReadPassword()
{
WriteYellow("Please enter a password: ");

var cursorStartPosition = Console.CursorLeft;
var passwordBuilder = new StringBuilder();
var continueReading = true;
while (continueReading)
{
var consoleKeyInfo = Console.ReadKey(intercept: true);
if (consoleKeyInfo.Key == ConsoleKey.Enter)
{
continueReading = false;
Console.Write(Environment.NewLine);
}
else if (consoleKeyInfo.Key == ConsoleKey.Backspace)
{
ApplyBackspace(passwordBuilder, cursorStartPosition);
}
else if (KeyIsNoArrow(consoleKeyInfo))
{
ApplyChar(passwordBuilder, consoleKeyInfo);
}
}

return passwordBuilder.ToString();
}

private static void ApplyBackspace(StringBuilder passwordBuilder, int cursorStartPosition)
{
if (passwordBuilder.Length > 0 && Console.CursorLeft > cursorStartPosition)
{
passwordBuilder.Remove(passwordBuilder.Length - 1, 1);
Console.Write("\b \b");
}
}

private static bool KeyIsNoArrow(ConsoleKeyInfo consoleKeyInfo)
{
return consoleKeyInfo.Key is not ConsoleKey.LeftArrow and
not ConsoleKey.UpArrow and
not ConsoleKey.RightArrow and
not ConsoleKey.DownArrow;
}

private static void ApplyChar(StringBuilder passwordBuilder, ConsoleKeyInfo consoleKeyInfo)
{
var passwordChar = consoleKeyInfo.KeyChar;
passwordBuilder.Append(passwordChar);
Console.Write("*");
}
}

0 comments on commit 061b039

Please sign in to comment.