Input Reader

May I read what you've written, please?

This functionality is an important part of any interactive console application, because it gives users a chance to input what they want to write to the console.

In case you want to listen to mouse events, you can consult the below page:

Pointer Events

In case you want to use something other than the reader, you can consult the other input tools defined in the below page:

Other Input

You can easily use this feature in any interactive console application that uses Terminaux. Just use the Terminaux.Reader.TermReader class that contains the Read() functions and their overloaded versions.

The reader not only provides the static text version for input prompts, but also the dynamic text version. Just create a simple function delegate that generates a string as the first argument, like this:

string input = TermReader.Read(() => $"{DateTime.Now} [{TermReaderState.CurrentState.CurrentTextPos}]\n> ", "Hello World!", false, false, false);

Please note that they are interruptible by default. If you want the input to be non-interruptible, you can set the interruptible argument to false.

Each one of these functions creates a reader state, TermReaderState, that contains essential information about the current reader state, including, but not limited to:

  • Current text

  • Input prompt text

  • Current text position

  • Kill buffer

  • Reader settings

If you're making your own mod in Nitrocid KS, it's best to use its own Input class instead of Terminaux's TermReader, as the class there actually deals with the screensaver in most circumstances.

Any key will append the selected characters to the current text input, and RETURN will accept the input. The below keybindings are available:

KeybindingAction

ENTER

Accepts input

Ctrl+C

Cancels reading (if TreatCtrlCAsInput is enabled)

Ctrl+A / HOME

Beginning of line

Ctrl+E / END

End of line

Ctrl+B /

Backward one character

Ctrl+F /

Forward one character

BACKSPACE

Remove one character from the left

UP ARROW

Get the older input

DOWN ARROW

Get the newer input

DELETE

Remove one character in current position

ALT+B

One word backward

ALT+F

One word forward

TAB

Next auto-completion entry (if there is one)

Insert four spaces (if no autocompletions)

SHIFT+TAB

Previous auto-completion entry

CTRL+U

Cut to the start of the line

CTRL+K

Cut to the end of the line

CTRL+W

Cut to the end of the previous word

ALT+D

Cut to the end of the next word

CTRL+Y

Yank the cut content

Alt+L

Make word lowercase

Alt+U

Make word UPPERCASE

Ctrl+Alt+L

Make input lowercase

Ctrl+Alt+U

Make input UPPERCASE

Alt+C

Make character uppercase and move to the end of word

Alt+V

Make character lowercase and move to the end of word

Alt+S

Shows all suggestions in the style akin to the Bourne Again SHell (bash)

Alt+R

Refreshes the prompt, the text input, and the current cursor position.

Insert

Text append mode (Insert or append)

CTRL+L

Clears the screen and refreshes the prompt.

ALT+\

Cut the whitespaces before and after the character.

CTRL+T

Substitutes two characters

ALT+T

Substitutes two words

ALT+SHIFT+#

Makes your current input text a comment (visual only, but ignores your text on submit)

ALT+TAB / CTRL+I

Forces the tab character to be written. Writes as spaces.

ALT+SHIFT+C

Temporarily conceals or reveals the whole input in normal prompts.

Warning: Some of the keys conflict with the terminal emulator and/or the operating system keybindings.

For more information about custom key bindings, go to the below page.

Custom Bindings

You can access the global reader settings by referencing the GlobalReaderSettings found in the TermReader class.

History tools

You can now set the history entry list with your array of history entries or clear the history list using the following functions:

  • SetHistory(List<string> History)

    • Sets the history to the chosen history list

  • ClearHistory()

    • Clears all history entries

State tools

You can also check to see if the console reader facility is busy getting input or not. The property, Busy, indicates this by returning true if there is input to be entered by the user.

If you want to wait for user input to finish, you can call the WaitForInput() function in the TermReaderTools class.