term

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2023 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package term is influenced by https://github.com/AlecAivazis/survey and https://github.com/manifoldco/promptui it might contain some code snippets from those A little copying is better than a little dependency. - Go proverbs.

Index

Constants

View Source
const (
	ArrowLeft  = rune(KeyCtrlB)
	ArrowRight = rune(KeyCtrlF)
	ArrowUp    = rune(KeyCtrlP)
	ArrowDown  = rune(KeyCtrlN)
	Space      = ' '
	Enter      = '\r'
	NewLine    = '\n'
	Backspace  = rune(KeyCtrlH)
	Backspace2 = rune(KeyDEL)
)

These are the key that aliases

Variables

This section is empty.

Functions

func Close

func Close() error

Close restores the terminal state

func DisableColor

func DisableColor()

DisableColor makes cell attributes meaningless

func Init

func Init(r Reader, w Writer) error

Init initializes the term package

Types

type BufferedReader

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

BufferedReader fullfills the io.Reader interface

func (*BufferedReader) Read

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

type BufferedWriter

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

BufferedWriter creates, clears and, moves up or down lines as needed to write the output to the terminal using ANSI escape codes.

func NewBufferedWriter

func NewBufferedWriter(w io.Writer) *BufferedWriter

NewBufferedWriter creates and initializes a new BufferedWriter.

func (*BufferedWriter) ClearScreen

func (b *BufferedWriter) ClearScreen() error

ClearScreen solves problems (R) and use it after Reset()

func (*BufferedWriter) Flush

func (b *BufferedWriter) Flush() error

Flush writes any buffered data to the underlying io.Writer, ensuring that any pending data is displayed.

func (*BufferedWriter) HideCursor

func (b *BufferedWriter) HideCursor()

HideCursor writes to os.Stdout that to hide cursor

func (*BufferedWriter) Reset

func (b *BufferedWriter) Reset()

Reset truncates the underlining buffer and marks all its previous lines to be cleared during the next Write.

func (*BufferedWriter) ShowCursor

func (b *BufferedWriter) ShowCursor()

ShowCursor writes to os.Stdout that to show cursor

func (*BufferedWriter) Write

func (b *BufferedWriter) Write(bites []byte) (int, error)

Write writes a single line to the underlining buffer.

func (*BufferedWriter) WriteCells

func (b *BufferedWriter) WriteCells(cs []Cell) (int, error)

WriteCells add colored text to the inner buffer

type Cell

type Cell struct {
	Ch   rune
	Attr []color.Attribute
}

Cell is a single character that will be drawn to the terminal

func Cprint

func Cprint(text string, attrs ...color.Attribute) []Cell

Cprint returns the text as colored cell slice

type Key

type Key int16

Key is the ascii codes of a keys

const (
	KeyCtrlSpace      Key = iota
	KeyCtrlA              // KeySOH
	KeyCtrlB              // KeySTX
	KeyCtrlC              // KeyETX
	KeyCtrlD              // KeyEOT
	KeyCtrlE              // KeyENQ
	KeyCtrlF              // KeyACK
	KeyCtrlG              // KeyBEL
	KeyCtrlH              // KeyBS
	KeyCtrlI              // KeyTAB
	KeyCtrlJ              // KeyLF
	KeyCtrlK              // KeyVT
	KeyCtrlL              // KeyFF
	KeyCtrlM              // KeyCR
	KeyCtrlN              // KeySO
	KeyCtrlO              // KeySI
	KeyCtrlP              // KeyDLE
	KeyCtrlQ              // KeyDC1
	KeyCtrlR              // KeyDC2
	KeyCtrlS              // KeyDC3
	KeyCtrlT              // KeyDC4
	KeyCtrlU              // KeyNAK
	KeyCtrlV              // KeySYN
	KeyCtrlW              // KeyETB
	KeyCtrlX              // KeyCAN
	KeyCtrlY              // KeyEM
	KeyCtrlZ              // KeySUB
	KeyESC                // KeyESC
	KeyCtrlBackslash      // KeyFS
	KeyCtrlRightSq        // KeyGS
	KeyCtrlCarat          // KeyRS
	KeyCtrlUnderscore     // KeyUS
	KeyDEL            = 0x7F
)

These are the control keys. Note that they overlap with other keys.

type Reader

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

Reader provides a minimal interface for Stdout.

type RuneReader

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

RuneReader reads from an io.Reader interface

func NewRuneReader

func NewRuneReader(reader Reader) *RuneReader

NewRuneReader creates a new instance of RuneReader

func (*RuneReader) ReadRune

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

ReadRune returns a single rune from the stdin

type Writer

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

Writer provides a minimal interface for Stdin.

Jump to

Keyboard shortcuts

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