ReadLine.Reboot 3.1.0

Suggested Alternatives

Terminaux

Additional Details

Please use Terminaux to take advantage of all the features that this library provides.

There is a newer version of this package available.
See the version list below for details.
dotnet add package ReadLine.Reboot --version 3.1.0
NuGet\Install-Package ReadLine.Reboot -Version 3.1.0
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.Reboot" Version="3.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ReadLine.Reboot --version 3.1.0
#r "nuget: ReadLine.Reboot, 3.1.0"
#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.Reboot as a Cake Addin
#addin nuget:?package=ReadLine.Reboot&version=3.1.0

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

ReadLine.Reboot

Build status

ReadLine.Reboot is a reboot of Toni Solarin-Sodara's original ReadLine that is discontinued. It's 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.

It is cross platform and runs anywhere .NET is supported, as long as they run on .NET Framework 4.8 or at least .NET Core 3.1.

Shortcut Guide

Note: Some keys conflict with terminal emulator keybindings.

Keybinding Action
Ctrl+A / HOME Beginning of line
Ctrl+E / END End of line
Ctrl+B / Backward one character
Ctrl+F / Forward one character
Alt+B Backward one word
Alt+F Forward one word
Ctrl+C Send EOF
Ctrl+H / Backspace Delete previous character
Ctrl+D / Delete Delete succeeding character / End of line if nothing
Ctrl+L / Esc Clear line
Ctrl+U Cut text to the start of line
Ctrl+K Cut text to the end of line
Ctrl+W / Alt+Backspace Cut previous word
Alt+D Cut next word
Alt+\ Cut horizontal line
Ctrl+Y Yank (paste the cut content)
Ctrl+T Switch two characters
Alt+T Switch two words
Alt+L Make word lowercase
Alt+U Make word uppercase
Alt+C Make char uppercase and move to the end of word
Alt+V Make char lowercase and move to the end of word
Shift+Alt+# Add comment # to the beginning of the line
Alt+Tab Insert the TAB character verbatim *
Shift+Alt+& Perform tilde expansion
Ctrl+J / Enter End of line
Ctrl+Shift+_ Undo the last change **
Alt+R Undos all the changes
Ctrl+N / Forward in history
Ctrl+P / Backward in history
Shift+Alt+< First history
Shift+Alt+> Last history (Go back to current line)
Alt+. Add last argument to current input
Ctrl+I / Tab Command line completion
Shift+Ctrl+I / Shift+Tab Backwards command line completion
Shift+Alt+* Dump all suggestions to current line
  • *: Conflicts with Alt+Tab on Windows.
  • **: Conflicts with Ctrl+Shift+_ on Windows Command Prompt

Installation

Available on NuGet

Visual Studio:

PM> Install-Package ReadLine.Reboot

.NET Core CLI:

dotnet add package ReadLine.Reboot

Comparison

Here, we'll compare some of the base features between Original ReadLine, Latency's ReadLine, and ReadLine.Reboot.

Feature Original Latency's ReadLine.Reboot Notes
CTRL + A / HOME Works Works Works
CTRL + E / END Works Works Works
CTRL + B / LEFT Works Malfunction Works Cursor goes backwards too much until the crash occurs
CTRL + F / RIGHT Works Works Works
CTRL + C Nonfunctional Malfunction Works Unimplemented in original, Latency's implementation just always exits the app, Ours works if you have CtrlCEnabled set to true
CTRL + H / BACKSPACE Works Malfunction Works Cursor goes backwards too much until the crash occurs
CTRL + D / DEL Works Works Works
CTRL + L / ESC Works Malfunction Works Cursor goes backwards too much until the crash occurs
CTRL + U Works Malfunction Works Cursor goes backwards too much until the crash occurs
CTRL + K Works Malfunction Works Cursor goes backwards too much until the crash occurs
CTRL + W Partial Partial Works Wipe all whitespace before erasure in original and Latency's
ALT + BACKSPACE Nonfunctional Malfunction Works Unimplemented in original and Latency, cursor goes backwards too much until the crash occurs (Latency)
CTRL + T Works Malfunction Works Corrupts output
CTRL + J Partial Partial Works Appends ACTUAL newline on Windows in original and Latency's
CTRL + N / DOWN (history) Partial Malfunction Works Clears line in original, corrupts output in Latency's
CTRL + P / UP (history) Partial Malfunction Works Clears line in original, corrupts output in Latency's
TAB (autocomplete) Works Works Works
TAB (no autocomplete) Partial Partial Works Whole ReadLine doesn't really support tab chars, ReadLine.Reboot treats tabs as eight spaces
SHIFT + TAB (autocomplete) Works Works Works
SHIFT + TAB (no autocomplete) Partial Partial Works Whole ReadLine doesn't really support tab chars, ReadLine.Reboot treats tabs as eight spaces

Usage

This section shows you how to use this library to read the lines and manage history. Just add this to the top of the source file you want to use ReadLine.Reboot on:

using ReadLineReboot;

Input

Note: The (prompt>) is optional

Read input
string input = ReadLine.Read("(prompt)> ");
Read input with default
string input = ReadLine.Read("(prompt)> ", "default");
Read input with custom prompt handler
ReadLine.WritePrompt = (prompt) => Console.Write($">> {prompt}");
string input = ReadLine.Read("(prompt)> ", "default");
Read password
string password = ReadLine.ReadPassword("(prompt)> ");
Read password with password mask
string password = ReadLine.ReadPassword("(prompt)> ", '*');
Interrupt reading
ReadLine.InterruptRead();

History management

Note: History information is persisted for an entire application session. Also, calls to ReadLine.Read() automatically adds the console input to history

// Get command history
ReadLine.GetHistory();

// Add command to history
ReadLine.AddHistory("dotnet run");

// Clear history
ReadLine.ClearHistory();

// Set history
List<string> newHistory = new() { "apt update", "apt dist-upgrade" };
ReadLine.SetHistory(newHistory);

// Disable history (default)
ReadLine.HistoryEnabled = false;

// Enable history
ReadLine.HistoryEnabled = true;

Auto-Completion

Note: If no "AutoCompletionHandler" is set, tab autocompletion will be disabled

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();

You can disable and enable the auto-completion feature below.

// Disable history (default)
ReadLine.AutoCompletionEnabled = false;

// Enable history
ReadLine.AutoCompletionEnabled = true;

Credits

Author For
Toni Solarin-Sodara Original ReadLine
EoflaOE Rebooting the ReadLine project

License

MIT License

Copyright (c) 2017 Toni Solarin-Sodara
Copyright (c) 2022 EoflaOE and its companies

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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. 
.NET Core netcoreapp3.1 is compatible. 
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • net6.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
3.4.1 5,228 8/25/2022
3.4.0 2,377 8/4/2022
3.4.0-build167 174 9/15/2022
3.4.0-build166 162 8/25/2022
3.4.0-build165 157 8/25/2022
3.4.0-build164 150 8/13/2022
3.4.0-build163 161 8/8/2022
3.4.0-build162 164 8/4/2022
3.4.0-build161 166 8/4/2022
3.4.0-build160 166 8/4/2022
3.4.0-build159 166 8/4/2022
3.4.0-build158 166 8/4/2022
3.4.0-build157 163 8/4/2022
3.4.0-build156 164 8/3/2022
3.4.0-build155 157 8/3/2022
3.4.0-build154 160 8/3/2022
3.4.0-build153 162 8/3/2022
3.4.0-build152 165 8/3/2022
3.4.0-build151 147 8/3/2022
3.4.0-build150 165 8/3/2022
3.4.0-build149 166 8/3/2022
3.4.0-build148 159 8/3/2022
3.4.0-build147 174 8/3/2022
3.4.0-build146 173 7/31/2022
3.4.0-build145 172 7/28/2022
3.3.2 2,062 7/26/2022
3.3.2-build144 175 7/28/2022
3.3.2-build143 176 7/26/2022
3.3.2-build142 166 7/26/2022
3.3.2-build141 184 7/19/2022
3.3.1 867 7/19/2022
3.3.1-build140 185 7/19/2022
3.3.1-build137 174 7/18/2022
3.3.1-build136 245 7/17/2022
3.3.1-build135 173 7/17/2022
3.3.1-build134 193 7/17/2022
3.3.1-build133 179 7/17/2022
3.3.1-build132 181 7/17/2022
3.3.1-build131 193 7/17/2022
3.3.1-build130 183 7/16/2022
3.3.1-build129 182 7/16/2022
3.3.1-build112 168 7/14/2022
3.3.1-build111 179 7/14/2022
3.3.1-build110 183 7/12/2022
3.2.0 765 7/9/2022
3.1.2 1,347 6/8/2022
3.1.1 464 6/8/2022
3.1.0 460 6/8/2022
3.0.1 550 6/2/2022
3.0.0 431 6/1/2022