Cross-platform .NET Standard 2.0 library for working with terminals.
dotnet add package ANSITerm
- 8, 16, 256-color and true color modes
- Automatic conversion between colors (nearest RGB)
- Uses ANSI sequences if supported
- Supports alternative buffer via
tput, emulated on Windows cmd
- Platform-independent cursor positioning as defined by ANSI
- Interface is close to
System.Console, things that don't work on all supported platforms were removed
Currently there are two backends -
ANSIBackend. First one mostly wraps corefx Console class, second one uses ANSI sequences.
Supported terminals (no configuration):
- Windows CMD (std) - has maximum of 16 colors
- ConEmu (ANSI) - true color support is assumed
- mintty (ANSI) - true color support is assumed
Working terminals needing configuration:
- MobaXTerm -
$ROWSenvironment variables must be set, also
stty -echo -icanon min 1 time 0should be run prior to launching (use
stty saneto restore terminal settings).
ANSI backend is used if any of these variables is set:
CONEMUANSI=ON(set by ConEmu)
MSYSCON(set by MSYS2, should contain path to mintty)
TERM(set by MobaXTerm)
Linux and OS X
ANSI backend is used. Information about color count, keys and other stuff is grabbed from terminfo using corefx TermInfo.
using ANSITerm; // ... var term = ANSIConsole.GetInstance(); term.SetFullscreen(true); term.SetCursorPosition(10, 10); term.ForegroundColor = new ColorValue(Color.Lime); term.WriteLine("Hello, world! Press ENTER to exit."); term.ReadLine();
Can I replace ncurses with it?
Well, no. It's closer to Python colorama library, but has some additional features. This project is aimed to be a simple and lightweight, and to contain only core functions that should work on all major platforms.