How PrettyPrompt handles cross-platform input and output
mainPrettyPrompt uses a hybrid approach to ensure cross-platform compatibility between Windows, Linux, and macOS:
- Output (ANSI Escape Sequences): Uses ANSI sequences for syntax highlighting, cursor positioning, and clearing the screen (defined in
AnsiEscapeCodes.cs). This approach is thread-safe and allows for efficient incremental screen updates via character streams. - Input (System.Console APIs): Uses standard Console APIs for reading characters from
STDIN(viaSystemConsole.cs).
Why this hybrid approach? While ANSI sequences are used for output, the library avoids using ANSI sequences for input because:
- Standard Console APIs allow for detecting the
<kbd>Shift</kbd>modifier (e.g., forShift + Entersoft newlines). - ANSI input sequences are cryptic and require complex custom parsing.
- To handle Bracketed Paste (pasting large blocks of text) without the performance hit of processing every single character as a keypress, PrettyPrompt uses
Console.KeyAvailableto detect a "full buffer" and batches them into a single paste event.