termio

package
v0.0.0-...-e0712e5 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrReadTimedOut = errors.New("read timed out")
	ErrReadClosing  = errors.New("termio closing")
)

Functions

func RuneWidth

func RuneWidth(ch rune) int

RuneWidth returns the width in the number of characters of a given rune.

func StringWidth

func StringWidth(s string) int

RuneWidth returns the width in the number of characters of a given string.

Types

type ByteAndError

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

type MockTerm

type MockTerm struct {
	mock.Mock
}

func (*MockTerm) CanWrite

func (m *MockTerm) CanWrite() bool

func (*MockTerm) CanWriteChars

func (m *MockTerm) CanWriteChars(charWidth int) bool

func (*MockTerm) Clear

func (m *MockTerm) Clear()

func (*MockTerm) Finish

func (m *MockTerm) Finish()

func (*MockTerm) Flush

func (m *MockTerm) Flush() error

func (*MockTerm) Height

func (m *MockTerm) Height() int

func (*MockTerm) MoveTo

func (m *MockTerm) MoveTo(newX, newY int)

func (*MockTerm) NewLine

func (m *MockTerm) NewLine() bool

func (*MockTerm) ReadByteTimeout

func (m *MockTerm) ReadByteTimeout(timeout time.Duration) (byte, error)

func (*MockTerm) Tab

func (m *MockTerm) Tab()

func (*MockTerm) Width

func (m *MockTerm) Width() int

func (*MockTerm) WriteRune

func (m *MockTerm) WriteRune(ch rune) bool

func (*MockTerm) WriteString

func (m *MockTerm) WriteString(s string) bool

func (*MockTerm) WriteZeroWidthBytes

func (m *MockTerm) WriteZeroWidthBytes(bytes []byte)

func (*MockTerm) WriteZeroWidthString

func (m *MockTerm) WriteZeroWidthString(s string)

type Term

type Term interface {
	// Width returns the terminal width.
	Width() int

	// Height returns the terminal height.
	Height() int

	// Clear clears the internal buffer, but it won't flush. Clear also refreshes the terminal size.
	Clear()

	// Flush flushes the internal buffer to the output terminal.
	Flush() error

	// Finish cleans up the terminal and restores the original state.
	Finish()

	// WriteZeroWidthString writes a string to the internal buffer without moving the cursor.
	WriteZeroWidthString(s string)

	// WriteZeroWidthBytes writes a byte array to the internal buffer without moving the cursor.
	WriteZeroWidthBytes(bytes []byte)

	// MoveTo moves the cursor to a given position.
	MoveTo(newX, newY int)

	// Tab moves the cursor to the next tab position.
	Tab()

	// Can write returns whether to be able to write anything at the cursor position without overflowing the terminal.
	CanWrite() bool

	// Can write returns whether to be able to write a char of a given width at the cursor position without overflowing the terminal.
	CanWriteChars(charWidth int) bool

	// NewLine moves the cursor to the beginning of the next line.
	NewLine() bool

	// WriteString writes a string to the internal buffer and moves the cursor.
	WriteString(s string) bool

	// WriteString writes a rune to the internal buffer and moves the cursor.
	WriteRune(ch rune) bool

	// ReadByteTimeout reads a byte from terminal with a timeout.
	ReadByteTimeout(timeout time.Duration) (byte, error)
}

func NewTerm

func NewTerm(in, out *os.File, forcedWidth, forcedHeight int) (Term, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳