term

package
v0.0.0-...-1781da9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2014 License: MIT Imports: 3 Imported by: 2

Documentation

Overview

输出ansi控制码,不支持windows系统

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的相关文档,可参考以下内容:

http://en.wikipedia.org/wiki/ANSI_escape_code
http://www.mudpedia.org/mediawiki/index.php/ANSI_colors

Index

Constants

View Source
const (
	Reset           = "\033[0m"
	Bold            = "\033[1m"
	Underline       = "\033[4m"
	Blink           = "\033[5m" // 闪烁
	ReverseVideo    = "\033[7m" // 反显
	Conceal         = "\033[8m"
	BoldOff         = "\033[22m"
	UnderlineOff    = "\033[24m"
	BlinkOff        = "\033[25m"
	ReverseVideoOff = "\033[27m"
	ConcealOff      = "\033[28m"

	FBlack   = "\033[30m"
	FRed     = "\033[31m"
	FGreen   = "\033[32m"
	FYellow  = "\033[33m"
	FBlue    = "\033[34m"
	FMagenta = "\033[35m"
	FCyan    = "\033[36m"
	FWhite   = "\033[37m"
	FDefault = "\033[39m" // 默认前景色

	BBlack   = "\033[40m"
	BRed     = "\033[41m"
	BGreen   = "\033[42m"
	BYellow  = "\033[43m"
	BBlue    = "\033[44m"
	BMagenta = "\033[45m"
	BCyan    = "\033[46m"
	BWhite   = "\033[47m"
	BDefault = "\033[49m" // 默认背景色

	SaveCursor    = "\033[s"    // 保存光标位置
	RestoreCursor = "\033[u"    // 恢复光标位置
	HideCursor    = "\033[?25l" // 隐藏光标
	ShowCursor    = "\033[?25h" // 显示光标
)
View Source
const (
	SGRReset           = "0"
	SGRBold            = "1"
	SGRUnderline       = "4"
	SGRBlink           = "5" // 闪烁
	SGRReverseVideo    = "7" // 反显
	SGRConceal         = "8"
	SGRBoldOff         = "22"
	SGRUnderlineOff    = "24"
	SGRBlinkOff        = "25"
	SGRReverseVideoOff = "27"
	SGRConcealOff      = "28"

	SGRFBlack   = "30"
	SGRFRed     = "31"
	SGRFGreen   = "32"
	SGRFYellow  = "33"
	SGRFBlue    = "34"
	SGRFMagenta = "35"
	SGRFCyan    = "36"
	SGRFWhite   = "37"
	SGRFDefault = "39" // 默认前景色

	SGRBBlack   = "40"
	SGRBRed     = "41"
	SGRBGreen   = "42"
	SGRBYellow  = "43"
	SGRBBlue    = "44"
	SGRBMagenta = "45"
	SGRBCyan    = "46"
	SGRBWhite   = "47"
	SGRBDefault = "49" // 默认背景色
)
View Source
const Version = "1.1.4.141013"

当前库的版本

Variables

This section is empty.

Functions

func BColor256

func BColor256(color int) string

获取扩展的背景颜色值控制码,当color的值超出[0,255]时,将触发panic

func Down

func Down(n int) string

返回下移N行的控制符

func Erase

func Erase(n int) string

返回清除屏幕的控制符。 n为0时,清除从当前光标到屏幕尾的所有字符; n为1时,清除从当前光标到屏幕头的所有字符; n为2时,清除当前屏幕的所有字符。 当n为其它值时,将触发panic

func EraseLine

func EraseLine(n int) string

返回清除行的控制符。 n为0时,清除从当前光标到行尾的所有字符; n为1时,清除从当前光标到行头的所有字符; n为2时,清除当前行的所有字符。 当n为其它值时,将触发panic

func FColor256

func FColor256(color int) string

获取扩展的文本颜色值控制码,当color的值超出[0,255]时,将触发panic

func Left

func Left(n int) string

返回左移N个字符的控制符

func Move

func Move(x, y int) string

移动光标到x,y的位置

func Right(n int) string

返回右移N个字符的控制符

func SGR

func SGR(args ...string) string

将几个SGR控制符合成一个ansi控制符

"30", "31", "32"
// 以上参数将会被转换成以下内容返回
"\033[30;31;32m"

func Up

func Up(n int) string

返回上移N行的控制符

Types

type AnsiWriter

type AnsiWriter struct {
	// contains filtered or unexported fields
}

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 NewWriter

func NewWriter(w io.Writer) *AnsiWriter

func (*AnsiWriter) BColor256

func (a *AnsiWriter) BColor256(color int) (int, error)

func (*AnsiWriter) Color256

func (a *AnsiWriter) Color256(f, b int) (int, error)

func (*AnsiWriter) Down

func (a *AnsiWriter) Down(n int) (int, error)

下移n行光标

func (*AnsiWriter) Erase

func (a *AnsiWriter) Erase(n int) (int, error)

清除屏幕。 n为0时,清除从当前光标到屏幕尾的所有字符; n为1时,清除从当前光标到屏幕头的所有字符; n为2时,清除当前屏幕的所有字符。 当n为其它值时,将触发panic

func (*AnsiWriter) EraseLine

func (a *AnsiWriter) EraseLine(n int) (int, error)

清除行。 n为0时,清除从当前光标到行尾的所有字符; n为1时,清除从当前光标到行头的所有字符; n为2时,清除当前行的所有字符。 当n为其它值时,将触发panic

func (*AnsiWriter) FColor256

func (a *AnsiWriter) FColor256(color int) (int, error)

func (*AnsiWriter) HideCursor

func (a *AnsiWriter) HideCursor() (int, error)

func (*AnsiWriter) Left

func (a *AnsiWriter) Left(n int) (int, error)

左移n个字符光标

func (*AnsiWriter) Move

func (a *AnsiWriter) Move(x, y int) (int, error)

移动光标到x,y的位置

func (*AnsiWriter) Print

func (a *AnsiWriter) Print(args ...interface{}) (int, error)

func (*AnsiWriter) Printf

func (a *AnsiWriter) Printf(format string, args ...interface{}) (int, error)

func (*AnsiWriter) Println

func (a *AnsiWriter) Println(args ...interface{}) (int, error)

func (*AnsiWriter) RestoreCursor

func (a *AnsiWriter) RestoreCursor() (int, error)

func (*AnsiWriter) Right

func (a *AnsiWriter) Right(n int) (int, error)

右移n个字符光标

func (*AnsiWriter) SGR

func (a *AnsiWriter) SGR(sgr ...string) (int, error)

func (*AnsiWriter) SaveCursor

func (a *AnsiWriter) SaveCursor() (int, error)

func (*AnsiWriter) ShowCursor

func (a *AnsiWriter) ShowCursor() (int, error)

func (*AnsiWriter) Up

func (a *AnsiWriter) Up(n int) (int, error)

上移n行光标

func (*AnsiWriter) Write

func (a *AnsiWriter) Write(b []byte) (int, error)

implements io.Writer

func (*AnsiWriter) WriteString

func (a *AnsiWriter) WriteString(str string) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL