Documentation
¶
Index ¶
- Constants
- Variables
- func BeginBuffer()
- func DisableBracketedPaste()
- func EnableBracketedPaste()
- func EndBuffer()
- func FlushBuffer()
- func GetLength() int
- func GetSize(fd int) (width, height int, err error)
- func GetWidth() (termWidth int)
- func IsTerminal(fd int) bool
- func MoveCursorBackwards(i int)
- func MoveCursorDown(i int)
- func MoveCursorForwards(i int)
- func MoveCursorUp(i int)
- func Printf(format string, a ...interface{})
- func Restore(fd int, state *State) error
- func WriteString(s string)
- type State
Constants ¶
const ( NewlineReturn = "\r\n" ClearLineAfter = "\x1b[0K" ClearLineBefore = "\x1b[1K" ClearLine = "\x1b[2K" ClearScreenBelow = "\x1b[0J" ClearScreen = "\x1b[2J" // Clears screen, preserving scroll buffer ClearDisplay = "\x1b[3J" // Clears screen fully, wipes the scroll buffer CursorTopLeft = "\x1b[H" SaveCursorPos = "\x1b7" RestoreCursorPos = "\x1b8" HideCursor = "\x1b[?25l" ShowCursor = "\x1b[?25h" BracketedPasteStart = "\x1b[?2004h" BracketedPasteEnd = "\x1b[?2004l" )
Terminal control sequences.
Variables ¶
var ( ArrowUp = string([]byte{27, 91, 65}) // ^[[A ArrowDown = string([]byte{27, 91, 66}) // ^[[B ArrowRight = string([]byte{27, 91, 67}) // ^[[C ArrowLeft = string([]byte{27, 91, 68}) // ^[[D )
Some core keys needed by some stuff.
Functions ¶
func BeginBuffer ¶ added in v1.2.0
func BeginBuffer()
BeginBuffer starts buffering terminal writes. Calls nest: only the outermost BeginBuffer/EndBuffer pair allocates and flushes the buffer, so render entrypoints can be wrapped independently without coordinating.
func DisableBracketedPaste ¶ added in v1.1.4
func DisableBracketedPaste()
DisableBracketedPaste disables bracketed paste mode.
func EnableBracketedPaste ¶ added in v1.1.4
func EnableBracketedPaste()
EnableBracketedPaste enables bracketed paste mode.
func EndBuffer ¶ added in v1.2.0
func EndBuffer()
EndBuffer flushes and tears down the buffer when leaving the outermost frame. It is safe to call unmatched (it no-ops at depth 0), so it can be deferred even if BeginBuffer is on an early-return path.
func FlushBuffer ¶ added in v1.2.0
func FlushBuffer()
FlushBuffer pushes everything buffered so far to the terminal without ending the frame. It must be called before any operation that READS the terminal and depends on prior output being on screen — chiefly an ESC[6n cursor-position query (see GetCursorPos): otherwise the prompt would still sit in the buffer and the reported cursor position would be wrong.
func GetLength ¶
func GetLength() int
GetLength returns the length of the terminal (Y length), or 80 if it cannot be established.
func GetWidth ¶
func GetWidth() (termWidth int)
GetWidth returns the width of the terminal or 80 if it cannot be established.
func IsTerminal ¶
IsTerminal returns true if the given file descriptor is a terminal.
func MoveCursorBackwards ¶
func MoveCursorBackwards(i int)
MoveCursorBackwards moves the cursor backward i columns.
func MoveCursorForwards ¶
func MoveCursorForwards(i int)
MoveCursorForwards moves the cursor forward i columns.
func Printf ¶ added in v1.2.0
func Printf(format string, a ...interface{})
Printf formats and writes to the terminal, honouring the frame buffer.
func Restore ¶
Restore restores the terminal connected to the given file descriptor to a previous state.
func WriteString ¶ added in v1.2.0
func WriteString(s string)
WriteString writes s to the terminal: into the frame buffer when one is active, otherwise straight to the output. Empty strings are dropped so callers need not guard.