termenv alternatives and similar packages
Based on the "Advanced Console UIs" category.
Alternatively, view termenv alternatives based on common mentions on social networks and blogs.
-
Rich Interactive Widgets for Terminal UIs
Terminal UI library with rich, interactive widgets โย written in Golang -
go-prompt
Building powerful interactive prompts in Go, inspired by python-prompt-toolkit. -
tcell
Tcell is an alternate terminal package, similar in some ways to termbox, but better in others. -
pterm
โจ #PTerm is a modern Go module to beautify console output. Featuring charts, progressbars, tables, trees, and much more ๐ It's completely configurable and 100% cross-platform compatible. -
progressbar
A really basic thread-safe progress bar for Golang applications -
uiprogress
A go library to render progress bars in terminal applications -
asciigraph
Go package to make lightweight ASCII line graph โญโโฏ in command line apps with no other dependencies. -
uitable
A go library to improve readability in terminal apps using tabular data -
termtables
A Go port of the Ruby library terminal-tables for simple ASCII table generation as well as providing markdown and HTML output -
chalk
Intuitive package for prettifying terminal/console output. http://godoc.org/github.com/ttacon/chalk -
yacspin
Yet Another CLi Spinner; providing over 80 easy to use and customizable terminal spinners for multiple OSes -
tabular
Tabular simplifies printing ASCII tables from command line utilities -
GCli
๐ฅ Go CLI application, tool library, running CLI commands, support console color, user interaction, progress display, data formatting display, generate bash/zsh completion add more features. Go็ๅฝไปค่กๅบ็จ๏ผๅทฅๅ ทๅบ๏ผ่ฟ่กCLIๅฝไปค๏ผๆฏๆๅฝไปค่ก่ฒๅฝฉ๏ผ็จๆทไบคไบ๏ผ่ฟๅบฆๆพ็คบ๏ผๆฐๆฎๆ ผๅผๅๆพ็คบ๏ผ็ๆbash/zshๅฝไปค่กฅๅ จ่ๆฌ -
marker
๐๏ธ Marker is the easiest way to match and mark strings for colorful terminal outputs! -
ctc
Console Text Colors - The non-invasive cross-platform terminal color library does not need to modify the Print method
Less time debugging, more time building
Do you think we are missing an alternative of termenv or a related project?
Popular Comparisons
README
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.
Features
- RGB/TrueColor support
- Detects the supported color range of your terminal
- Automatically converts colors to the best matching, available colors
- Terminal theme (light/dark) detection
- Chainable syntax
- Nested styles
Installation
go get github.com/muesli/termenv
Query Terminal Support
termenv
can query the terminal it is running in, so you can safely use
advanced features, like RGB colors. ColorProfile
returns the color profile
supported by the terminal:
profile := termenv.ColorProfile()
This returns one of the supported color profiles:
termenv.Ascii
- no ANSI support detected, ASCII onlytermenv.ANSI
- 16 color ANSI supporttermenv.ANSI256
- Extended 256 color ANSI supporttermenv.TrueColor
- RGB/TrueColor support
Alternatively, you can use termenv.EnvColorProfile
which evaluates the
terminal like ColorProfile
, but also respects the NO_COLOR
and
CLICOLOR_FORCE
environment variables.
You can also query the terminal for its color scheme, so you know whether your app is running in a light- or dark-themed environment:
// Returns terminal's foreground color
color := termenv.ForegroundColor()
// Returns terminal's background color
color := termenv.BackgroundColor()
// Returns whether terminal uses a dark-ish background
darkTheme := 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
s := 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
s.Foreground(p.Color("#abcdef"))
// but also supports ANSI colors (0-255)
s.Background(p.Color("69"))
// ...or the color.Color interface
s.Foreground(p.FromColor(color.RGBA{255, 128, 0, 255}))
// Combine fore- & background colors
s.Foreground(p.Color("#ffffff")).Background(p.Color("#0000ff"))
// Supports the fmt.Stringer interface
fmt.Println(s)
Styles
You can use a chainable syntax to compose your own styles:
s := termenv.String("foobar")
// Text styles
s.Bold()
s.Faint()
s.Italic()
s.CrossOut()
s.Underline()
s.Overline()
// Reverse swaps current fore- & background colors
s.Reverse()
// Blinking text
s.Blink()
// Combine multiple options
s.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
.
Positioning
// Move the cursor to a given position
termenv.MoveCursor(row, column)
// Save the cursor position
termenv.SaveCursorPosition()
// Restore a saved cursor position
termenv.RestoreCursorPosition()
// 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 up a given number of lines
termenv.CursorForward(n)
// Move the cursor backwards a given number of cells
termenv.CursorBack(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)
Screen
// Reset the terminal to its default style, removing any active styles
termenv.Reset()
// RestoreScreen restores a previously saved screen state
termenv.RestoreScreen()
// SaveScreen saves the screen state
termenv.SaveScreen()
// 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()
// Clear the current line
termenv.ClearLine()
// Clear a given number of lines
termenv.ClearLines(n)
// Set the scrolling region of the terminal
termenv.ChangeScrollingRegion(top, bottom)
// Insert the given number of lines at the top of the scrollable region, pushing
// lines below down
termenv.InsertLines(n)
// Delete the given number of lines, pulling any lines in the scrollable region
// below up
termenv.DeleteLines(n)
Session
// SetWindowTitle sets the terminal window title
termenv.SetWindowTitle(title)
// SetForegroundColor sets the default foreground color
termenv.SetForegroundColor(color)
// SetBackgroundColor sets the default background color
termenv.SetBackgroundColor(color)
// SetCursorColor sets the cursor color
termenv.SetCursorColor(color)
// Hide the cursor
termenv.HideCursor()
// Show the cursor
termenv.ShowCursor()
Mouse
// Enable X10 mouse mode, only button press events are sent
termenv.EnableMousePress()
// Disable X10 mouse mode
termenv.DisableMousePress()
// Enable Mouse Tracking mode
termenv.EnableMouse()
// Disable Mouse Tracking mode
termenv.DisableMouse()
// Enable Hilite Mouse Tracking mode
termenv.EnableMouseHilite()
// Disable Hilite Mouse Tracking mode
termenv.DisableMouseHilite()
// Enable Cell Motion Mouse Tracking mode
termenv.EnableMouseCellMotion()
// Disable Cell Motion Mouse Tracking mode
termenv.DisableMouseCellMotion()
// Enable All Motion Mouse mode
termenv.EnableMouseAllMotion()
// Disable All Motion Mouse mode
termenv.DisableMouseAllMotion()
Optional Feature Support
Terminal | Alt Screen | Query Color Scheme | Query Cursor Position | Set Window Title | Change Cursor Color | Change Default Foreground Setting | Change Default Background Setting |
---|---|---|---|---|---|---|---|
alacritty | โ | โ | โ | โ | โ | โ | โ |
foot | โ | โ | โ | โ | โ | โ | โ |
kitty | โ | โ | โ | โ | โ | โ | โ |
Konsole | โ | โ | โ | โ | โ | โ | โ |
rxvt | โ | โ | โ | โ | โ | โ | โ |
screen | โ | โ1 | โ | โ | โ | โ | โ |
st | โ | โ | โ | โ | โ | โ | โ |
tmux | โ | โ1 | โ | โ | โ | โ | โ |
vte-based2 | โ | โ | โ | โ | โ | โ | โ |
wezterm | โ | โ | โ | โ | โ | โ | โ |
xterm | โ | โ | โ | โ | โ | โ | โ |
Linux Console | โ | โ | โ | โ | โ | โ | โ |
Apple Terminal | โ | โ | โ | โ | โ | โ | โ |
iTerm | โ | โ | โ | โ | โ | โ | โ |
Windows cmd | โ | โ | โ | โ | โ | โ | โ |
Windows Terminal | โ | โ | โ | โ | โ | โ | โ |
You can help improve this list! Check out [how to](ansi_compat.md) and open an issue or pull request.
Color Support
- 24-bit (RGB): alacritty, foot, iTerm, kitty, Konsole, st, tmux, vte-based, wezterm, Windows Terminal
- 8-bit (256): rxvt, screen, xterm, Apple Terminal
- 4-bit (16): Linux Console
Platform Support
termenv
works on Unix systems (like Linux, macOS, or BSD) and Windows. While
terminal applications on Unix support ANSI styling out-of-the-box, on Windows
you need to enable ANSI processing in your application first:
mode, err := termenv.EnableWindowsANSIConsole()
if err != nil {
panic(err)
}
defer termenv.RestoreWindowsConsole(mode)
Color Chart
You can find the source code used to create this chart in termenv
's examples.
Related Projects
- reflow - ANSI-aware text operations
- Lip Gloss - style definitions for nice terminal layouts ๐
- ansi - ANSI sequence helpers
termenv in the Wild
Need some inspiration or just want to see how others are using termenv
? Check
out these projects:
- Bubble Tea - a powerful little TUI framework ๐
- Glamour - stylesheet-based markdown rendering for your CLI apps ๐๐ปโโ๏ธ
- Glow - a markdown renderer for the command-line ๐ ๐ป
- duf - Disk Usage/Free Utility - a better 'df' alternative
- gitty - contextual information about your git projects
- slides - terminal-based presentation tool
Feedback
Got some feedback or suggestions? Please open an issue or drop me a note!
License
*Note that all licence references and agreements mentioned in the termenv README section above
are relevant to that project's source code only.