Class TerminalInputSource
- Namespace
- MiniTui
- Assembly
- MiniTui.dll
The default input source: on Linux and macOS it puts the terminal in raw mode, and on Windows the console in VT input mode, and decodes the input bytes itself, so Esc, Alt, function keys and modifier combinations decode the same way everywhere, and a key sequence split across reads is reassembled instead of producing a stray Esc. It also turns on bracketed paste, so a paste arrives as one PasteEvent instead of keys. Conhost has no bracketed paste, so there Ctrl+V pastes the clipboard's text as a PasteEvent. Wherever raw or VT input isn't available, it reads keys like ConsoleInputSource, and pasted text arrives as keys.
public sealed class TerminalInputSource : IInputSource, IDisposable
- Inheritance
-
TerminalInputSource
- Implements
- Inherited Members
Remarks
In raw mode the terminal doesn't handle Ctrl+C, Ctrl+Z, Ctrl+, Ctrl+S or Ctrl+Q itself: they reach the app as
keys. Ctrl+C still quits through Keys. Set the MINITUI_INPUT environment variable to
console to make ConsoleInputSource the default instead.
Constructors
TerminalInputSource()
Create a source with the DefaultEscapeTimeout.
public TerminalInputSource()
TerminalInputSource(TimeSpan)
Create a source with a custom escape timeout.
public TerminalInputSource(TimeSpan escapeTimeout)
Parameters
escapeTimeoutTimeSpanHow long to wait after an Esc byte for the rest of a key sequence before treating it as the Esc key. Zero resolves at the end of each read.
Exceptions
- ArgumentOutOfRangeException
escapeTimeoutis negative or over 1 second.
Properties
DefaultEscapeTimeout
The default escape timeout, 50 ms.
public static TimeSpan DefaultEscapeTimeout { get; }
Property Value
EscapeTimeout
How long a lone Esc byte waits for the rest of a sequence.
public TimeSpan EscapeTimeout { get; }
Property Value
Methods
Dispose()
Restore the terminal mode if this source changed it.
public void Dispose()
TryRead(out ConsoleKeyInfo)
Read the next key if one is available, skipping any pastes and mouse events ahead of it. Never blocks.
public bool TryRead(out ConsoleKeyInfo key)
Parameters
keyConsoleKeyInfo