All Projects → muesli → Termenv

muesli / Termenv

Licence: mit
Advanced ANSI style & color support for your terminal applications

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Termenv

Colorful
Terminal string styling done right, in Python 🐍 🎉
Stars: ✭ 456 (-17.84%)
Mutual labels:  terminal, console, ansi, colors
Colorette
Easily set the color and style of text in the terminal.
Stars: ✭ 1,047 (+88.65%)
Mutual labels:  terminal, console, ansi, colors
Termcolor
Termcolor is a header-only C++ library for printing colored messages to the terminal. Written just for fun with a help of the Force.
Stars: ✭ 533 (-3.96%)
Mutual labels:  terminal, console, colors
S Tui
Terminal-based CPU stress and monitoring utility
Stars: ✭ 2,825 (+409.01%)
Mutual labels:  terminal, console, tui
Finalcut
A text-based widget toolkit
Stars: ✭ 244 (-56.04%)
Mutual labels:  terminal, console, tui
Pulsemixer
CLI and curses mixer for PulseAudio
Stars: ✭ 441 (-20.54%)
Mutual labels:  terminal, console, tui
Smenu
smenu started as a lightweight and flexible terminal menu generator, but quickly evolved into a powerful and versatile CLI selection tool for interactive or scripting use.
Stars: ✭ 1,906 (+243.42%)
Mutual labels:  terminal, console, tui
Jquery.terminal
jQuery Terminal Emulator - JavaScript library for creating web-based terminals with custom commands
Stars: ✭ 2,623 (+372.61%)
Mutual labels:  terminal, console, tui
log-utils
Basic logging utils: colors, symbols and timestamp.
Stars: ✭ 24 (-95.68%)
Mutual labels:  console, colors, ansi
pytermgui
Python TUI framework with mouse support, modular widget system, customizable and rapid terminal markup language and more!
Stars: ✭ 1,270 (+128.83%)
Mutual labels:  console, ansi, tui
concolor
Colouring template strings using tags with annotations 🎨
Stars: ✭ 35 (-93.69%)
Mutual labels:  console, colors, ansi
Kubebox
⎈❏ Terminal and Web console for Kubernetes
Stars: ✭ 1,855 (+234.23%)
Mutual labels:  terminal, console, tui
Lazyhub
lazyhub - Terminal UI Client for GitHub using gocui.
Stars: ✭ 133 (-76.04%)
Mutual labels:  terminal, console, tui
Mandown
man-page inspired Markdown viewer
Stars: ✭ 173 (-68.83%)
Mutual labels:  terminal, console, tui
Nnn
n³ The unorthodox terminal file manager
Stars: ✭ 13,138 (+2267.21%)
Mutual labels:  terminal, console, tui
Phetch
🐭 quick lil gopher client for your terminal
Stars: ✭ 108 (-80.54%)
Mutual labels:  terminal, console, tui
Stig
TUI and CLI for the BitTorrent client Transmission
Stars: ✭ 360 (-35.14%)
Mutual labels:  terminal, console, tui
Zui
⬢ Zsh User Interface library – CGI+DHTML-like rapid application development with Zsh
Stars: ✭ 95 (-82.88%)
Mutual labels:  terminal, console, tui
Dte
A small, configurable console text editor (moved to https://gitlab.com/craigbarnes/dte)
Stars: ✭ 98 (-82.34%)
Mutual labels:  terminal, console, tui
leeks.js
Simple ANSI styling for your terminal
Stars: ✭ 12 (-97.84%)
Mutual labels:  console, colors, ansi

termenv Logo
Latest Release GoDoc Build Status Coverage Status Go ReportCard

termenv lets you safely use advanced styling options on the terminal. It gathers information about the terminal environment in terms of its ANSI & color support and offers you convenient methods to colorize and style your output, without you having to deal with all kinds of weird ANSI escape sequences and color conversions.

Example output

Installation

go get github.com/muesli/termenv

Query Terminal Status

// returns supported color profile: Ascii, ANSI, ANSI256, or TrueColor
termenv.ColorProfile()

// returns default foreground color
termenv.ForegroundColor()

// returns default background color
termenv.BackgroundColor()

// returns whether terminal uses a dark-ish background
termenv.HasDarkBackground()

Colors

termenv supports multiple color profiles: ANSI (16 colors), ANSI Extended (256 colors), and TrueColor (24-bit RGB). Colors will automatically be degraded to the best matching available color in the desired profile:

TrueColor => ANSI 256 Colors => ANSI 16 Colors => Ascii

out := termenv.String("Hello World")

// retrieve color profile supported by terminal
p := termenv.ColorProfile()

// supports hex values
// will automatically degrade colors on terminals not supporting RGB
out = out.Foreground(p.Color("#abcdef"))
// but also supports ANSI colors (0-255)
out = out.Background(p.Color("69"))
// ...or the color.Color interface
out = out.Foreground(p.FromColor(color.RGBA{255, 128, 0, 255}))

fmt.Println(out)

Styles

out := termenv.String("foobar")

// text styles
out.Bold()
out.Faint()
out.Italic()
out.CrossOut()
out.Underline()
out.Overline()

// reverse swaps current fore- & background colors
out.Reverse()

// blinking text
out.Blink()

// combine multiple options
out.Bold().Underline()

Template Helpers

// load template helpers
f := termenv.TemplateFuncs(termenv.ColorProfile())
tpl := template.New("tpl").Funcs(f)

// apply bold style in a template
bold := `{{ Bold "Hello World" }}`

// examples for colorized templates
col := `{{ Color "#ff0000" "#0000ff" "Red on Blue" }}`
fg := `{{ Foreground "#ff0000" "Red Foreground" }}`
bg := `{{ Background "#0000ff" "Blue Background" }}`

// wrap styles
wrap := `{{ Bold (Underline "Hello World") }}`

// parse and render
tpl, err = tpl.Parse(bold)

var buf bytes.Buffer
tpl.Execute(&buf, nil)
fmt.Println(&buf)

Other available helper functions are: Faint, Italic, CrossOut, Underline, Overline, Reverse, and Blink.

Screen

// Reset the terminal to its default style, removing any active styles
termenv.Reset()

// Switch to the altscreen. The former view can be restored with ExitAltScreen()
termenv.AltScreen()

// Exit the altscreen and return to the former terminal view
termenv.ExitAltScreen()

// Clear the visible portion of the terminal
termenv.ClearScreen()

// Move the cursor to a given position
termenv.MoveCursor(row, column)

// Hide the cursor
termenv.HideCursor()

// Show the cursor
termenv.ShowCursor()

// Move the cursor up a given number of lines
termenv.CursorUp(n)

// Move the cursor down a given number of lines
termenv.CursorDown(n)

// Move the cursor down a given number of lines and place it at the beginning
// of the line
termenv.CursorNextLine(n)

// Move the cursor up a given number of lines and place it at the beginning of
// the line
termenv.CursorPrevLine(n)

// Clear the current line
termenv.ClearLine()

// Clear a given number of lines
termenv.ClearLines(n)

Color Chart

ANSI color chart

You can find the source code used to create this chart in termenv's examples.

Related Projects

Check out Glow, a markdown renderer for the command-line, which uses termenv.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].