ReadLine.Ext 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package ReadLine.Ext --version 0.0.1
NuGet\Install-Package ReadLine.Ext -Version 0.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ReadLine.Ext" Version="0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ReadLine.Ext --version 0.0.1
#r "nuget: ReadLine.Ext, 0.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ReadLine.Ext as a Cake Addin
#addin nuget:?package=ReadLine.Ext&version=0.0.1

// Install ReadLine.Ext as a Cake Tool
#tool nuget:?package=ReadLine.Ext&version=0.0.1

ReadLine.Ext

Build NuGet License

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 extends ReadLine.IConsole.
  • The library adds a supporting class ReadLine.KeyParser that can parse Ansi/VT-100 escapecodes into System.ConsoleKeyInfo to make it easy to implement custom IConsole classes. The KeyParser 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 Comment
Ctrl+A / HOME Beginning of line
Ctrl+B / Backward one character
Ctrl+C Send EOF
Ctrl+E / END End of line
Ctrl+F / Forward one character
Ctrl+H / Backspace Delete previous character
Tab Command line completion
Shift+Tab Backwards command line completion
Ctrl+J / Enter Line feed
Ctrl+K Cut text to the end of line
Ctrl+L / Esc Clear line
Ctrl+M Same as Enter key
Ctrl+N / Forward in history
Ctrl+P / Backward in history
Ctrl+U Cut text to the start of line
Ctrl+W Cut previous word
Backspace Delete previous character
Ctrl + D / Delete Delete succeeding character

Installation

Available on NuGet

Visual Studio:

PM> Install-Package ReadLine

.NET Core CLI:

dotnet add package ReadLine

Usage

Read input from the console

string input = ReadLine.Read("(prompt)> ");

Read password from the console

string password = ReadLine.ReadPassword("(prompt)> ");

Read input from custom console

class MyConsole : IConsole { ... };
var console = new MyConsole();
string input = console.Read("(prompt)> ");

Note: The (prompt>) is optional

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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 162 9/8/2023
0.0.9-alpha.0.1 60 9/8/2023
0.0.8 164 7/4/2023
0.0.8-alpha.0.1 85 7/4/2023
0.0.7 149 7/3/2023
0.0.7-alpha.0.1 84 7/3/2023
0.0.6 135 6/16/2023
0.0.6-alpha.0.2 79 6/16/2023
0.0.5 139 6/9/2023
0.0.4 167 4/17/2023
0.0.3 170 4/17/2023
0.0.2 145 4/16/2023
0.0.1 159 4/12/2023
0.0.0-alpha.0 84 4/12/2023