ReadLine.Ext
0.0.8-alpha.0.1
See the version list below for details.
dotnet add package ReadLine.Ext --version 0.0.8-alpha.0.1
NuGet\Install-Package ReadLine.Ext -Version 0.0.8-alpha.0.1
<PackageReference Include="ReadLine.Ext" Version="0.0.8-alpha.0.1" />
paket add ReadLine.Ext --version 0.0.8-alpha.0.1
#r "nuget: ReadLine.Ext, 0.0.8-alpha.0.1"
// Install ReadLine.Ext as a Cake Addin #addin nuget:?package=ReadLine.Ext&version=0.0.8-alpha.0.1&prerelease // Install ReadLine.Ext as a Cake Tool #tool nuget:?package=ReadLine.Ext&version=0.0.8-alpha.0.1&prerelease
ReadLine.Ext
This library is an enhanced clone of tonerdo/readline that adds the following extras ;
- Allows ReadLine to be used not only with the default
System.Console
but also any user-supplied virtual console that extendsReadLine.IConsole
. - The library adds a supporting class
ReadLine.KeyParser
that can parse Ansi/VT-100 escapecodes intoSystem.ConsoleKeyInfo
to make it easy to implement customIConsole
classes. TheKeyParser
uses an embedded copy from the implementation used in System.Console (net7.0 version). - The library is cross platform but requires net7.0 or greater.
ReadLine is a GNU Readline like library built in pure C#. It can serve as a drop in replacement for the inbuilt Console.ReadLine()
and brings along
with it some of the terminal goodness you get from unix shells, like command history navigation and tab auto completion.
Shortcut Guide
Shortcut | Alias | Comment |
---|---|---|
Ctrl +A |
Home |
Go to beginning of line |
Ctrl +E |
End |
Go to end of line |
Ctrl +B |
← |
Go backward one character |
Ctrl +F |
→ |
Go forward one character |
Alt +B |
Ctrl +← |
Go backward one word |
Alt +F |
Ctrl +→ |
Go forward one word |
Ctrl +C |
Ctrl +Z |
Send EOF |
Ctrl +H |
Backspace |
Delete previous character |
Ctrl +D |
Delete |
Delete succeeding character |
Ctrl +J |
Enter |
Line feed |
Ctrl +L |
Esc |
Clear line |
Ctrl +P |
↑ |
Backward in history |
Ctrl +N |
↓ |
Forward in history |
F3 |
Last in history | |
Insert |
Toggle insert mode | |
Ctrl +I |
Tab |
Command line completion |
Shift +Tab |
Backwards command line completion | |
Ctrl +U |
Ctrl +Home |
Cut text to the start of line |
Ctrl +K |
Ctrl +End |
Cut text to the end of line |
Ctrl +W |
Ctrl +Backspace |
Cut previous word |
Alt +D |
Cut succeeding word | |
Ctrl +T |
Swap last two chars before the cursor (typo) |
Usage
Read input from the console
string input = ReadLine.Read("(prompt)> ");
Note: The (prompt>)
is optional
Read password from the console
string password = ReadLine.ReadPassword("(prompt)> ");
Read input from custom context/console
class MyConsole : IConsole { ... };
var context = new ReadContext { Console = new MyConsole() };
var input = context.Read("(prompt)> ");
ReadContext
defines the Console, Command-History and Auto-Completion to use.
Convert char[] to ConsoleKeyInfo[]
char [] input = ... ;
ConsoleKeyInfo[] keys = ReadLine.KeyParser.Parse(input);
History management
// Get command history
var history = ReadLine.Context.History;
// Add command to history
ReadLine.Context.History.Add("dotnet run");
// Clear history
ReadLine.Context.History.Clear();
// Disable history
ReadLine.Context.HistoryEnabled = false;
Note: History information is persisted for an entire application session. Also, calls to ReadLine.Read()
automatically adds the console input to history
Auto-Completion
class AutoCompletionHandler : IAutoCompleteHandler
{
// characters to start completion from
public char[] Separators { get; set; } = new char[] { ' ', '.', '/' };
// text - The current text entered in the console
// index - The index of the terminal cursor within {text}
public string[] GetSuggestions(string text, int index)
{
if (text.StartsWith("git "))
return new string[] { "init", "clone", "pull", "push" };
else
return null;
}
}
ReadLine.AutoCompletionHandler = new AutoCompletionHandler();
Note: If no "AutoCompletionHandler" is set, tab autocompletion will be disabled
Contributing
Contributions are highly welcome. If you have found a bug or if you have a feature request, please report them at this repository issues section.
Things you can help with:
- Achieve better command parity with GNU Readline.
- Add more test cases.
License
This project is licensed under the MIT license. See the LICENSE file for more info.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.0.9 | 219 | 9/8/2023 |
0.0.9-alpha.0.1 | 87 | 9/8/2023 |
0.0.8 | 188 | 7/4/2023 |
0.0.8-alpha.0.1 | 102 | 7/4/2023 |
0.0.7 | 184 | 7/3/2023 |
0.0.7-alpha.0.1 | 107 | 7/3/2023 |
0.0.6 | 170 | 6/16/2023 |
0.0.6-alpha.0.2 | 102 | 6/16/2023 |
0.0.5 | 166 | 6/9/2023 |
0.0.4 | 190 | 4/17/2023 |
0.0.3 | 206 | 4/17/2023 |
0.0.2 | 175 | 4/16/2023 |
0.0.1 | 193 | 4/12/2023 |
0.0.0-alpha.0 | 99 | 4/12/2023 |