curses

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2022 License: GPL-3.0 Imports: 5 Imported by: 2

README

curses.go

GO binding for ncurses.

Sample

package main

import "github.com/tncardoso/curses.go"

func main() {
    curses.Initscr()
    defer curses.End()
    curses.Cbreak()
    curses.Noecho()
    curses.Stdscr.Keypad(true)
    
    curses.Attron(curses.A_BOLD)
    curses.Addstr("Hello World!")
    curses.Refresh()

    wind := curses.NewWindow(10,40,10,10)
    wind.Box(0,0)
    wind.Refresh()
    
    curses.Stdscr.Getch()
}

Requirements

Installation

goinstall is now supporting cgo packages, therefore installing curses.go should be as easy as:

$ goinstall github.com/tncardoso/curses.go

If you have problems with goinstall, you can update your go release or clone the repository:

$ git clone git://github.com/tncardoso/curses.go.git
$ cd curses.go
$ gomake install

Documentation

Index

Constants

View Source
const (
	A_NORMAL     = C.A_NORMAL
	A_ATTRIBUTES = C.A_ATTRIBUTES
	A_CHARTEXT   = C.A_CHARTEXT
	A_COLOR      = C.A_COLOR
	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_ALTCHARSET = C.A_ALTCHARSET
	A_INVIS      = C.A_INVIS
	A_PROTECT    = C.A_PROTECT
	A_HORIZONTAL = C.A_HORIZONTAL
	A_LEFT       = C.A_LEFT
	A_LOW        = C.A_LOW
	A_RIGHT      = C.A_RIGHT
	A_TOP        = C.A_TOP
	A_VERTICAL   = C.A_VERTICAL
)

Attributes

View Source
const (
	KEY_DOWN   = C.KEY_DOWN
	KEY_UP     = C.KEY_UP
	KEY_LEFT   = C.KEY_LEFT
	KEY_RIGHT  = C.KEY_RIGHT
	KEY_RESIZE = C.KEY_RESIZE
)

Keys

View Source
const (
	BUTTON1_PRESSED        C.mmask_t = C.BUTTON1_PRESSED
	BUTTON1_RELEASED                 = C.BUTTON1_RELEASED
	BUTTON1_CLICKED                  = C.BUTTON1_CLICKED
	BUTTON1_DOUBLE_CLICKED           = C.BUTTON1_DOUBLE_CLICKED
	BUTTON1_TRIPLE_CLICKED           = C.BUTTON1_TRIPLE_CLICKED
	BUTTON2_PRESSED                  = C.BUTTON2_PRESSED
	BUTTON2_RELEASED                 = C.BUTTON2_RELEASED
	BUTTON2_CLICKED                  = C.BUTTON2_CLICKED
	BUTTON2_DOUBLE_CLICKED           = C.BUTTON2_DOUBLE_CLICKED
	BUTTON2_TRIPLE_CLICKED           = C.BUTTON2_TRIPLE_CLICKED
	BUTTON3_PRESSED                  = C.BUTTON3_PRESSED
	BUTTON3_RELEASED                 = C.BUTTON3_RELEASED
	BUTTON3_CLICKED                  = C.BUTTON3_CLICKED
	BUTTON3_DOUBLE_CLICKED           = C.BUTTON3_DOUBLE_CLICKED
	BUTTON3_TRIPLE_CLICKED           = C.BUTTON3_TRIPLE_CLICKED
	BUTTON4_PRESSED                  = C.BUTTON4_PRESSED
	BUTTON4_RELEASED                 = C.BUTTON4_RELEASED
	BUTTON4_CLICKED                  = C.BUTTON4_CLICKED
	BUTTON4_DOUBLE_CLICKED           = C.BUTTON4_DOUBLE_CLICKED
	BUTTON4_TRIPLE_CLICKED           = C.BUTTON4_TRIPLE_CLICKED
	BUTTON_SHIFT                     = C.BUTTON_SHIFT
	BUTTON_CTRL                      = C.BUTTON_CTRL
	BUTTON_ALT                       = C.BUTTON_ALT
	ALL_MOUSE_EVENTS                 = C.ALL_MOUSE_EVENTS
	REPORT_MOUSE_POSITION            = C.REPORT_MOUSE_POSITION
)
View Source
const ERR = C.ERR

Error return value

View Source
const (
	KEY_MOUSE = C.KEY_MOUSE
)

Variables

This section is empty.

Functions

func ACS_BLOCK

func ACS_BLOCK() uint32

func ACS_BOARD

func ACS_BOARD() uint32

func ACS_BTEE

func ACS_BTEE() uint32

func ACS_BULLET

func ACS_BULLET() uint32

func ACS_CKBOARD

func ACS_CKBOARD() uint32

func ACS_DARROW

func ACS_DARROW() uint32

func ACS_DEGREE

func ACS_DEGREE() uint32

func ACS_DIAMOND

func ACS_DIAMOND() uint32

func ACS_HLINE

func ACS_HLINE() uint32

func ACS_LANTERN

func ACS_LANTERN() uint32

func ACS_LARROW

func ACS_LARROW() uint32

func ACS_LLCORNER

func ACS_LLCORNER() uint32

func ACS_LRCORNER

func ACS_LRCORNER() uint32

func ACS_LTEE

func ACS_LTEE() uint32

func ACS_PLMINUS

func ACS_PLMINUS() uint32

func ACS_PLUS

func ACS_PLUS() uint32

func ACS_RARROW

func ACS_RARROW() uint32

func ACS_RTEE

func ACS_RTEE() uint32

func ACS_S1

func ACS_S1() uint32

func ACS_S9

func ACS_S9() uint32

func ACS_TTEE

func ACS_TTEE() uint32

func ACS_UARROW

func ACS_UARROW() uint32

func ACS_ULCORNER

func ACS_ULCORNER() uint32

func ACS_URCORNER

func ACS_URCORNER() uint32

func ACS_VLINE

func ACS_VLINE() uint32

func Addch

func Addch(ch int)

func Addstr

func Addstr(str ...interface{})

func Attroff

func Attroff(attr int)

Disable attribute

func Attron

func Attron(attr int)

Enable attribute

func Attrset

func Attrset(attr int)

Set attribute

func COLORS

func COLORS() int

COLORS is the maximum number of colors that curses can support.

func COLOR_PAIRS

func COLOR_PAIRS() int

COLOR_PAIRS is the maximum number of color pairs that curses can support.

func CanChangeColor

func CanChangeColor() bool

CanChangeColor returns true if the terminal supports more than the default 8-bit colors.

func Cbreak

func Cbreak()

No buffering.

func Clear

func Clear()

Copies blanks to every position on the window buffer.

func Echo

func Echo()

Enable character echoing while reading.

func End

func End()

Finalizes curses.

func Erase

func Erase()

Copies blanks to every position on the window.

func Getch

func Getch() int

Get char from the standard in.

func Getmaxyx

func Getmaxyx() (row, col int)

Get terminal size.

func HasColors

func HasColors() bool

HasColors returns true if the terminal supports colors.

func Mouseinterval

func Mouseinterval(delay time.Duration) time.Duration

Sets and returns the max time, between click and release, that can be considered a click. The finest resolution available is milliseconds. Pass -1 to obtain the current value without changing it. Pass 0 to disable click resolution.

func Move

func Move(y, x int)

func Mvaddch

func Mvaddch(y, x int, ch int)

func Mvaddstr

func Mvaddstr(y, x int, str ...interface{})

func Noecho

func Noecho()

Disables character echoing while reading.

func Raw

func Raw()

Raw input. No buffering. CTRL+Z and CTRL+C passed to the application.

func Refresh

func Refresh()

Refresh screen.

func StartColor

func StartColor() error

StartColor must be called before calling any other color-related functions (including COLORS/COLOR_PAIRS).

func Timeout

func Timeout(d time.Duration)

Sets global read timeout; if negative input will be blocking.

func UseDefaultColors

func UseDefaultColors()

UseDefaultColors enables the use of COLOR_DEFAULT.

Types

type Color

type Color int

Colors; the value of Color must be less t han COLORS().

const (
	COLOR_BLACK   Color = C.COLOR_BLACK
	COLOR_RED     Color = C.COLOR_RED
	COLOR_GREEN   Color = C.COLOR_GREEN
	COLOR_YELLOW  Color = C.COLOR_YELLOW
	COLOR_BLUE    Color = C.COLOR_BLUE
	COLOR_MAGENTA Color = C.COLOR_MAGENTA
	COLOR_CYAN    Color = C.COLOR_CYAN
	COLOR_WHITE   Color = C.COLOR_WHITE
	COLOR_DEFAULT Color = Color(-1)
)

func (Color) Content

func (c Color) Content() (int, int, int)

Content returns the rgb triplet that the Color currently represents.

func (Color) Init

func (c Color) Init(r, g, b int)

Init initializes a given color ID with the specified rgb triplet. The values of r, g, and b must be within 0 and 1000, inclusive. This method does nothing if !CanChangeColor. Changing an existing color will flush curses' screen buffer, causing a full redraw on next refresh. This method only really works iff TERM=xterm-256color (maybe others, depends heavily on termcaps).

type ColorPair

type ColorPair int

ColorPair is an id for a specific color pair (foreground/background). The value must be less than COLOR_PAIRS.

func Attrget

func Attrget() (int, ColorPair)

Get current attributes

func (ColorPair) Attribute

func (p ColorPair) Attribute() int

func (ColorPair) Content

func (p ColorPair) Content() (Color, Color)

Content returns the fore/background pair this ColorPair currently represents.

func (ColorPair) Init

func (p ColorPair) Init(fg, bg Color)

Init initializes a given color pair ID. The colors do not need to exist yet, but will likely default to black (undefined behavior). Changing an existing ColorPair will flush curses' screen buffer, causing a full redraw on next refresh.

type MouseEvent

type MouseEvent struct {
	Id      int
	X, Y, Z int
	State   MouseMask
}

func Getmouse

func Getmouse() *MouseEvent

type MouseMask

type MouseMask C.mmask_t

func Mousemask

func Mousemask(mask MouseMask) MouseMask

Enables receiving mouse input from Getch.

type Window

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

Curses window type.

var Stdscr *Window = &Window{C.stdscr}

Standard window.

func Initscr

func Initscr() *Window

Initializes curses. This function should be called before using the package.

func NewWindow

func NewWindow(height, width, starty, startx int) *Window

Create new window.

func (*Window) Addch

func (win *Window) Addch(ch int)

func (*Window) Addstr

func (win *Window) Addstr(str ...interface{})

func (*Window) Attroff

func (win *Window) Attroff(attr int)

func (*Window) Attron

func (win *Window) Attron(attr int)

func (*Window) Attrset

func (win *Window) Attrset(attr int)

func (*Window) Border

func (win *Window) Border(ls, rs, ts, bs, tl, tr, bl, br int)

Set border characters. 1. ls: character to be used for the left side of the window 2. rs: character to be used for the right side of the window 3. ts: character to be used for the top side of the window 4. bs: character to be used for the bottom side of the window 5. tl: character to be used for the top left corner of the window 6. tr: character to be used for the top right corner of the window 7. bl: character to be used for the bottom left corner of the window 8. br: character to be used for the bottom right corner of the window

func (*Window) Box

func (win *Window) Box(v, h int)

Set box lines.

func (*Window) Clear

func (win *Window) Clear()

func (*Window) Clrtoeol

func (win *Window) Clrtoeol()

Erases content from cursor to end of line inclusive.

func (*Window) Del

func (win *Window) Del()

Delete current window.

func (*Window) Erase

func (win *Window) Erase()

func (*Window) Getch

func (win *Window) Getch() int

Get char from the standard in.

func (*Window) Getmaxyx

func (win *Window) Getmaxyx() (row, col int)

Get windows sizes.

func (*Window) Idlok

func (win *Window) Idlok(bf bool)

Hardware insert/delete feature.

func (*Window) Keypad

func (win *Window) Keypad(on bool)

Enable reading of function keys.

func (*Window) Mvaddch

func (win *Window) Mvaddch(y, x int, ch int)

func (*Window) Mvaddstr

func (win *Window) Mvaddstr(y, x int, str ...interface{})

func (*Window) Refresh

func (win *Window) Refresh()

Refresh given window.

func (*Window) Scroll

func (win *Window) Scroll()

Scroll given window.

func (*Window) Scrollok

func (win *Window) Scrollok(bf bool)

Enable window scrolling.

func (*Window) Setscrreg

func (win *Window) Setscrreg(top, bot int)

func (*Window) Timeout

func (win *Window) Timeout(d time.Duration)

Sets read timeout for specific window; if negative input will block.

func (*Window) Wmove

func (win *Window) Wmove(y, x int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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