tea/vendor/github.com/muesli/termenv
6543 d5058b3b20 Update Vendors (#250)
update go min version

Update Vendors:
 * code.gitea.io/gitea-vet v0.2.0 -> v0.2.1
 * code.gitea.io/sdk/gitea v0.13.0 -> v0.13.1
 * github.com/AlecAivazis/survey v2.1.1 -> v2.2.2
 * github.com/adrg/xdg v0.2.1 -> v0.2.2
 * github.com/araddon/dateparse d820a6159ab1 -> 8aadafed4dc4
 * github.com/go-git/go-git v5.1.0 -> v5.2.0
 * github.com/muesli/termenv v0.7.2 -> v0.7.4
 * github.com/stretchr/testify v1.5.1 -> v1.6.1
 * github.com/urfave/cli v2.2.0 -> v2.3.0

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/tea/pulls/250
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: mrsdizzie <info@mrsdizzie.com>
Co-Authored-By: 6543 <6543@noreply.gitea.io>
Co-Committed-By: 6543 <6543@noreply.gitea.io>
2020-11-09 23:25:54 +08:00
..
.gitignore Use glamour and termev to render/colorize content (#181) 2020-09-19 16:00:50 +00:00
.golangci.yml Update Vendors (#250) 2020-11-09 23:25:54 +08:00
LICENSE Use glamour and termev to render/colorize content (#181) 2020-09-19 16:00:50 +00:00
README.md Use glamour and termev to render/colorize content (#181) 2020-09-19 16:00:50 +00:00
ansicolors.go Use glamour and termev to render/colorize content (#181) 2020-09-19 16:00:50 +00:00
color.go Use glamour and termev to render/colorize content (#181) 2020-09-19 16:00:50 +00:00
constants_linux.go Use glamour and termev to render/colorize content (#181) 2020-09-19 16:00:50 +00:00
constants_solaris.go Update Vendors (#250) 2020-11-09 23:25:54 +08:00
constants_unix.go Update Vendors (#250) 2020-11-09 23:25:54 +08:00
go.mod Update Vendors (#250) 2020-11-09 23:25:54 +08:00
go.sum Update Vendors (#250) 2020-11-09 23:25:54 +08:00
screen.go Use glamour and termev to render/colorize content (#181) 2020-09-19 16:00:50 +00:00
style.go Use glamour and termev to render/colorize content (#181) 2020-09-19 16:00:50 +00:00
templatehelper.go Use glamour and termev to render/colorize content (#181) 2020-09-19 16:00:50 +00:00
termenv.go Use glamour and termev to render/colorize content (#181) 2020-09-19 16:00:50 +00:00
termenv_unix.go Update Vendors (#250) 2020-11-09 23:25:54 +08:00
termenv_windows.go Use glamour and termev to render/colorize content (#181) 2020-09-19 16:00:50 +00:00

README.md

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"))

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 = 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.

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

License

MIT