Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Commit

Permalink
Made a flag to let you know if it ran to completion
Browse files Browse the repository at this point in the history
  • Loading branch information
AptiviCEO committed Jun 2, 2022
1 parent a2e718e commit ad7f28b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public override void RunFixture()
{
ReadLine.CtrlCEnabled = true;
input = ReadLine.Read("(prompt)> ");
Console.WriteLine($"<< {input}");
if (ReadLine.ReadRanToCompletion)
Console.WriteLine($"<< {input}");
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions ReadLine.Reboot/ReadLine.Reboot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<PropertyGroup>
<AssemblyTitle>ReadLine.Reboot</AssemblyTitle>
<AssemblyDescription>A reboot of tonerdo's ReadLine library for .NET</AssemblyDescription>
<AssemblyVersion>3.0.0</AssemblyVersion>
<Description>A reboot of tonerdo's ReadLine library for .NET</Description>
<AssemblyVersion>3.0.1</AssemblyVersion>
<Authors>Toni Solarin-Sodara,EoflaOE</Authors>
<TargetFrameworks>net6.0;netcoreapp3.1;net48</TargetFrameworks>
<DebugType>portable</DebugType>
Expand All @@ -16,7 +17,7 @@
<RepositoryUrl>https://github.com/EoflaOE/ReadLine.Reboot</RepositoryUrl>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>3.0.0</Version>
<Version>3.0.1</Version>
<Company>EoflaOE</Company>
<Copyright>Copyright (c) 2022 EoflaOE and its companies.</Copyright>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
12 changes: 12 additions & 0 deletions ReadLine.Reboot/ReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public static class ReadLine
/// </summary>
public static bool CtrlCEnabled { get; set; }

/// <summary>
/// Whether the last <see cref="Read(string, string)"/> or <see cref="ReadPassword(string, char)"/> request ran to completion
/// </summary>
public static bool ReadRanToCompletion { get; private set; }

/// <summary>
/// The auto completion handler. You need to make a class that implements <see cref="IAutoCompleteHandler"/>
/// </summary>
Expand Down Expand Up @@ -108,6 +113,9 @@ public static void SetHistory(List<string> history)
/// <returns>The written text if anything is input from the user, or the default text if nothing if printed</returns>
public static string Read(string prompt = "", string defaultText = "")
{
// Reset the flag
ReadRanToCompletion = false;

// Prepare the prompt
WritePrompt.Invoke(prompt);
KeyHandler keyHandler = new KeyHandler(new ConsoleWrapper(), _history, AutoCompletionHandler);
Expand Down Expand Up @@ -139,6 +147,9 @@ public static string Read(string prompt = "", string defaultText = "")
/// <returns>The written text</returns>
public static string ReadPassword(string prompt = "", char mask = default)
{
// Reset the flag
ReadRanToCompletion = false;

// Prepare the prompt
WritePrompt.Invoke(prompt);
KeyHandler keyHandler = new KeyHandler(new ConsoleWrapper() { PasswordMode = true, PasswordMaskChar = mask }, null, null);
Expand Down Expand Up @@ -182,6 +193,7 @@ private static string GetText(KeyHandler keyHandler)
{
// Write a new line and get the text
Console.WriteLine();
ReadRanToCompletion = true;
return keyHandler.Text;
}
}
Expand Down

0 comments on commit ad7f28b

Please sign in to comment.