『Golang』跨平台TUI(基于文字的用户界面)库Terbox-Go文档翻译
原文 package termboximport "github.com/nsf/termbox-go"
索引
包文件api.go 变量var ( IsInit bool = false ) 查看 func CellBufferfunc CellBuffer() []Cell 返回一个 func Clearfunc Clear(fg,bg Attribute) error 清理内部后台缓存。 func Closefunc Close() 当 func Flushfunc Flush() error 与终端同步内部后台缓存。 func HideCursorfunc HideCursor() 设置 func Initfunc Init() error 初始化 示例:err := termbox.Init() if err != nil { panic(err) } defer termbox.Close() func Interruptfunc Interrupt() 通过返回一个 func SetCellfunc SetCell(x,bg Attribute) 在指定的位置改变内部后台缓存中单元格的参数。 func SetCursorfunc SetCursor(x,y int) 设置光标的位置。参见 func Sizefunc Size() (int,int) 返回内部缓存的大小(几乎与终端窗口尺寸同样大小)。但是当终端的大小被改变后,它并不总是与终端窗口的大小一致,内部后台缓存仅仅在 func Syncfunc Sync() error 当有事务引起 type Attributetype Attribute uint16 const ( ColorDefault Attribute = iota ColorBlack ColorRed ColorGreen ColorYellow ColorBlue ColorMagenta ColorCyan ColorWhite ) 单元格颜色,你可以通过使用 const ( AttrBold Attribute = 1 << (iota + 9) AttrUnderline AttrReverse ) 单元格属性,通过使用 值得一提的是,一些平台不支持某些的属性。例如Windows Console不支持下划线属性。在一些终端上,应用 type Celltype Cell struct { Ch rune Fg Attribute Bg Attribute } 一个单元格,在屏幕上的独立概念实体。屏幕是基于单元格的一个2d数组。 type Eventtype Event struct { Type EventType // one of Event* constants Mod Modifier // one of Mod* constants or 0 Key Key // one of Key* constants,invalid if 'Ch' is not 0 Ch rune // a unicode character Width int // width of the screen Height int // height of the screen Err error // error in case if input failed MouseX int // x coord of mouse MouseY int // y coord of mouse } 此类型描述一个 func PollEventfunc PollEvent() Event 等待一个事件,并返回它。这事一个阻塞方法调用。 type EventTypetype EventType uint8 const ( EventKey EventType = iota EventResize EventMouse EventError EventInterrupt ) 指示事件类型,祥见 type InputModetype InputMode int const ( InputEsc InputMode = 1 << iota InputAlt InputMouse InputCurrent InputMode = 0 ) 输入模式,详见 func SetInputModefunc SetInputMode(mode InputMode) InputMode 设置
这两个模式都可以与 如果 type Keytype Key uint16 const ( KeyF1 Key = 0xFFFF - iota KeyF2 KeyF3 KeyF4 KeyF5 KeyF6 KeyF7 KeyF8 KeyF9 KeyF10 KeyF11 KeyF12 KeyInsert KeyDelete KeyHome KeyEnd KeyPgup KeyPgdn KeyArrowUp KeyArrowDown KeyArrowLeft KeyArrowRight MouseLeft MouseMiddle MouseRight ) 键值常量,详见 const ( KeyCtrlTilde Key = 0x00 KeyCtrl2 Key = 0x00 KeyCtrlSpace Key = 0x00 KeyCtrlA Key = 0x01 KeyCtrlB Key = 0x02 KeyCtrlC Key = 0x03 KeyCtrlD Key = 0x04 KeyCtrlE Key = 0x05 KeyCtrlF Key = 0x06 KeyCtrlG Key = 0x07 KeyBackspace Key = 0x08 KeyCtrlH Key = 0x08 KeyTab Key = 0x09 KeyCtrlI Key = 0x09 KeyCtrlJ Key = 0x0A KeyCtrlK Key = 0x0B KeyCtrlL Key = 0x0C KeyEnter Key = 0x0D KeyCtrlM Key = 0x0D KeyCtrlN Key = 0x0E KeyCtrlO Key = 0x0F KeyCtrlP Key = 0x10 KeyCtrlQ Key = 0x11 KeyCtrlR Key = 0x12 KeyCtrlS Key = 0x13 KeyCtrlT Key = 0x14 KeyCtrlU Key = 0x15 KeyCtrlV Key = 0x16 KeyCtrlW Key = 0x17 KeyCtrlX Key = 0x18 KeyCtrlY Key = 0x19 KeyCtrlZ Key = 0x1A KeyEsc Key = 0x1B KeyCtrlLsqBracket Key = 0x1B KeyCtrl3 Key = 0x1B KeyCtrl4 Key = 0x1C KeyCtrlBackslash Key = 0x1C KeyCtrl5 Key = 0x1D KeyCtrlRsqBracket Key = 0x1D KeyCtrl6 Key = 0x1E KeyCtrl7 Key = 0x1F KeyCtrlSlash Key = 0x1F KeyCtrlUnderscore Key = 0x1F KeySpace Key = 0x20 KeyBackspace2 Key = 0x7F KeyCtrl8 Key = 0x7F ) type Modifiertype Modifier uint8 const ( ModAlt Modifier = 0x01 )
type OutputModetype OutputMode int const ( OutputCurrent OutputMode = iota OutputNormal Output256 Output216 OutputGrayscale ) 输出模式。详见 func SetOutputModefunc SetOutputMode(mode OutputMode) OutputMode 设置
此模式提供8个不同的颜色: 黑,红,绿,黄,蓝,品红,蓝绿色,白 快捷方式:ColorBlack,ColorRec,…… 属性:AttrBold,AttrUnderline,AttrReverse 示例: SetCell(x,y,'@',ColorBlack | AttrBold,ColorRed);
此模式你可以使用256色的终端模式: 0x00 - 0x07: 与OutputNormal一致的8个颜色 0x08 - 0x0f: Color* 或 AttrBold 0x10 - 0xe7: 216种不同的颜色 0xe8 - 0xff: 24种灰度 示例: SetCell(x,184,240); SetCell(x,0xb8,0xf0);
此种模式仅仅支持256色模式的第三种情况。但是你不需要提供偏移。
这个模式仅仅支持256色模式的第四种情况。但是你不需要提供偏移。在所有模式中 使用 如果 需要注意的是,这将会返回一个不同的 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |