Skip to content

Commit

Permalink
Merge pull request #25 from psylenced/add-history-override
Browse files Browse the repository at this point in the history
History now has a global and per-call override.
  • Loading branch information
tonerdo authored Oct 22, 2017
2 parents 5a40db2 + 09a6be1 commit 6d247be
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ReadLine/ReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ static ReadLine()
public static void ClearHistory() => _history = new List<string>();
public static Func<string, int, string[]> AutoCompletionHandler { private get; set; }
public static bool PasswordMode { private get; set; }
public static bool DisableHistory { get; set; }

public static string Read(string prompt = "", string defaultInput = "")
public static string Read(string prompt = "", string defaultInput = "", bool? enableHistory = null)
{
Console.Write(prompt);

_keyHandler = new KeyHandler(new Console2() { PasswordMode = PasswordMode }, _history, AutoCompletionHandler);
bool useHistory = enableHistory ?? !DisableHistory;
var history = useHistory ? _history : new List<string>();

_keyHandler = new KeyHandler(new Console2() { PasswordMode = PasswordMode }, history, AutoCompletionHandler);
ConsoleKeyInfo keyInfo = Console.ReadKey(true);

while (keyInfo.Key != ConsoleKey.Enter)
Expand All @@ -39,7 +43,7 @@ public static string Read(string prompt = "", string defaultInput = "")
string text = _keyHandler.Text;
if (String.IsNullOrWhiteSpace(text) && !String.IsNullOrWhiteSpace(defaultInput))
text = defaultInput;
else
else if (useHistory)
_history.Add(text);

return text;
Expand Down

0 comments on commit 6d247be

Please sign in to comment.