terminal

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0, MIT, MIT Imports: 11 Imported by: 0

README

survey/terminal

This package started as a copy of kokuban/go-ansi but has since been modified to fit survey's specific needs.

Documentation

Index

Constants

View Source
const (
	EVENT_KEY = 0x0001

	// key codes for arrow keys
	// https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
	VK_DELETE = 0x2E
	VK_END    = 0x23
	VK_HOME   = 0x24
	VK_LEFT   = 0x25
	VK_UP     = 0x26
	VK_RIGHT  = 0x27
	VK_DOWN   = 0x28

	RIGHT_CTRL_PRESSED = 0x0004
	LEFT_CTRL_PRESSED  = 0x0008

	ENABLE_ECHO_INPUT      uint32 = 0x0004
	ENABLE_LINE_INPUT      uint32 = 0x0002
	ENABLE_PROCESSED_INPUT uint32 = 0x0001
)
View Source
const (
	KeyArrowLeft       = '\x02'
	KeyArrowRight      = '\x06'
	KeyArrowUp         = '\x10'
	KeyArrowDown       = '\x0e'
	KeySpace           = ' '
	KeyEnter           = '\r'
	KeyBackspace       = '\b'
	KeyDelete          = '\x7f'
	KeyInterrupt       = '\x03'
	KeyEndTransmission = '\x04'
	KeyEscape          = '\x1b'
	KeyDeleteWord      = '\x17' // Ctrl+W
	KeyDeleteLine      = '\x18' // Ctrl+X
	SpecialKeyHome     = '\x01'
	SpecialKeyEnd      = '\x11'
	SpecialKeyDelete   = '\x12'
	IgnoreKey          = '\000'
	KeyTab             = '\t'
)

Variables

View Source
var (
	//lint:ignore ST1012 keeping old name for backwards compatibility
	InterruptErr = errors.New("interrupt")
)

Functions

func EraseLine

func EraseLine(out FileWriter, mode EraseLineMode) error

func NewAnsiStderr

func NewAnsiStderr(out FileWriter) io.Writer

func NewAnsiStdout

func NewAnsiStdout(out FileWriter) io.Writer

func StringWidth

func StringWidth(str string) int

StringWidth returns the visible width of a string when printed to the terminal

Types

type BufferedReader

type BufferedReader struct {
	In     io.Reader
	Buffer *bytes.Buffer
}

func (*BufferedReader) Read

func (br *BufferedReader) Read(p []byte) (int, error)

type Coord

type Coord struct {
	X Short
	Y Short
}

func (Coord) CursorIsAtLineBegin

func (cur Coord) CursorIsAtLineBegin() bool

func (Coord) CursorIsAtLineEnd

func (cur Coord) CursorIsAtLineEnd(size *Coord) bool

type Cursor

type Cursor struct {
	In  FileReader
	Out FileWriter
}

func (*Cursor) Back

func (c *Cursor) Back(n int) error

func (*Cursor) Down

func (c *Cursor) Down(n int) error

func (*Cursor) Forward

func (c *Cursor) Forward(n int) error

func (*Cursor) Hide

func (c *Cursor) Hide() error

func (*Cursor) HorizontalAbsolute

func (c *Cursor) HorizontalAbsolute(x int) error

func (*Cursor) Location

func (c *Cursor) Location(buf *bytes.Buffer) (*Coord, error)

func (*Cursor) MoveNextLine

func (c *Cursor) MoveNextLine(cur *Coord, terminalSize *Coord) error

for comparability purposes between windows in windows we don't have to print out a new line

func (*Cursor) NextLine

func (c *Cursor) NextLine(n int) error

func (*Cursor) PreviousLine

func (c *Cursor) PreviousLine(n int) error

func (*Cursor) Restore

func (c *Cursor) Restore() error

func (*Cursor) Save

func (c *Cursor) Save() error

save the cursor location

func (*Cursor) Show

func (c *Cursor) Show() error

func (*Cursor) Size

func (c *Cursor) Size(buf *bytes.Buffer) (*Coord, error)

func (*Cursor) Up

func (c *Cursor) Up(n int) error

type EraseLineMode

type EraseLineMode int
const (
	ERASE_LINE_END EraseLineMode = iota
	ERASE_LINE_START
	ERASE_LINE_ALL
)

type FileReader

type FileReader interface {
	io.Reader
	Fd() uintptr
}

FileReader provides a minimal interface for Stdout.

type FileWriter

type FileWriter interface {
	io.Writer
	Fd() uintptr
}

FileWriter provides a minimal interface for Stdin.

type OnRuneFn

type OnRuneFn func(rune, []rune) ([]rune, bool, error)

type RuneReader

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

func NewRuneReader

func NewRuneReader(stdio Stdio) *RuneReader

func (*RuneReader) Buffer

func (rr *RuneReader) Buffer() *bytes.Buffer

func (*RuneReader) ReadLine

func (rr *RuneReader) ReadLine(mask rune, onRunes ...OnRuneFn) ([]rune, error)

func (*RuneReader) ReadLineWithDefault

func (rr *RuneReader) ReadLineWithDefault(mask rune, d []rune, onRunes ...OnRuneFn) ([]rune, error)

func (*RuneReader) ReadRune

func (rr *RuneReader) ReadRune() (rune, int, error)

func (*RuneReader) RestoreTermMode

func (rr *RuneReader) RestoreTermMode() error

func (*RuneReader) SetTermMode

func (rr *RuneReader) SetTermMode() error

type Short

type Short int16
var COORDINATE_SYSTEM_BEGIN Short = 0

type Stdio

type Stdio struct {
	In  FileReader
	Out FileWriter
	Err io.Writer
}

Stdio is the standard input/output the terminal reads/writes with.

type Writer

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

func (*Writer) Write

func (w *Writer) Write(data []byte) (n int, err error)

Jump to

Keyboard shortcuts

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