"Golang" Cross-platform Tui (text-based user interface) library Terbox-go document translation

Source: Internet
Author: User
Tags setcell
This is a creation in Article, where the information may have evolved or changed.

Original

Package Termbox

import "github.com/nsf/termbox-go"

termbox-gois a library for creating cross-platform Tui (text-based user interface).

Index

    • Variables
    • Func Cellbuffer () []cell
    • Func Clear (FG, BG Attribute) error
    • Func Close ()
    • Func Flush () error
    • Func hidecursor ()
    • Func Init () error
    • Func Interrupt ()
    • Func Setcell (x, y int, ch rune, FG, BG Attribute)
    • Func setcursor (x, y int)
    • Func Size () (int, int)
    • Func Sync () error
    • Type Attribute
    • Type Cell
    • Type Event
    • Func pollevent () Event

      • Type EventType
    • Type Inputmode

      • Func setinputmode (mode Inputmode) Inputmode
    • Type Key
    • Type Modifier
    • Type Outputmode

      • Func setoutputmode (mode Outputmode) Outputmode

Package files

Api.go
Api_common.go
Syscalls_linux.go
Termbox.go
Termbox_common.go
Terminfo.go
Terminfo_builtin.go

Variable

var (    IsInit bool = false)

See termbox If it has been initialized.

Func Cellbuffer

func CellBuffer() []Cell

Returns one slice to termbox the background cache. You can use Size the method to get the size of the background cache. If you do not use or method to clean up the cache after calling the current method, the Clear Flush background cache Slice will persist.

Func Clear

func Clear(fg, bg Attribute) error

Cleans up the internal background cache.

Func Close

func Close()

termboxThis method is called to terminate the library when it has been successfully initialized and termbox the method is no longer needed termbox .

Func Flush

func Flush() error

Synchronizes the internal back-end cache with the terminal.

Func hidecursor

func HideCursor()

Sets SetCursor(-1,-1) the shortcut key.

Func Init

func Init() error

Initializes the termbox library. This method needs to be called before other methods. After a successful initialization, the library must use the Close method end.

Example:

err := termbox.Init()if err != nil {        panic(err)}defer termbox.Close()

Func Interrupt

func Interrupt()

Terminates an in-progress call by returning one EventInterrupt PollEvent . It is important to note that this method PollEvent will be blocked until the method is successfully interrupted.

Func Setcell

func SetCell(x, y int, ch rune, fg, bg Attribute)

Changes the parameters of the cells in the internal background cache at the specified location.

Func setcursor

func SetCursor(x, y int)

Sets the position of the cursor. SeeHideCursor()

Func Size

func Size() (int, int)

Returns the size of the internal cache (almost the same size as the terminal window size). However, when the size of the terminal is changed, it is not always consistent with the size of the terminal window, and the internal background cache only Clear Flush gets synchronized after the or method call.

Func Sync

func Sync() error

Synchronize immediately when there is a transaction termbox that causes the parsing of the terminal cache and the actual situation to be unsynchronized.

Type Attribute

type Attribute uint16
const (    ColorDefault Attribute = iota    ColorBlack    ColorRed    ColorGreen    ColorYellow    ColorBlue    ColorMagenta    ColorCyan    ColorWhite)

Cell color, which you can do by using bitwise or | blending multiple properties.

const (    AttrBold Attribute = 1 << (iota + 9)    AttrUnderline    AttrReverse)

Cell properties, by using bitwise or | to blend multiple properties. Although colors cannot be blended, you can mix multiple properties and a separate color.

It is worth mentioning that some of the platforms do not support certain properties. For example, Windows Console does not support underline properties. On some terminals, applying AttrBold to the background may cause the text to blink. Use them carefully, and test your code on different terminals.

Type Cell

type Cell struct {    Ch  rune    Fg  Attribute    Bg  Attribute}

A cell that is an independent conceptual entity on the screen. The screen is a 2d array based on the cell. Chis a unicode character, Fg and Bg is a foreground and background property.

Type Event

type 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}

This type describes an termbox event. Mod, Key and Ch whether the field is Type a validation of a key-value event. Widthand the Height field is the Type verification of whether the reset is reset. The Err field is a Type validation of whether the error event is false.

Func pollevent

func PollEvent() Event

Wait for an event and return it. This is a blocking method call.

Type EventType

type EventType uint8
const (    EventKey EventType = iota    EventResize    EventMouse    EventError    EventInterrupt)

Indicates the event type, see Event.Type field.

Type Inputmode

type InputMode int
const (    InputEsc InputMode = 1 << iota    InputAlt    InputMouse    InputCurrent InputMode = 0)

Input mode, see SetInputMode method.

Func Setinputmode

func SetInputMode(mode InputMode) InputMode

Sets the termbox input mode. There are two types of input modes for Termbox:

    1. EscInput mode. When ESC in a buffer sequence, and it matches any known sequence. ESCrepresents KeyEsc (Esc key value). This is the default input mode.
    2. AltInput mode. When ESC in a buffer sequence, and it matches any known sequence. ESCenables the modifier for the next keyboard event ModAlt .

Both modes can be mixed with the Mouse pattern. MouseThe settings mode enables mouse click events.

If mode Yes InputCurrent , returns the current input mode. See Input modes and Input* constants.

Type Key

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

Key-value constants, see Event.Key fields.

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 key    Ctrlh 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 KEYCT RlY 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 Keyctrlunde Rscore key = 0x1F keyspace key = 0x20 KeyBackspace2 key = 0x7F KeyCtrl8 key = 0x7F)

Type Modifier

type Modifier uint8
const (    ModAlt Modifier = 0x01)

AltModify constants, see Event.Mod fields and SetInputMode methods.

Type Outputmode

type OutputMode int
const (    OutputCurrent OutputMode = iota    OutputNormal    Output256    Output216    OutputGrayscale)

Output mode. See SetOutputMode method.

Func Setoutputmode

func SetOutputMode(mode OutputMode) OutputMode

Sets the termbox output mode. The Termbox has four output options:

    1. Outputnormal = [1..8]
此模式提供8个不同的颜色:    黑,红,绿,黄,蓝,品红,蓝绿色,白快捷方式:ColorBlack,ColorRec,……属性:AttrBold,AttrUnderline,AttrReverse示例:    SetCell(x, y, '@', ColorBlack | AttrBold, ColorRed);
    1. Output256 = [1..256]
此模式你可以使用256色的终端模式:0x00 - 0x07: 与OutputNormal一致的8个颜色0x08 - 0x0f: Color* 或 AttrBold0x10 - 0xe7: 216种不同的颜色0xe8 - 0xff: 24种灰度示例:    SetCell(x, y, '@', 184, 240);    SetCell(x, y, '@', 0xb8, 0xf0);
    1. Output216 = [1..216]

This mode only supports the third case of 256-color mode. But you don't need to provide offsets.

    1. Outputgrayscale = [1..24]

This mode only supports the fourth case of 256-color mode. But you don't need to provide offsets. Represents the default color in all modes 0 .

Use go run _demos/output.go to view it in your terminal's response.

If mode it is, OutputCurrent it returns the current output mode.

It is important to note that this will return a different OutputMode more than one request when the request pattern may not be available on the target platform.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.