Documentation ¶
Overview ¶
Package goncurses is a new curses (ncurses) library for the Go programming language. It implements all the ncurses extension libraries: form, menu and panel.
Minimal operation would consist of initializing the display:
src, err := goncurses.Init() if err != nil { log.Fatal("init:", err) } defer goncurses.End()
It is important to always call End() before your program exits. If you fail to do so, the terminal will not perform properly and will either need to be reset or restarted completely.
CAUTION: Calls to ncurses functions are normally not atomic nor reentrant and therefore extreme care should be taken to ensure ncurses functions are not called concurrently. Specifically, never write data to the same window concurrently nor accept input and send output to the same window as both alter the underlying C data structures in a non safe manner.
Ideally, you should structure your program to ensure all ncurses related calls happen in a single goroutine. This is probably most easily achieved via channels and Go's built-in select. Alternatively, or additionally, you can use a mutex to protect any calls in multiple goroutines from happening concurrently. Failure to do so will result in unpredictable and undefined behaviour in your program.
The examples directory contains demontrations of many of the capabilities goncurses can provide.
Index ¶
- Constants
- Variables
- func BaudRate() int
- func Beep()
- func CBreak(on bool)
- func CanChangeColor() bool
- func ColorContent(col int16) (int16, int16, int16)
- func CursesVersion() string
- func Cursor(vis byte) error
- func Echo(on bool)
- func End()
- func Flash()
- func FlushInput() error
- func HalfDelay(delay int) error
- func HasColors() bool
- func HasInsertChar() bool
- func HasInsertLine() bool
- func HasKey(ch Key) bool
- func InitColor(col, r, g, b int16) error
- func InitPair(pair, fg, bg int16) error
- func IsEnd() bool
- func IsTermResized(nlines, ncols int) bool
- func KeyString(k Key) string
- func MouseInterval(ms int) int
- func MouseOk() bool
- func Nap(ms int)
- func NewLines(on bool)
- func PairContent(pair int16) (fg int16, bg int16, err error)
- func Raw(on bool)
- func RequestByName(request string) (res int, err error)
- func RequestName(request int) (string, error)
- func ResizeTerm(nlines, ncols int) error
- func SlkAttributeOff(attr Char) error
- func SlkAttributeOn(attr Char) error
- func SlkClear() error
- func SlkColor(cp int16) error
- func SlkInit(f SlkFormat)
- func SlkLabel(labnum int) string
- func SlkNoutRefresh() error
- func SlkRefresh() error
- func SlkRestore() error
- func SlkSet(labnum int, label string, just SlkJustify) error
- func SlkSetAttribute(attr Char) error
- func SlkTouch() error
- func StartColor() error
- func TypeAhead(fd int) int
- func UnGetChar(ch Char)
- func Update() error
- func UpdatePanels()
- func UseDefaultColors() error
- func UseEnvironment(use bool)
- type Char
- type Field
- func (f *Field) Background() Char
- func (f *Field) Buffer() string
- func (f *Field) Duplicate(y, x int32) (*Field, error)
- func (f *Field) Foreground() Char
- func (f *Field) Free() error
- func (f *Field) Info(h, w, y, x, off, nbuf *int) error
- func (f *Field) Justification() int
- func (f *Field) Move(y, x int32) error
- func (f *Field) Options(opts int, on bool)
- func (f *Field) Pad() int
- func (f *Field) SetBackground(ch Char) error
- func (f *Field) SetBuffer(s string) error
- func (f *Field) SetForeground(ch Char) error
- func (f *Field) SetJustification(just int) error
- func (f *Field) SetMax(max int) error
- func (f *Field) SetOptionsOff(opts Char) error
- func (f *Field) SetOptionsOn(opts Char) error
- func (f *Field) SetPad(padch int) error
- type Form
- func (f *Form) Driver(drvract Key) error
- func (f *Form) FieldCount() int
- func (f *Form) Free() error
- func (f *Form) Post() error
- func (f *Form) SetFields(fields []*Field) error
- func (f *Form) SetOptions(opts int) error
- func (f *Form) SetSub(w *Window) error
- func (f *Form) SetWindow(w *Window) error
- func (f *Form) Sub() Window
- func (f *Form) UnPost() error
- type FormDriverReq
- type Key
- type Menu
- func (m *Menu) Background() int
- func (m *Menu) Count() int
- func (m *Menu) Current(mi *MenuItem) *MenuItem
- func (m *Menu) Driver(daction int) error
- func (m *Menu) Foreground() int
- func (m *Menu) Format(r, c int) error
- func (m *Menu) Free() error
- func (m *Menu) Grey(ch Char)
- func (m *Menu) Items() []*MenuItem
- func (m *Menu) Mark(mark string) error
- func (m *Menu) Option(opts int, on bool) error
- func (m *Menu) Pad() int
- func (m *Menu) Pattern() string
- func (m *Menu) PositionCursor()
- func (m *Menu) Post() error
- func (m *Menu) Scale() (int, int, error)
- func (m *Menu) SetBackground(ch Char) error
- func (m *Menu) SetForeground(ch Char) error
- func (m *Menu) SetItems(items []*MenuItem) error
- func (m *Menu) SetPad(ch Char) error
- func (m *Menu) SetPattern(pattern string) error
- func (m *Menu) SetSpacing(desc, row, col int) error
- func (m *Menu) SetWindow(w *Window) error
- func (m *Menu) Spacing() (int, int, int)
- func (m *Menu) SubWindow(sub *Window) error
- func (m *Menu) UnPost() error
- func (m *Menu) Window() *Window
- type MenuDriverReq
- type MenuItem
- type MouseButton
- type MouseEvent
- type Pad
- type Panel
- func (p *Panel) Above() *Panel
- func (p *Panel) Bottom() error
- func (p *Panel) Delete() error
- func (p *Panel) Hidden() bool
- func (p *Panel) Hide() error
- func (p *Panel) Move(y, x int) error
- func (p *Panel) Replace(w *Window) error
- func (p *Panel) Show() error
- func (p *Panel) Top() error
- func (p *Panel) Window() *Window
- type Screen
- type SlkFormat
- type SlkJustify
- type Window
- func (w *Window) AddChar(ach Char)
- func (w *Window) AttrOff(attr Char) (err error)
- func (w *Window) AttrOn(attr Char) (err error)
- func (w *Window) AttrSet(attr Char) error
- func (w *Window) Background() Char
- func (w *Window) Border(ls, rs, ts, bs, tl, tr, bl, br Char) error
- func (w *Window) Box(vch, hch Char) error
- func (w *Window) Clear() error
- func (w *Window) ClearOk(ok bool)
- func (w *Window) ClearToBottom() error
- func (w *Window) ClearToEOL() error
- func (w *Window) Color(pair int16)
- func (w *Window) ColorOff(pair int16) error
- func (w *Window) ColorOn(pair int16) error
- func (w *Window) Copy(src *Window, sy, sx, dtr, dtc, dbr, dbc int, overlay bool) error
- func (w *Window) CursorYX() (int, int)
- func (w *Window) DelChar() error
- func (w *Window) Delete() error
- func (w *Window) Derived(height, width, y, x int) *Window
- func (w *Window) Duplicate() *Window
- func (w *Window) Enclose(y, x int) bool
- func (w *Window) Erase()
- func (w *Window) GetChar() Key
- func (w *Window) GetString(n int) (string, error)
- func (w *Window) HLine(y, x int, ch Char, wid int)
- func (w *Window) InChar() Char
- func (w *Window) IsCleared() bool
- func (w *Window) IsKeypad() bool
- func (w *Window) Keypad(keypad bool) error
- func (w *Window) LineTouched(line int) bool
- func (w *Window) MaxYX() (int, int)
- func (w *Window) Move(y, x int)
- func (w *Window) MoveAddChar(y, x int, ach Char)
- func (w *Window) MoveDelChar(y, x int) error
- func (w *Window) MoveGetChar(y, x int) Key
- func (w *Window) MoveInChar(y, x int) Char
- func (w *Window) MovePrint(y, x int, args ...interface{})
- func (w *Window) MovePrintf(y, x int, format string, args ...interface{})
- func (w *Window) MovePrintln(y, x int, args ...interface{})
- func (w *Window) MoveWindow(y, x int)
- func (w *Window) NoutRefresh()
- func (w *Window) Overlay(src *Window) error
- func (w *Window) Overwrite(src *Window) error
- func (w *Window) Parent() *Window
- func (w *Window) Print(args ...interface{})
- func (w *Window) Printf(format string, args ...interface{})
- func (w *Window) Println(args ...interface{})
- func (w *Window) Refresh()
- func (w *Window) Resize(height, width int)
- func (w *Window) Scroll(n int)
- func (w *Window) ScrollOk(ok bool)
- func (w *Window) SetBackground(attr Char)
- func (w *Window) Standend() error
- func (w *Window) Standout() error
- func (w *Window) Sub(height, width, y, x int) *Window
- func (w *Window) Sync(sync int)
- func (w *Window) Timeout(delay int)
- func (w *Window) Touch() error
- func (w *Window) TouchLine(start, count int) error
- func (w *Window) Touched() bool
- func (w *Window) UnTouch()
- func (w *Window) VLine(y, x int, ch Char, wid int)
- func (w *Window) YX() (int, int)
Constants ¶
const ( SYNC_NONE = iota SYNC_CURSOR // Sync cursor in all sub/derived windows SYNC_DOWN // Sync changes in all parent windows SYNC_UP // Sync change in all child windows )
Synconize options for Sync() function
const ( A_NORMAL Char = C.A_NORMAL A_STANDOUT = C.A_STANDOUT A_UNDERLINE = C.A_UNDERLINE A_REVERSE = C.A_REVERSE A_BLINK = C.A_BLINK A_DIM = C.A_DIM A_BOLD = C.A_BOLD A_PROTECT = C.A_PROTECT A_INVIS = C.A_INVIS A_ALTCHARSET = C.A_ALTCHARSET A_CHARTEXT = C.A_CHARTEXT )
Text attributes
const ( /* VT100 symbols */ ACS_ULCORNER Char = C.A_ALTCHARSET + 'l' ACS_LLCORNER = C.A_ALTCHARSET + 'm' ACS_URCORNER = C.A_ALTCHARSET + 'k' ACS_LRCORNER = C.A_ALTCHARSET + 'j' ACS_LTEE = C.A_ALTCHARSET + 't' ACS_RTEE = C.A_ALTCHARSET + 'u' ACS_BTEE = C.A_ALTCHARSET + 'v' ACS_TTEE = C.A_ALTCHARSET + 'w' ACS_HLINE = C.A_ALTCHARSET + 'q' ACS_VLINE = C.A_ALTCHARSET + 'x' ACS_PLUS = C.A_ALTCHARSET + 'n' ACS_S1 = C.A_ALTCHARSET + 'o' ACS_S9 = C.A_ALTCHARSET + 's' ACS_DIAMOND = C.A_ALTCHARSET + '`' ACS_CKBOARD = C.A_ALTCHARSET + 'a' ACS_DEGREE = C.A_ALTCHARSET + 'f' ACS_PLMINUS = C.A_ALTCHARSET + 'g' ACS_BULLET = C.A_ALTCHARSET + '~' /* Teletype 5410v1 symbols */ ACS_LARROW = C.A_ALTCHARSET + ',' ACS_RARROW = C.A_ALTCHARSET + '+' ACS_DARROW = C.A_ALTCHARSET + '.' ACS_UARROW = C.A_ALTCHARSET + '-' ACS_BOARD = C.A_ALTCHARSET + 'h' ACS_LANTERN = C.A_ALTCHARSET + 'i' ACS_BLOCK = C.A_ALTCHARSET + '0' /* Undocumented, not well supported */ ACS_S3 = C.A_ALTCHARSET + 'p' ACS_S7 = C.A_ALTCHARSET + 'r' ACS_LEQUAL = C.A_ALTCHARSET + 'y' ACS_GEQUAL = C.A_ALTCHARSET + 'z' ACS_PI = C.A_ALTCHARSET + '{' ACS_NEQUAL = C.A_ALTCHARSET + '|' ACS_STERLING = C.A_ALTCHARSET + '}' )
Definitions for printed characters not found on most keyboards.
const ( C_BLACK int16 = C.COLOR_BLACK C_BLUE = C.COLOR_BLUE C_CYAN = C.COLOR_CYAN C_GREEN = C.COLOR_GREEN C_MAGENTA = C.COLOR_MAGENTA C_RED = C.COLOR_RED C_WHITE = C.COLOR_WHITE C_YELLOW = C.COLOR_YELLOW )
Colors available to ncurses. Combine these with the dim/bold attributes for bright/dark versions of each color. These colors can be used for both background and foreground colors.
const ( KEY_TAB Key = 9 // tab KEY_RETURN = 10 // enter key vs. KEY_ENTER KEY_DOWN = C.KEY_DOWN // down arrow key KEY_UP = C.KEY_UP // up arrow key KEY_LEFT = C.KEY_LEFT // left arrow key KEY_RIGHT = C.KEY_RIGHT // right arrow key KEY_HOME = C.KEY_HOME // home key KEY_BACKSPACE = C.KEY_BACKSPACE // backpace KEY_F1 = C.KEY_F0 + 1 // F1 key KEY_F2 = C.KEY_F0 + 2 // F2 key KEY_F3 = C.KEY_F0 + 3 // F3 key KEY_F4 = C.KEY_F0 + 4 // F4 key KEY_F5 = C.KEY_F0 + 5 // F5 key KEY_F6 = C.KEY_F0 + 6 // F6 key KEY_F7 = C.KEY_F0 + 7 // F7 key KEY_F8 = C.KEY_F0 + 8 // F8 key KEY_F9 = C.KEY_F0 + 9 // F9 key KEY_F10 = C.KEY_F0 + 10 // F10 key KEY_F11 = C.KEY_F0 + 11 // F11 key KEY_F12 = C.KEY_F0 + 12 // F12 key KEY_DL = C.KEY_DL // delete-line key KEY_IL = C.KEY_IL // insert-line key KEY_DC = C.KEY_DC // delete-character key KEY_IC = C.KEY_IC // insert-character key KEY_EIC = C.KEY_EIC // sent by rmir or smir in insert mode KEY_CLEAR = C.KEY_CLEAR // clear-screen or erase key KEY_EOS = C.KEY_EOS // clear-to-end-of-screen key KEY_EOL = C.KEY_EOL // clear-to-end-of-line key KEY_SF = C.KEY_SF // scroll-forward key KEY_SR = C.KEY_SR // scroll-backward key KEY_PAGEDOWN = C.KEY_NPAGE // page-down key (next-page) KEY_PAGEUP = C.KEY_PPAGE // page-up key (prev-page) KEY_STAB = C.KEY_STAB // set-tab key KEY_CTAB = C.KEY_CTAB // clear-tab key KEY_CATAB = C.KEY_CATAB // clear-all-tabs key KEY_ENTER = C.KEY_ENTER // enter/send key KEY_PRINT = C.KEY_PRINT // print key KEY_LL = C.KEY_LL // lower-left key (home down) KEY_A1 = C.KEY_A1 // upper left of keypad KEY_A3 = C.KEY_A3 // upper right of keypad KEY_B2 = C.KEY_B2 // center of keypad KEY_C1 = C.KEY_C1 // lower left of keypad KEY_C3 = C.KEY_C3 // lower right of keypad KEY_BTAB = C.KEY_BTAB // back-tab key KEY_BEG = C.KEY_BEG // begin key KEY_CANCEL = C.KEY_CANCEL // cancel key KEY_CLOSE = C.KEY_CLOSE // close key KEY_COMMAND = C.KEY_COMMAND // command key KEY_COPY = C.KEY_COPY // copy key KEY_CREATE = C.KEY_CREATE // create key KEY_END = C.KEY_END // end key KEY_EXIT = C.KEY_EXIT // exit key KEY_FIND = C.KEY_FIND // find key KEY_HELP = C.KEY_HELP // help key KEY_MARK = C.KEY_MARK // mark key KEY_MESSAGE = C.KEY_MESSAGE // message key KEY_MOVE = C.KEY_MOVE // move key KEY_NEXT = C.KEY_NEXT // next key KEY_OPEN = C.KEY_OPEN // open key KEY_OPTIONS = C.KEY_OPTIONS // options key KEY_PREVIOUS = C.KEY_PREVIOUS // previous key KEY_REDO = C.KEY_REDO // redo key KEY_REFERENCE = C.KEY_REFERENCE // reference key KEY_REFRESH = C.KEY_REFRESH // refresh key KEY_REPLACE = C.KEY_REPLACE // replace key KEY_RESTART = C.KEY_RESTART // restart key KEY_RESUME = C.KEY_RESUME // resume key KEY_SAVE = C.KEY_SAVE // save key KEY_SBEG = C.KEY_SBEG // shifted begin key KEY_SCANCEL = C.KEY_SCANCEL // shifted cancel key KEY_SCOMMAND = C.KEY_SCOMMAND // shifted command key KEY_SCOPY = C.KEY_SCOPY // shifted copy key KEY_SCREATE = C.KEY_SCREATE // shifted create key KEY_SDC = C.KEY_SDC // shifted delete-character key KEY_SDL = C.KEY_SDL // shifted delete-line key KEY_SELECT = C.KEY_SELECT // select key KEY_SEND = C.KEY_SEND // shifted end key KEY_SEOL = C.KEY_SEOL // shifted clear-to-end-of-line key KEY_SEXIT = C.KEY_SEXIT // shifted exit key KEY_SFIND = C.KEY_SFIND // shifted find key KEY_SHELP = C.KEY_SHELP // shifted help key KEY_SHOME = C.KEY_SHOME // shifted home key KEY_SIC = C.KEY_SIC // shifted insert-character key KEY_SLEFT = C.KEY_SLEFT // shifted left-arrow key KEY_SMESSAGE = C.KEY_SMESSAGE // shifted message key KEY_SMOVE = C.KEY_SMOVE // shifted move key KEY_SNEXT = C.KEY_SNEXT // shifted next key KEY_SOPTIONS = C.KEY_SOPTIONS // shifted options key KEY_SPREVIOUS = C.KEY_SPREVIOUS // shifted previous key KEY_SPRINT = C.KEY_SPRINT // shifted print key KEY_SREDO = C.KEY_SREDO // shifted redo key KEY_SREPLACE = C.KEY_SREPLACE // shifted replace key KEY_SRIGHT = C.KEY_SRIGHT // shifted right-arrow key KEY_SRSUME = C.KEY_SRSUME // shifted resume key KEY_SSAVE = C.KEY_SSAVE // shifted save key KEY_SSUSPEND = C.KEY_SSUSPEND // shifted suspend key KEY_SUNDO = C.KEY_SUNDO // shifted undo key KEY_SUSPEND = C.KEY_SUSPEND // suspend key KEY_UNDO = C.KEY_UNDO // undo key KEY_MOUSE = C.KEY_MOUSE // any mouse event KEY_RESIZE = C.KEY_RESIZE // Terminal resize event //KEY_EVENT = C.KEY_EVENT // We were interrupted by an event KEY_MAX = C.KEY_MAX // Maximum key value is KEY_EVENT (0633) )
const ( M_ALL MouseButton = C.ALL_MOUSE_EVENTS M_ALT = C.BUTTON_ALT // alt-click M_B1_PRESSED = C.BUTTON1_PRESSED // button 1 M_B1_RELEASED = C.BUTTON1_RELEASED M_B1_CLICKED = C.BUTTON1_CLICKED M_B1_DBL_CLICKED = C.BUTTON1_DOUBLE_CLICKED M_B1_TPL_CLICKED = C.BUTTON1_TRIPLE_CLICKED M_B2_PRESSED = C.BUTTON2_PRESSED // button 2 M_B2_RELEASED = C.BUTTON2_RELEASED M_B2_CLICKED = C.BUTTON2_CLICKED M_B2_DBL_CLICKED = C.BUTTON2_DOUBLE_CLICKED M_B2_TPL_CLICKED = C.BUTTON2_TRIPLE_CLICKED M_B3_PRESSED = C.BUTTON3_PRESSED // button 3 M_B3_RELEASED = C.BUTTON3_RELEASED M_B3_CLICKED = C.BUTTON3_CLICKED M_B3_DBL_CLICKED = C.BUTTON3_DOUBLE_CLICKED M_B3_TPL_CLICKED = C.BUTTON3_TRIPLE_CLICKED M_B4_PRESSED = C.BUTTON4_PRESSED // button 4 M_B4_RELEASED = C.BUTTON4_RELEASED M_B4_CLICKED = C.BUTTON4_CLICKED M_B4_DBL_CLICKED = C.BUTTON4_DOUBLE_CLICKED M_B4_TPL_CLICKED = C.BUTTON4_TRIPLE_CLICKED M_CTRL = C.BUTTON_CTRL // ctrl-click M_SHIFT = C.BUTTON_SHIFT // shift-click M_POSITION = C.REPORT_MOUSE_POSITION // mouse moved )
Mouse button events
const ( REQ_NEXT_PAGE FormDriverReq = C.REQ_NEXT_PAGE // next page REQ_PREV_PAGE = C.REQ_PREV_PAGE // previous page REQ_FIRST_PAGE = C.REQ_FIRST_PAGE // first page REQ_LAST_PAGE = C.REQ_LAST_PAGE // last page REQ_NEXT_FIELD = C.REQ_NEXT_FIELD // next field REQ_PREV_FIELD = C.REQ_PREV_FIELD // previous field REQ_FIRST_FIELD = C.REQ_FIRST_FIELD // first field REQ_LAST_FIELD = C.REQ_LAST_FIELD // last field REQ_SNEXT_FIELD = C.REQ_SNEXT_FIELD // sorted next field REQ_SPREV_FIELD = C.REQ_SPREV_FIELD // sorted previous field REQ_SFIRST_FIELD = C.REQ_SFIRST_FIELD // sorted first field REQ_SLAST_FIELD = C.REQ_SLAST_FIELD // sorted last field REQ_LEFT_FIELD = C.REQ_LEFT_FIELD // left field REQ_RIGHT_FIELD = C.REQ_RIGHT_FIELD // right field REQ_UP_FIELD = C.REQ_UP_FIELD // up to a field REQ_DOWN_FIELD = C.REQ_DOWN_FIELD // down to a field REQ_NEXT_CHAR = C.REQ_NEXT_CHAR // next character in field REQ_PREV_CHAR = C.REQ_PREV_CHAR // previous character in field REQ_NEXT_LINE = C.REQ_NEXT_LINE // next line REQ_PREV_LINE = C.REQ_PREV_LINE // previous line REQ_NEXT_WORD = C.REQ_NEXT_WORD // next word REQ_PREV_WORD = C.REQ_PREV_WORD // previous word REQ_BEG_FIELD = C.REQ_BEG_FIELD // beginning of field REQ_END_FIELD = C.REQ_END_FIELD // end of field REQ_BEG_LINE = C.REQ_BEG_LINE // beginning of line REQ_END_LINE = C.REQ_END_LINE // end of line REQ_LEFT_CHAR = C.REQ_LEFT_CHAR // character to the left REQ_RIGHT_CHAR = C.REQ_RIGHT_CHAR // character to the right REQ_UP_CHAR = C.REQ_UP_CHAR // up a character REQ_DOWN_CHAR = C.REQ_DOWN_CHAR // down a character REQ_NEW_LINE = C.REQ_NEW_LINE // insert of overlay a new line REQ_INS_CHAR = C.REQ_INS_CHAR // insert a blank character at cursor REQ_INS_LINE = C.REQ_INS_LINE // insert a blank line at cursor REQ_DEL_CHAR = C.REQ_DEL_CHAR // delete character at cursor REQ_DEL_PREV = C.REQ_DEL_PREV // delete character before cursor REQ_DEL_LINE = C.REQ_DEL_LINE // delete line REQ_DEL_WORD = C.REQ_DEL_WORD // delete word REQ_CLR_EOL = C.REQ_CLR_EOL // clear from cursor to end of line REQ_CLR_EOF = C.REQ_CLR_EOF // clear from cursor to end of field REQ_CLR_FIELD = C.REQ_CLR_FIELD // clear field REQ_OVL_MODE = C.REQ_OVL_MODE // overlay mode REQ_INS_MODE = C.REQ_INS_MODE // insert mode REQ_SCR_FLINE = C.REQ_SCR_FLINE // scroll field forward a line REQ_SCR_BLINE = C.REQ_SCR_BLINE // scroll field back a line REQ_SCR_FPAGE = C.REQ_SCR_FPAGE // scroll field forward a page REQ_SCR_BPAGE = C.REQ_SCR_BPAGE // scroll field back a page REQ_SCR_FHPAGE = C.REQ_SCR_FHPAGE // scroll field forward half a page REQ_SCR_BHPAGE = C.REQ_SCR_BHPAGE // scroll field back half a page REQ_SCR_FCHAR = C.REQ_SCR_FCHAR // scroll field forward a character REQ_SCR_BCHAR = C.REQ_SCR_BCHAR // scroll field back a character REQ_SCR_HFLINE = C.REQ_SCR_HFLINE // horisontal scroll field forward a line REQ_SCR_HBLINE = C.REQ_SCR_HBLINE // horisontal scroll field back a line REQ_SCR_HFHALF = C.REQ_SCR_HFHALF // horisontal scroll field forward half a line REQ_SCR_HBHALF = C.REQ_SCR_HBHALF // horisontal scroll field back half a line REQ_VALIDATION = C.REQ_VALIDATION // validate field REQ_NEXT_CHOICE = C.REQ_NEXT_CHOICE // display next field choice REQ_PREV_CHOICE = C.REQ_PREV_CHOICE // display previous field choice )
const ( FO_VISIBLE = C.O_VISIBLE // Field visibility FO_ACTIVE = C.O_ACTIVE // Field is sensitive/accessable FO_PUBLIC = C.O_PUBLIC // Typed characters are echoed FO_EDIT = C.O_EDIT // Editable FO_WRAP = C.O_WRAP // Line wrapping FO_BLANK = C.O_BLANK // Clear on entry FO_AUTOSKIP = C.O_AUTOSKIP // Skip to next field when current filled FO_NULLOK = C.O_NULLOK // Blank ok FO_STATIC = C.O_STATIC // Fixed size FO_PASSOK = C.O_PASSOK // Field validation )
const ( REQ_LEFT MenuDriverReq = C.REQ_LEFT_ITEM REQ_RIGHT = C.REQ_RIGHT_ITEM REQ_UP = C.REQ_UP_ITEM REQ_DOWN = C.REQ_DOWN_ITEM REQ_ULINE = C.REQ_SCR_ULINE REQ_DLINE = C.REQ_SCR_DLINE REQ_PAGE_DOWN = C.REQ_SCR_DPAGE REQ_PAGE_UP = C.REQ_SCR_UPAGE REQ_FIRST = C.REQ_FIRST_ITEM REQ_LAST = C.REQ_LAST_ITEM REQ_NEXT = C.REQ_NEXT_ITEM REQ_PREV = C.REQ_PREV_ITEM REQ_TOGGLE = C.REQ_TOGGLE_ITEM REQ_CLEAR_PATTERN = C.REQ_CLEAR_PATTERN REQ_BACK_PATTERN = C.REQ_BACK_PATTERN REQ_NEXT_MATCH = C.REQ_NEXT_MATCH REQ_PREV_MATCH = C.REQ_PREV_MATCH )
const ( O_ONEVALUE = C.O_ONEVALUE // Only one item can be selected O_SHOWDESC = C.O_SHOWDESC // Display item descriptions O_ROWMAJOR = C.O_ROWMAJOR // Display in row-major order O_IGNORECASE = C.O_IGNORECASE // Ingore case when pattern-matching O_SHOWMATCH = C.O_SHOWMATCH // Move cursor to item when pattern-matching O_NONCYCLIC = C.O_NONCYCLIC // Don't wrap next/prev item )
Menu Options
const O_SELECTABLE = C.O_SELECTABLE
Menu Item Options
Variables ¶
var DriverActions = map[Key]int{ KEY_DOWN: C.REQ_DOWN_ITEM, KEY_HOME: C.REQ_FIRST_ITEM, KEY_END: C.REQ_LAST_ITEM, KEY_LEFT: C.REQ_LEFT_ITEM, KEY_PAGEDOWN: C.REQ_SCR_DPAGE, KEY_PAGEUP: C.REQ_SCR_UPAGE, KEY_RIGHT: C.REQ_RIGHT_ITEM, KEY_UP: C.REQ_UP_ITEM, }
DriverActions is a convenience mapping for common responses to keyboard input
Functions ¶
func Beep ¶
func Beep()
Beep requests the terminal make an audible bell or, if not available, flashes the screen. Note that screen flashing doesn't work on all terminals
func CBreak ¶
func CBreak(on bool)
Turn on/off buffering; raw user signals are passed to the program for handling. Overrides raw mode
func ColorContent ¶
Get RGB values for specified colour
func CursesVersion ¶
func CursesVersion() string
CursesVersion returns the version of the ncurses library currently linked to
func Cursor ¶
Set the cursor visibility. Options are: 0 (invisible/hidden), 1 (normal) and 2 (extra-visible)
func End ¶
func End()
Must be called prior to exiting the program in order to make sure the terminal returns to normal operation
func Flash ¶
func Flash()
Flash requests the terminal flashes the screen or, if not available, make an audible bell. Note that screen flashing doesn't work on all terminals
func HalfDelay ¶
Behaves like cbreak() but also adds a timeout for input. If timeout is exceeded after a call to Getch() has been made then GetChar will return with an error.
func HasInsertChar ¶
func HasInsertChar() bool
HasInsertChar return true if the terminal has insert and delete character capabilities
func HasInsertLine ¶
func HasInsertLine() bool
HasInsertLine returns true if the terminal has insert and delete line capabilities. See ncurses documentation for more details
func InitColor ¶
InitColor is used to set 'color' to the specified RGB values. Values may be between 0 and 1000.
func IsTermResized ¶
IsTermResized returns true if ResizeTerm would modify any current Windows if called with the given parameters
func MouseInterval ¶
MouseInterval sets the maximum time in milliseconds that can elapse between press and release mouse events and returns the previous setting. Use a value of 0 (zero) to disable click resolution. Use a value of -1 to get the previous value without changing the current value. Default value is 1/6 of a second.
func MouseOk ¶
func MouseOk() bool
MouseOk returns true if ncurses has built-in mouse support. On ncurses 5.7 and earlier, this function is not present and so will always return false
func PairContent ¶
PairContent returns the current foreground and background colours associated with the given pair
func Raw ¶
func Raw(on bool)
Raw turns on input buffering; user signals are disabled and the key strokes are passed directly to input. Set to false if you wish to turn this mode off
func RequestByName ¶
RequestByName returns the request ID of the provide request
func ResizeTerm ¶
ResizeTerm will attempt to resize the terminal. This only has an effect if the terminal is in an XWindows (GUI) environment.
func SlkAttributeOff ¶
SlkAttributeOff turns off the given OR'd attributes withoiut turning any on
func SlkAttributeOn ¶
SlkAttributeOn turns on the given OR'd attributes without turning any off
func SlkInit ¶
func SlkInit(f SlkFormat)
Initializes the soft-key labels with the given format; keys like the F1-F12 keys on most keyboards. After a call to SlkRefresh a bar at the bottom of the standard screen returned by Init will be displayed. This function MUST be called prior to Init()
func SlkRefresh ¶
func SlkRefresh() error
SlkRefresh behaves the same as Window.Refresh. Most applications would use SlkNoutRefresh because a Window.Refresh is likely to follow
func SlkRestore ¶
func SlkRestore() error
SlkRestore restores the soft-key labels to the screen after an SlkClear()
func SlkSet ¶
func SlkSet(labnum int, label string, just SlkJustify) error
SlkSet sets the 'labnum' text to the supplied 'label'. Labels must not be greater than 8 characters
func SlkSetAttribute ¶
SlkSetAttribute sets the OR'd attributes to use
func StartColor ¶
func StartColor() error
Enables colors to be displayed. Will return an error if terminal is not capable of displaying colors
func UpdatePanels ¶
func UpdatePanels()
UpdatePanels refreshes the panel stack. It must be called prior to using ncurses's DoUpdate()
func UseDefaultColors ¶
func UseDefaultColors() error
UseDefaultColors tells the curses library to assign the terminal's default foreground and background colors to color number -1. This will allow you to call InitPair(x, -1, -1) to set both the foreground and backgroun colours of pair x to the terminal's default. This function can fail if the terminal does not support certain ncurses features like orig_pair or initialize_pair.
func UseEnvironment ¶
func UseEnvironment(use bool)
UseEnvironment specifies whether the LINES and COLUMNS environmental variables should be used or not
Types ¶
type Field ¶
func (*Field) Background ¶
Background returns the field's background character attributes
func (*Field) Buffer ¶
Buffer returns a string containing the contents of the buffer. The returned string will contain whitespace up to the buffer size as set by SetMax or the value by the call to NewField
func (*Field) Duplicate ¶
Duplicate the field at the specified coordinates, returning a pointer to the newly allocated object.
func (*Field) Foreground ¶
Foreground returns the field's foreground character attributes
func (*Field) Info ¶
Info retrieves the height, width, y, x, offset and buffer size of the given field. Pass the memory addess of the variable to store the data in or nil.
func (*Field) Justification ¶
Just returns the justification type of the field
func (*Field) SetBackground ¶
SetBackground character and attributes (colours, etc)
func (*Field) SetBuffer ¶
SetBuffer sets the visible characters in the field. A buffer is empty by default.
func (*Field) SetForeground ¶
SetForeground character and attributes (colours, etc)
func (*Field) SetJustification ¶
SetJustification of the field
func (*Field) SetOptionsOff ¶
OptionsOff turns feature(s) off
func (*Field) SetOptionsOn ¶
OptionsOn turns feature(s) on
type Form ¶
type Form struct {
// contains filtered or unexported fields
}
func (*Form) Driver ¶
Driver issues the actions requested to the form itself. See the corresponding REQ_* constants
func (*Form) FieldCount ¶
FieldCount returns the number of fields attached to the Form
func (*Form) Free ¶
Free the memory allocated to the form. Forms are not automatically free'd by Go's garbage collection system so the memory allocated to it must be explicitely free'd
func (*Form) SetFields ¶
SetFields overwrites the current fields for the Form with new ones. It is important to make sure all prior fields have been freed otherwise this action will result in a memory leak
type Menu ¶
type Menu struct {
// contains filtered or unexported fields
}
func (*Menu) Background ¶
Background returns the menu's background character setting
func (*Menu) Driver ¶
Driver controls how the menu is activated. Action usually corresponds to the string return by the Key() function in goncurses.
func (*Menu) Foreground ¶
Foreground gets the attributes of highlighted items in the menu
func (*Menu) Free ¶
Free deallocates memory set aside for the menu. This must be called before exiting.
func (*Menu) Option ¶
Option sets the options for the menu. See the O_* definitions for a list of values which can be OR'd together
func (*Menu) PositionCursor ¶
func (m *Menu) PositionCursor()
PositionCursor sets the cursor over the currently selected menu item.
func (*Menu) SetBackground ¶
SetBackground set the attributes of the un-highlighted items in the menu
func (*Menu) SetForeground ¶
SetForeground sets the attributes of the highlighted items in the menu
func (*Menu) SetItems ¶
SetItems will either set the items in the menu. When setting items you must make sure the prior menu items will be freed.
func (*Menu) SetPattern ¶
SetPattern sets the padding character for menu items.
func (*Menu) SetSpacing ¶
SetSpacing of the the menu's items. 'desc' is the space between the item and it's description andmay not be larger than TAB_SIZE. 'row' is the number of rows separating each item and may not be larger than three. 'col' is the spacing between each column of items in multi-column mode. Use values of 0 or 1 to reset spacing to default, which is one
type MenuItem ¶
type MenuItem struct {
// contains filtered or unexported fields
}
func (*MenuItem) Description ¶
Description returns the second value passed to NewItem
func (*MenuItem) Free ¶
func (mi *MenuItem) Free()
Free must be called on all menu items to avoid memory leaks
func (*MenuItem) Selectable ¶
Selectable turns on/off whether a menu option is "greyed out"
type MouseButton ¶
type MouseButton int
func MouseMask ¶
func MouseMask(mask MouseButton, old *MouseButton) MouseButton
MouseMask accepts a single int of OR'd mouse events. If a mouse event is triggered, GetChar() will return KEY_MOUSE. To retrieve the actual event use GetMouse() to pop it off the queue. Pass a pointer as the second argument to store the prior events being monitored or nil.
type MouseEvent ¶
type MouseEvent struct { Id int16 /* device ID */ X, Y, Z int /* event coordinates */ State MouseButton /* button state */ }
func GetMouse ¶
func GetMouse() *MouseEvent
GetMouse returns the MouseEvent associated with a KEY_MOUSE event returned by a call to GetChar(). Returns a new MouseEvent or nil on error or if no event is currently in the mouse event queue
type Pad ¶
type Pad struct {
*Window
}
func NewPad ¶
NewPad creates a window which is not restricted by the terminal's dimentions (unlike a Window). Pads accept all functions which can be called on a window. It returns a pointer to a new Pad of h(eight) by w(idth).
func (*Pad) Echo ¶
Echo prints a single character to the pad immediately. This has the same effect of calling AddChar() + Refresh() but has a significant speed advantage
func (*Pad) NoutRefresh ¶
NoutRefresh indicates that a section of the screen should be redrawn but does not update the phsyical screen until Update() is called. See Pad.Refresh() for details on the arguments and Window.NoutRefresh for more details on the workings of this function
func (*Pad) Refresh ¶
Refresh will calculate how to update the physical screen in the most efficient manor and update it. See Window.Refresh for more details. The coordinates py, px specify the location on the pad from which the characters we want to display are located. sy and sx specify the location on the screen where this data should be displayed. h and w are the height and width of the rectangle to be displayed. The coodinates and the size of the rectangle must be contained within both the Pad's and Window's respective areas
type Panel ¶
type Panel struct {
// contains filtered or unexported fields
}
func Below ¶
Returns a pointer to the panel below in the stack or nil. Passing nil will return the bottom panel in the stack
func NewPanel ¶
Panel creates a new panel derived from the window, adding it to the panel stack. The pointer to the original window can still be used to excute most window functions with the exception of Refresh(). Always use panel's Refresh() function.
func (*Panel) Above ¶
Returns a pointer to the panel above in the stack or nil. Passing nil will return the top panel in the stack
func (*Panel) Move ¶
Move the panel to the specified location. It is important to never use ncurses movement functions on the window governed by panel. Always use this function
type Screen ¶
type Screen struct {
// contains filtered or unexported fields
}
func NewTerm ¶
NewTerm returns a new Screen, representing a physical terminal. If using this function to generate a new Screen you should not call Init(). Unlike Init(), NewTerm does not call Refresh() to clear the screen so this will need to be done manually. When finished with a terminal, you must call End() in reverse order that each terminal was created in. After you are finished with the screen you must call Delete to free the memory allocated to it. This function is usually only useful for programs using multiple terminals or test for terminal capabilites. The argument termType is the type of terminal to be used ($TERM is used if value is "" which also has the same effect of using os.Getenv("TERM"))
func (*Screen) Delete ¶
func (s *Screen) Delete()
Delete frees memory allocated to the screen. This function
func (*Screen) End ¶
func (s *Screen) End()
End is just a wrapper for the global End function. This helper function has been provided to help ensure that new terminals are closed in the proper, reverse order they were created. It makes the terminal active via set then called End so it is closed properly. You must make sure that Delete is called once done with the screen/terminal.
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
func Init ¶
Initialize the ncurses library. You must run this function prior to any other goncurses function in order for the library to work
func StdScr ¶
func StdScr() *Window
StdScr returns a Window for the underlying stdscr object which represents the physical screen. This is the same Window returned by Init and therefore not useful unless using NewTerm and other multi-screen related functions.
func (*Window) AddChar ¶
AddChar prints a single character to the window. The character can be OR'd together with attributes and colors.
func (*Window) Background ¶
Background returns the current background attributes
func (*Window) Border ¶
Border uses the characters supplied to draw a border around the window. t, b, r, l, s correspond to top, bottom, right, left and side respectively.
func (*Window) Box ¶
Box draws a border around the given window. For complete control over the characters used to draw the border use Border()
func (*Window) Clear ¶
Clears the screen and the underlying virtual screen. This forces the entire screen to be rewritten from scratch. This will cause likely cause a noticeable flicker because the screen is completely cleared before redrawing it. This is probably not what you want. Instead, you should probably use the Erase() function. It is the same as called Erase() followed by a call to ClearOk().
func (*Window) ClearOk ¶
ClearOk clears the window completely prior to redrawing it. If called on stdscr then the whole screen is redrawn no matter which window has Refresh() called on it. Defaults to False.
func (*Window) ClearToBottom ¶
Clear starting at the current cursor position, moving to the right, to the bottom of window
func (*Window) ClearToEOL ¶
Clear from the current cursor position, moving to the right, to the end of the line
func (*Window) ColorOn ¶
Normally color pairs are turned on via attron() in ncurses but this implementation chose to make it seperate
func (*Window) Copy ¶
Copy is similar to Overlay and Overwrite but provides a finer grain of control.
func (*Window) CursorYX ¶
Getyx returns the current cursor location in the Window. Note that it uses ncurses idiom of returning y then x.
func (*Window) DelChar ¶
DelChar deletes the character at the current cursor position, moving all characters to the right of that position one space to the left and appends a blank character at the end.
func (*Window) Delete ¶
Delete the window. This function must be called to ensure memory is freed to prevent memory leaks once you are done with the window.
func (*Window) Derived ¶
Derived creates a new window of height and width at the coordinates y, x. These coordinates are relative to the original window thereby confining the derived window to the area of original window. See the SubWindow function for additional notes.
func (*Window) Erase ¶
func (w *Window) Erase()
Erase the contents of the window, clearing it. This function allows the underlying structures to be updated efficiently and thereby provide smooth updates to the terminal when frequently clearing and re-writing the window or screen.
func (*Window) GetChar ¶
GetChar retrieves a character from standard input stream and returns it. In the event of an error or if the input timeout has expired (ie. if Timeout() has been set to zero or a positive value and no characters have been received) the value returned will be zero (0)
func (*Window) GetString ¶
GetString reads at most 'n' characters entered by the user from the Window. Attempts to enter greater than 'n' characters will elicit a 'beep'
func (*Window) HLine ¶
HLine draws a horizontal line starting at y, x and ending at width using the specified character
func (*Window) Keypad ¶
Keypad turns on/off the keypad characters, including those like the F1-F12 keys and the arrow keys
func (*Window) LineTouched ¶
LineTouched returns true if the line has been touched; returns false otherwise
func (*Window) MaxYX ¶
Returns the maximum size of the Window. Note that it uses ncurses idiom of returning y then x.
func (*Window) MoveAddChar ¶
MoveAddChar prints a single character to the window at the specified y x coordinates. See AddChar for more info.
func (*Window) MoveDelChar ¶
MoveDelChar deletes the character at the givin cursor coordinates, moving all characters to the right of that position one space to the left and appends a blank character at the end.
func (*Window) MoveGetChar ¶
MoveGetChar moves the cursor to the given position and gets a character from the input stream
func (*Window) MoveInChar ¶
MoveInChar returns the character at the designated coordates in the curses window
func (*Window) MovePrint ¶
MovePrint moves the cursor to the specified coordinates and prints the supplied message. See Print for more details.The first two arguments are the coordinates to print to.
func (*Window) MovePrintf ¶
MovePrintf moves the cursor to coordinates and prints the message using the specified format. See Printf and MovePrint for more information.
func (*Window) MovePrintln ¶
MovePrintln moves the cursor to coordinates and prints the message. See Println and MovePrint for more details.
func (*Window) MoveWindow ¶
MoveWindow moves the location of the window to the specified coordinates
func (*Window) NoutRefresh ¶
func (w *Window) NoutRefresh()
NoutRefresh, or No Output Refresh, flags the window for redrawing but does not output the changes to the terminal (screen). Essentially, the output is buffered and a call to Update() flushes the buffer to the terminal. This function provides a speed increase over calling Refresh() when multiple windows are involved because only the final output is transmitted to the terminal.
func (*Window) Overlay ¶
Overlay copies overlapping sections of src window onto the destination window. Non-blank elements are not overwritten.
func (*Window) Overwrite ¶
Overwrite copies overlapping sections of src window onto the destination window. This function is considered "destructive" by copying all elements of src onto the destination window.
func (*Window) Parent ¶
Parent returns a pointer to a Sub-window's parent, or nil if the window has no parent
func (*Window) Print ¶
func (w *Window) Print(args ...interface{})
Print a string to the given window. See the fmt package in the standard library for more information. In order to simulate the 'n' version of functions (like addnstr) just slice your string to the maximum length before passing it as an argument. window.Print("My line which should be clamped to 20 characters"[:20])
func (*Window) Printf ¶
Printf functions the same as the stardard library's fmt package. See Print for more details.
func (*Window) Println ¶
func (w *Window) Println(args ...interface{})
Println behaves the s as Println in the stanard library's fmt package. See Print for more information.
func (*Window) Refresh ¶
func (w *Window) Refresh()
Refresh the window so it's contents will be displayed
func (*Window) Scroll ¶
Scroll the contents of the window. Use a negative number to scroll up, a positive number to scroll down. ScrollOk Must have been called prior.
func (*Window) SetBackground ¶
SetBackground fills the background with the supplied attributes and/or characters.
func (*Window) Sub ¶
SubWindow creates a new window of height and width at the coordinates y, x. This window shares memory with the original window so changes made to one window are reflected in the other. It is necessary to call Touch() on this window prior to calling Refresh in order for it to be displayed.
func (*Window) Sync ¶
Sync updates all parent or child windows which were created via SubWindow() or DerivedWindow(). Argument can be one of: SYNC_DOWN, which syncronizes all parent windows (done by Refresh() by default so should rarely, if ever, need to be called); SYNC_UP, which updates all child windows to match any updates made to the parent; and, SYNC_CURSOR, which updates the cursor position only for all windows to match the parent window
func (*Window) Timeout ¶
Timeout sets the window to blocking or non-blocking read mode. Calls to GetCh will behave in the following manor depending on the value of delay: <= -1 - blocking mode is set (blocks indefinately) == 0 - non-blocking; returns zero (0) >= 1 - blocks for delay in milliseconds; returns zero (0)
func (*Window) Touch ¶
Touch indicates that the window contains changes which should be updated on the next call to Refresh
func (*Window) TouchLine ¶
Touchline behaves like Touch but only effects count number of lines, beginning at start
func (*Window) UnTouch ¶
func (w *Window) UnTouch()
UnTouch indicates the window should not be updated on the next call to Refresh