Documentation
¶
Overview ¶
Package ansi 输出 ansi 控制码
windows 系统默认情况下不支持 ansi 控制码。 若仅仅是需要输出彩色字符到控制台,请使用 term/colors 包。
fmt.Printf("%v这是红色的字", term.FRed)
fmt.Printf("%v这是红色字,绿色背景", term.SGR(term.SGRFRed,term.SGRBGreen))
fmt.Printf("%v%v这是红色字,绿色背景", term.FRed,term.BGreen)
// 包装一个stderr。
w := term.NewWriter(os.Stderr)
w.Left(5)
w.SGR(term.SGRFRed)
w.Printf("%s", "string")
w.Move(1,1)
ansi 的相关文档,可参考以下内容:
https://en.wikipedia.org/wiki/ANSI_escape_code https://zh.wikipedia.org/wiki/ANSI%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97
Index ¶
- Constants
- type ESC
- func B256Color(color uint8) ESC
- func BTrueColor(r, g, b uint8) ESC
- func CHA(n int) ESC
- func CNL(n int) ESC
- func CPL(n int) ESC
- func CSI(end byte, v ...int) ESC
- func CUB(n int) ESC
- func CUD(n int) ESC
- func CUF(n int) ESC
- func CUP(x, y int) ESC
- func CUU(n int) ESC
- func DSR() ESC
- func ED(n int) ESC
- func EL(n int) ESC
- func F256Color(color uint8) ESC
- func FTrueColor(r, g, b uint8) ESC
- func RCP() ESC
- func SCP() ESC
- func SD(n int) ESC
- func SGR(args ...int) ESC
- func SU(n int) ESC
- type Writer
- func (a *Writer) B256Color(color uint8) (int, error)
- func (a *Writer) BTrueColor(r, g, b uint8) (int, error)
- func (a *Writer) Color256(f, b uint8) (int, error)
- func (a *Writer) Down(n int) (int, error)
- func (a *Writer) Erase(n int) (int, error)
- func (a *Writer) EraseLine(n int) (int, error)
- func (a *Writer) F256Color(color uint8) (int, error)
- func (a *Writer) FTrueColor(r, g, b uint8) (int, error)
- func (a *Writer) Left(n int) (int, error)
- func (a *Writer) Move(x, y int) (int, error)
- func (a *Writer) Print(args ...interface{}) (int, error)
- func (a *Writer) Printf(format string, args ...interface{}) (int, error)
- func (a *Writer) Println(args ...interface{}) (int, error)
- func (a *Writer) RestoreCursor() (int, error)
- func (a *Writer) Right(n int) (int, error)
- func (a *Writer) SGR(sgr ...int) (int, error)
- func (a *Writer) SaveCursor() (int, error)
- func (a *Writer) TrueColor(fr, fg, fb, br, bg, bb uint8) (int, error)
- func (a *Writer) Up(n int) (int, error)
- func (a *Writer) WriteESC(esc ESC) (int, error)
Constants ¶
const ResetCode = 0
ResetCode 重置所有状态的 ansi.ESC 状态码
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ESC ¶
type ESC string
ESC 表示 ansi 转码序列
func ED ¶
ED 返回清除屏幕的控制符
n == 0 时,清除从当前光标到屏幕尾的所有字符; n == 1 时,清除从当前光标到屏幕头的所有字符; n == 2 时,清除当前屏幕的所有字符; 当 n 为其它值时,将触发 panic
func EL ¶
EL 获取清除行的控制符
n == 0 时,清除从当前光标到行尾的所有字符; n == 1 时,清除从当前光标到行头的所有字符; n == 2 时,清除当前行的所有字符。 当 n 为其它值时,将触发 panic
type Writer ¶
Writer ansi 控制码的 io.Writer 接口
a := NewWriter(os.Stdout)
a.Left(5)
a.ClearLine(2)
a.SGR(term.SGRFRed,term.SGRBGreen)
a.Print("abc")
fmt.Fprintf(a, "%v", term.SGRFBBlue)
func (*Writer) BTrueColor ¶
BTrueColor 输出 24 色彩背景色
func (*Writer) Erase ¶
Erase 清除屏幕
n==0 时,清除从当前光标到屏幕尾的所有字符; n==1 时,清除从当前光标到屏幕头的所有字符; n==2 时,清除当前屏幕的所有字符; 当 n 为其它值时,将触发 panic
func (*Writer) EraseLine ¶
EraseLine 清除行
n==0 时,清除从当前光标到行尾的所有字符; n==1 时,清除从当前光标到行头的所有字符; n==2 时,清除当前行的所有字符; 当 n 为其它值时,将触发 panic
func (*Writer) FTrueColor ¶
FTrueColor 输出 24 色彩前景色