termio

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const BACKSPACE uint16 = 0x08

BACKSPACE is the backspace

View Source
const BACKTAB uint16 = 0x5b5a

BACKTAB indicates shift + tab

View Source
const CARRIAGE_RETURN uint16 = 0x0D

CARRIAGE_RETURN indicates "enter"

View Source
const CURSOR_DOWN uint16 = 0x5b42

CURSOR_DOWN (down arrow)

View Source
const CURSOR_LEFT uint16 = 0x5b43

CURSOR_LEFT (left arrow)

View Source
const CURSOR_RIGHT uint16 = 0x5b44

CURSOR_RIGHT (left arrow)

View Source
const CURSOR_UP uint16 = 0x5b41

CURSOR_UP (up arrow)

View Source
const DEL uint16 = 0x7f

DEL is the delete key

View Source
const ESC uint16 = 0x1b

ESC is the escape code.

View Source
const SCROLL_DOWN uint16 = 0x5b54

SCROLL_DOWN (page down)

View Source
const SCROLL_UP uint16 = 0x5b53

SCROLL_UP (page up)

View Source
const TAB uint16 = 0x09

TAB indicates the horizontal tab

View Source
const TERM_BLACK = uint(0)

TERM_BLACK represents black

View Source
const TERM_BLUE = uint(4)

TERM_BLUE represents blue

View Source
const TERM_CYAN = uint(6)

TERM_CYAN represents cyan

View Source
const TERM_GREEN = uint(2)

TERM_GREEN represents green

View Source
const TERM_MAGENTA = uint(5)

TERM_MAGENTA represents magenta

View Source
const TERM_RED = uint(1)

TERM_RED represents red

View Source
const TERM_WHITE = uint(7)

TERM_WHITE represents white

View Source
const TERM_YELLOW = uint(3)

TERM_YELLOW represents yellow

View Source
const UNKNOWN uint16 = 0x5bff

UNKNOWN is a fall-back for unknown escape sequences

Variables

This section is empty.

Functions

This section is empty.

Types

type AnsiEscape

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

AnsiEscape represents an ANSI escape code used for formatting text in a terminal.

func BoldAnsiEscape

func BoldAnsiEscape() AnsiEscape

BoldAnsiEscape constructs a reset term.

func NewAnsiEscape

func NewAnsiEscape() AnsiEscape

NewAnsiEscape construct an empty escape

func ResetAnsiEscape

func ResetAnsiEscape() AnsiEscape

ResetAnsiEscape constructs a reset term.

func UnderlineAnsiEscape

func UnderlineAnsiEscape() AnsiEscape

UnderlineAnsiEscape constructs a reset term.

func (AnsiEscape) Bg256Colour

func (p AnsiEscape) Bg256Colour(col uint) AnsiEscape

Bg256Colour sets the background colour using 256-colour mode.

func (AnsiEscape) BgColour

func (p AnsiEscape) BgColour(col uint) AnsiEscape

BgColour sets the foreground colour

func (AnsiEscape) Build

func (p AnsiEscape) Build() string

Build constructs the final escape

func (AnsiEscape) Fg256Colour

func (p AnsiEscape) Fg256Colour(col uint) AnsiEscape

Fg256Colour sets the foreground colour using 256-colour mode.

func (AnsiEscape) FgColour

func (p AnsiEscape) FgColour(col uint) AnsiEscape

FgColour sets the foreground colour

type Canvas

type Canvas interface {
	// Get the dimensions of this canvas.
	GetDimensions() (uint, uint)
	// Write a chunk to the canvas.
	Write(x, y uint, text FormattedText)
}

Canvas represents a surface on which widgets can draw.

type FormattedText

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

FormattedText represents, as the name suggests, a chunk of formatted text.

func NewColouredText

func NewColouredText(text string, colour uint) FormattedText

NewColouredText constructs a new (coloured) chunk of text.

func NewFormattedText

func NewFormattedText(text string, format AnsiEscape) FormattedText

NewFormattedText constructs a new chunk of text with a given format.

func NewText

func NewText(text string) FormattedText

NewText constructs a new (unformatted) chunk of text.

func (*FormattedText) Bytes

func (p *FormattedText) Bytes() []byte

Bytes returns an ANSI-formatted byte representing of this chunk.

func (*FormattedText) ClearFormat

func (p *FormattedText) ClearFormat()

ClearFormat clears any formatting for this chunk of text.

func (*FormattedText) Clip

func (p *FormattedText) Clip(start uint, end uint)

Clip removes text from the start and end.

func (*FormattedText) Format

func (p *FormattedText) Format(format AnsiEscape)

Format sets the format for this chunk of text.

func (*FormattedText) Len

func (p *FormattedText) Len() uint

Len returns the number of characters [runes] in this chunk of formatted text. Observe that this does not include characters arising from the formatting escapes.

type Terminal

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

Terminal provides a simple top-level window.

func NewTerminal

func NewTerminal() (*Terminal, error)

NewTerminal constructs a new terminal.

func (*Terminal) Add

func (t *Terminal) Add(w Widget)

Add a new widget to this window. Widgets will be laid out vertically in the order they are added.

func (*Terminal) GetSize

func (t *Terminal) GetSize() (uint, uint)

GetSize returns the dimensions of the terminal.

func (*Terminal) ReadKey

func (t *Terminal) ReadKey() (uint16, error)

ReadKey returns a keyevent from the keyboard. This is either an ASCII character, or an extended escape code.

func (*Terminal) Render

func (t *Terminal) Render() error

Render this window to the terminal.

func (*Terminal) Restore

func (t *Terminal) Restore() error

Restore terminal to its original state.

type Widget

type Widget interface {
	// Get height of this widget, where MaxUint indicates widget expands to take
	// as much as it can.
	GetHeight() uint
	// Render this widget on the given canvas.
	Render(canvas Canvas)
}

Widget is an abstract entity which can be displayed upon a terminal window.

type Window

type Window interface {
	// Add a new widget to this window.  Widgets will be laid out vertically in
	// the order they are added.
	Add(w Widget)
	// Render this window to the terminal.
	Render() error
}

Window provides an abstraction over an interactive terminal session. This is fairly simplistic at this stage, and supports layout of widges in a vertical direction only.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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