Categorygithub.com/halimath/terminal
modulepackage
0.0.0-20240104140753-89b28be769de
Repository: https://github.com/halimath/terminal.git
Documentation: pkg.go.dev

# README

termx

ANSI terminal support for Go(lang)

CI Status Package Doc Releases

terminal provides a go module to access ANSI features of a (pseudo) terminal. The module provides packages that support

  • colored output
  • raw input handling
  • application mode
  • alternative screen buffers
  • mouse support

All features are implemented to support xterm compatible terminals (no terminfo parsing is done). In addition compatible features are tested to work on windows as well (if supported).

Installation

terminal can be installed as a Go module

go get github.com/halimath/terminal

Usage

The terminal package provides a type Terminal which provides methods to deal with the terminal. The Terminal type provides methods to

  • enter and exit raw mode
  • read and write strings, raw bytes as well as control sequences
  • read input.Events which decode byte sequences into key presses and mouse events

This module provides a package csi which contains Control Sequence Introducer definitions that enable advanced terminal output operations, such as

  • moving the cursor
  • clearing (parts of) the screen
  • setting the terminal's window title
  • querying terminal information (i.e. cursor position, background color)

This module provides a package sgr, which contains definitions for Select Graphic Rendition which allows applications to format colored text or otherwise styled text output.

See the examples directory for small applications demonstrating how to use this module.

Useful resources

A lot of information about the escape sequences and their treatment by different terminal applications has been gathered from the following resources which i highly recommend to anyone interested in the internals of terminal:

License

Copyright 2023 Alexander Metzner.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

# Packages

Package csi contains constants and functions to produce _control sequence introducer_ strings that instruct a terminal to perform special operations, i.e.
No description provided by the author
No description provided by the author
Package rawmode provides a minimal set of functions to enter and exit raw input mode.
Package sgr contains definitions for _select graphic rendition_ instructions that, when applied to some string, instruct the terminal emulator to select different colors, fonts, decorations, ..

# Functions

TruecolorSupported returns whether the environment this process runs in supports truecolor.
New creates a new Terminal using os.Stdin for input and os.Stdout for output.
NewWithFile creates and initializes a new terminal using r and w as reader and write.

# Variables

ErrRawMode is a sentinel error value returned from New or NewWithFD in case switching the terminal to raw mode failed.

# Structs

Terminal implements both read and write access to the terminal.