Skip to content

RaZeR-RBI/ansiterm-net

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

ANSITerm

Cross-platform .NET Standard 2.0 library for working with terminals.

API Documentation

Installation

dotnet add package ANSITerm

Features

  • 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

Details

Currently there are two backends - StdBackend and ANSIBackend. First one mostly wraps corefx Console class, second one uses ANSI sequences.

Windows

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 - $LINES and $ROWS environment variables must be set, also stty -echo -icanon min 1 time 0 should be run prior to launching (use stty sane to 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.

Example

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.

About

Cross-platform .NET Standard 2.0 colored terminal library

Resources

License

Stars

Watchers

Forks

Packages

No packages published