muesli/termenv là dự án Backend trên GitHub, viết chủ yếu bằng Go, với 2.0k sao. Advanced ANSI style & color support for your terminal applications
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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
Usage
output := termenv.NewOutput(os.Stdout)
termenv queries the terminal's capabilities it is running in, so you can
safely use advanced features, like RGB colors or ANSI styles. output.Profile
returns the supported profile:
termenv.Ascii - no ANSI support detected, ASCII only
termenv.ANSI - 16 color ANSI support
termenv.ANSI256 - Extended 256 color ANSI support
termenv.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 := output.ForegroundColor()
// Returns terminal's background color
color := output.BackgroundColor()
// Returns whether terminal uses a dark-ish background
darkTheme := output.HasDarkBackground()
Manual Profile Selection
If you don't want to rely on the automatic detection, you can manually select
the profile you want to use:
termenv supports multiple color profiles: Ascii (black & white only),
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:
s := output.String("Hello World")
// Supports hex values
// Will automatically degrade colors on terminals not supporting RGB
s.Foreground(output.Color("#abcdef"))
// but also supports ANSI colors (0-255)
s.Background(output.Color("69"))
// ...or the color.Color interface
s.Foreground(output.FromColor(color.RGBA{255, 128, 0, 255}))
// Combine fore- & background colors
s.Foreground(output.Color("#ffffff")).Background(output.Color("#0000ff"))
// Supports the fmt.Stringer interface
fmt.Println(s)
Styles
You can use a chainable syntax to compose your own styles:
s := output.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
termenv provides a set of helper functions to style your Go templates:
// load template helpers
f := output.TemplateFuncs()
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
output.MoveCursor(row, column)
// Save the cursor position
output.SaveCursorPosition()
// Restore a saved cursor position
output.RestoreCursorPosition()
// Move the cursor up a given number of lines
output.CursorUp(n)
// Move the cursor down a given number of lines
output.CursorDown(n)
// Move the cursor up a given number of lines
output.CursorForward(n)
// Move the cursor backwards a given number of cells
output.CursorBack(n)
// Move the cursor down a given number of lines and place it at the beginning
// of the line
output.CursorNextLine(n)
// Move the cursor up a given number of lines and place it at the beginning of
// the line
output.CursorPrevLine(n)
Screen
// Reset the terminal to its default style, removing any active styles
output.Reset()
// RestoreScreen restores a previously saved screen state
output.RestoreScreen()
// SaveScreen saves the screen state
output.SaveScreen()
// Switch to the altscreen. The former view can be restored with ExitAltScreen()
output.AltScreen()
// Exit the altscreen and return to the former terminal view
output.ExitAltScreen()
// Clear the visible portion of the terminal
output.ClearScreen()
// Clear the current line
output.ClearLine()
// Clear a given number of lines
output.ClearLines(n)
// Set the scrolling region of the terminal
output.ChangeScrollingRegion(top, bottom)
// Insert the given number of lines at the top of the scrollable region, pushing
// lines below down
output.InsertLines(n)
// Delete the given number of lines, pulling any lines in the scrollable region
// below up
output.DeleteLines(n)
Session
// SetWindowTitle sets the terminal window title
output.SetWindowTitle(title)
// SetForegroundColor sets the default foreground color
output.SetForegroundColor(color)
// SetBackgroundColor sets the default background color
output.SetBackgroundColor(color)
// SetCursorColor sets the cursor color
output.SetCursorColor(color)
// Hide the cursor
output.HideCursor()
// Show the cursor
output.ShowCursor()
// Copy to clipboard
output.Copy(message)
// Copy to primary clipboard (X11)
output.CopyPrimary(message)
// Trigger notification
output.Notify(title, body)
You can help improve this list! Check out how to and open an issue or pull request.
System Commands
Click to show feature matrix
Terminal
Copy to Clipboard (OSC52)
Hyperlinks (OSC8)
Notifications (OSC777)
alacritty
✅
✅3
❌
foot
✅
✅
✅
kitty
✅
✅
✅
Konsole
❌4
✅
❌
rxvt
❌
❌
❌
urxvt
✅5
❌
✅
screen
✅
❌6
❌
st
✅
❌
❌
tmux
✅
❌7
❌
vte-based2
❌2
✅
❌
wezterm
✅
✅
❌
xterm
✅
❌
❌
Linux Console
⛔
⛔
❌
Apple Terminal
✅8
❌
❌
iTerm
✅
✅
❌
Windows cmd
❌
❌
❌
Windows Terminal
✅
✅
❌
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:
muesli/termenv thuộc nhóm Backend trên TopGit, cùng 7 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về muesli/termenv ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/muesli/termenv là nguồn chính thức.
muesli/termenv có bao nhiêu sao?
muesli/termenv có 2.0k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/muesli/termenv. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
muesli/termenv có phải mã nguồn mở không?
Có — muesli/termenv phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/muesli/termenv.
muesli/termenv còn đang phát triển không?
Commit gần nhất trên muesli/termenv là 9 tháng trước (theo timestamp GitHub). Repo có 92 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
muesli/termenv dùng license gì?
muesli/termenv phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
muesli/termenv là gì?
muesli/termenv (muesli/termenv) là dự án Go trên GitHub. Theo mô tả gốc: Advanced ANSI style & color support for your terminal applications
muesli/termenv viết bằng ngôn ngữ gì?
muesli/termenv chủ yếu viết bằng Go. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về termenv?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về termenv.