twin

package
v1.9.9 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2022 License: BSD-2-Clause-Views Imports: 10 Imported by: 1

Documentation

Overview

Package twin provides Terminal Window interaction

Package twin provides Terminal Window interaction

Index

Constants

This section is empty.

Variables

View Source
var ColorDefault = newColor(colorTypeDefault, 0)

Reset to default foreground / background color

View Source
var MOUSE_EVENT_REGEX = regexp.MustCompile("^\x1b\\[<([0-9]+);([0-9]+);([0-9]+)M")

Example event: "\x1b[<65;127;41M"

Where:

* "\x1b[<" says this is a mouse event

* "65" says this is Wheel Up. "64" would be Wheel Down.

* "127" is the column number on screen, "1" is the first column.

* "41" is the row number on screen, "1" is the first row.

* "M" marks the end of the mouse event.

Functions

This section is empty.

Types

type AttrMask

type AttrMask uint
const (
	AttrBold AttrMask = 1 << iota
	AttrBlink
	AttrReverse
	AttrUnderline
	AttrDim
	AttrItalic
	AttrStrikeThrough
	AttrNone AttrMask = 0 // Normal text
)

type Cell

type Cell struct {
	Rune  rune
	Style Style
}

Cell is a rune with a style to be written to a cell on screen

func NewCell

func NewCell(rune rune, style Style) Cell

func TrimSpaceLeft added in v1.7.1

func TrimSpaceLeft(cells []Cell) []Cell

Returns a slice of cells with leading whitespace cells removed

func TrimSpaceRight added in v1.7.1

func TrimSpaceRight(cells []Cell) []Cell

Returns a slice of cells with trailing whitespace cells removed

func (Cell) String

func (cell Cell) String() string

type Color

type Color uint32

Create using NewColor16(), NewColor256 or NewColor24Bit(), or use ColorDefault.

func NewColor16

func NewColor16(colorNumber0to15 int) Color

Four bit colors as defined here: https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit

func NewColor24Bit

func NewColor24Bit(red uint8, green uint8, blue uint8) Color

func NewColor256

func NewColor256(colorNumber uint8) Color

func NewColorHex

func NewColorHex(rgb uint32) Color

func (Color) BackgroundAnsiString

func (color Color) BackgroundAnsiString() string

func (Color) ForegroundAnsiString

func (color Color) ForegroundAnsiString() string

func (Color) String

func (color Color) String() string

type ColorType

type ColorType uint8

type Event

type Event interface {
}

type EventKeyCode

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

func (*EventKeyCode) KeyCode

func (eventKeyCode *EventKeyCode) KeyCode() KeyCode

type EventMouse

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

func (*EventMouse) Buttons

func (eventMouse *EventMouse) Buttons() MouseButtonMask

type EventResize

type EventResize struct {
}

After you get this, query Screen.Size() to get the new size

type EventRune

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

func (*EventRune) Rune

func (eventRune *EventRune) Rune() rune

type FakeScreen

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

Used for testing.

Try GetRow() after some SetCell() calls to see what you got.

func NewFakeScreen

func NewFakeScreen(width int, height int) *FakeScreen

func (*FakeScreen) Clear

func (screen *FakeScreen) Clear()

func (*FakeScreen) Close

func (screen *FakeScreen) Close()

func (*FakeScreen) Events

func (screen *FakeScreen) Events() chan Event

func (*FakeScreen) GetRow

func (screen *FakeScreen) GetRow(row int) []Cell

func (*FakeScreen) SetCell

func (screen *FakeScreen) SetCell(column int, row int, cell Cell)

func (*FakeScreen) Show

func (screen *FakeScreen) Show()

func (*FakeScreen) ShowCursorAt

func (screen *FakeScreen) ShowCursorAt(column int, row int)

func (*FakeScreen) ShowNLines added in v1.8.4

func (screen *FakeScreen) ShowNLines(int)

func (*FakeScreen) Size

func (screen *FakeScreen) Size() (width int, height int)

type KeyCode

type KeyCode uint16
const (
	KeyEscape KeyCode = iota
	KeyEnter

	KeyBackspace
	KeyDelete

	KeyUp
	KeyDown
	KeyRight
	KeyLeft

	KeyHome
	KeyEnd
	KeyPgUp
	KeyPgDown
)

type MouseButtonMask

type MouseButtonMask uint16
const (
	MouseWheelUp MouseButtonMask = 1 << iota
	MouseWheelDown
	MouseWheelLeft
	MouseWheelRight
)

type Screen

type Screen interface {
	// Close() restores terminal to normal state, must be called after you are
	// done with your screen
	Close()

	Clear()

	SetCell(column int, row int, cell Cell)

	// Render our contents into the terminal window
	Show()

	// Can be called after Close()ing the screen to fake retaining its output.
	// Plain Show() is what you'd call during normal operation.
	ShowNLines(lineCountToShow int)

	// Returns screen width and height.
	//
	// NOTE: Never cache this response! On window resizes you'll get an
	// EventResize on the Screen.Events channel, and this method will start
	// returning the new size instead.
	Size() (width int, height int)

	// ShowCursorAt() moves the cursor to the given screen position and makes
	// sure it is visible.
	//
	// If the position is outside of the screen, the cursor will be hidden.
	ShowCursorAt(column int, row int)

	// This channel is what your main loop should be checking.
	Events() chan Event
}

func NewScreen

func NewScreen() (Screen, error)

NewScreen() requires Close() to be called after you are done with your new screen, most likely somewhere in your shutdown code.

type Style

type Style struct {
	// contains filtered or unexported fields
}
var StyleDefault Style

func (Style) Background

func (style Style) Background(color Color) Style

func (Style) Foreground

func (style Style) Foreground(color Color) Style

func (Style) RenderUpdateFrom

func (current Style) RenderUpdateFrom(previous Style) string

Emit an ANSI escape sequence switching from a previous style to the current one.

func (Style) String

func (style Style) String() string

func (Style) WithAttr

func (style Style) WithAttr(attr AttrMask) Style

func (Style) WithoutAttr

func (style Style) WithoutAttr(attr AttrMask) Style

type UnixScreen

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

func (*UnixScreen) Clear

func (screen *UnixScreen) Clear()

func (*UnixScreen) Close

func (screen *UnixScreen) Close()

Close() restores terminal to normal state, must be called after you are done with the screen returned by NewScreen()

func (*UnixScreen) Events

func (screen *UnixScreen) Events() chan Event

func (*UnixScreen) SetCell

func (screen *UnixScreen) SetCell(column int, row int, cell Cell)

func (*UnixScreen) Show

func (screen *UnixScreen) Show()

func (*UnixScreen) ShowCursorAt

func (screen *UnixScreen) ShowCursorAt(column int, row int)

ShowCursorAt() moves the cursor to the given screen position and makes sure it is visible.

If the position is outside of the screen, the cursor will be hidden.

func (*UnixScreen) ShowNLines added in v1.8.4

func (screen *UnixScreen) ShowNLines(height int)

func (*UnixScreen) Size

func (screen *UnixScreen) Size() (width int, height int)

Returns screen width and height.

NOTE: Never cache this response! On window resizes you'll get an EventResize on the Screen.Events channel, and this method will start returning the new size instead.

Jump to

Keyboard shortcuts

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