termy

package module
v0.1.2-beta Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: GPL-3.0 Imports: 7 Imported by: 0

README ΒΆ

Termy πŸ“Ί

(pronounced tˈɜːmi)

PKG Termy facilitates access to basic (terminal emulator's) functionality.


termy.go allows you to put your terminal in non-cooked modes.

package main

import "github.com/mec-nyan/termy"


func main() {

	t := termy.New(int(os.Stdin.Fd()), false)
	err := t.Cbreaky()
	if err != nil {
		...
	}
	defer t.Restore()

	// Your code...

}

escapy.go provides function to send in-band control sequences to your terminal.

func main() {

	// ...

	termy.SaveCurPos() // Save current cursor position.


	// Do stuff.

	termy.RestoreCurPos() // Go back to saved position.
	termy.ClearToEOS()    // Clean up.

	// ...
}

TODO: I'll soon add capabilities for styles, colours, etc.

Documentation ΒΆ

Overview ΒΆ

escapy.go These are standalone versions of the cursor manipulation functions. They write directly to os.Stdout.

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func ClearScreen ΒΆ

func ClearScreen()

func ClearToBOL ΒΆ

func ClearToBOL()

func ClearToEOL ΒΆ

func ClearToEOL()

func ClearToEOS ΒΆ

func ClearToEOS()

func CurToCol ΒΆ

func CurToCol(col int)

func CurToRow ΒΆ

func CurToRow(row int)

func Down ΒΆ

func Down()

func EnterCaMode ΒΆ

func EnterCaMode()

func ExitCaMode ΒΆ

func ExitCaMode()

func HideCur ΒΆ

func HideCur()

func Home ΒΆ

func Home()

func Left ΒΆ

func Left()

func MoveDown ΒΆ

func MoveDown(lines int)

func MoveLeft ΒΆ

func MoveLeft(lines int)

func MoveRight ΒΆ

func MoveRight(lines int)

func MoveTo ΒΆ

func MoveTo(row, col int)

func MoveUp ΒΆ

func MoveUp(lines int)

func RestoreCurPos ΒΆ

func RestoreCurPos()
func Right()

func SaveCurPos ΒΆ

func SaveCurPos()

func ShowCur ΒΆ

func ShowCur()

func Up ΒΆ

func Up()

Types ΒΆ

type TermSettings ΒΆ

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

func New ΒΆ

func New(fd int, echo bool) *TermSettings

New creates an instance of TermSettings to handle the terminal state. fd: file descriptor (as in os.Stdout.Fd()), echo: Set to false to disable automatic echoing of user input.

func (*TermSettings) Cbreaky ΒΆ

func (ts *TermSettings) Cbreaky() error

Cbreaky set the terminal (actually, STDIN) in a cbreak-like mode. Accepts an optional bool to disable echo as well. On success it saves the original state so you can retore it later. Example usage:

term := termy.New(int(os.Stdin.Fd()), false) err := term.Cbreaky() if err != nil ... defer term.Restore()

func (*TermSettings) Restore ΒΆ

func (ts *TermSettings) Restore() error

Restore sets the terminal to its previous state. It returns an error if the previous state was not saved. Tipically you will call Restore after Cbreaky (probably with `defer`)

func (*TermSettings) Size ΒΆ

func (ts *TermSettings) Size() (rows, cols int, err error)

TODO: Should size be part of "Termy"? TODO: How should we handle "resize"?

type Termy ΒΆ

type Termy struct {
	colours.Colour
	styles.Style
	// contains filtered or unexported fields
}

Termy struct handles in-band colour and style commands for its tty. tty would normally be os.Stdout.

func NewTermy ΒΆ

func NewTermy(w io.Writer) *Termy

NewTermy sets up a new Termy struct to handle in-band signalling to the selected io.Writer.

func (*Termy) ClearScreen ΒΆ

func (t *Termy) ClearScreen()

Clear the screen and move the cursor to the upper left corner.

func (*Termy) ClearToBOL ΒΆ

func (t *Termy) ClearToBOL()

Clear to the beginning of line.

func (*Termy) ClearToEOL ΒΆ

func (t *Termy) ClearToEOL()

Clear to end of line.

func (*Termy) ClearToEOS ΒΆ

func (t *Termy) ClearToEOS()

Clear to end of screen.

func (*Termy) Code ΒΆ

func (t *Termy) Code() string

Code generates the code for the currently selected colours and/or style. It doesn't prepend the CSI.

func (*Termy) CurToCol ΒΆ

func (t *Termy) CurToCol(col int)

Move cursor to column "col".

func (*Termy) CurToRow ΒΆ

func (t *Termy) CurToRow(row int)

Move cursor to row "row".

func (*Termy) Down ΒΆ

func (t *Termy) Down()

Move cursor down one row.

func (*Termy) EnterCaMode ΒΆ

func (t *Termy) EnterCaMode()

Enter alt buffer mode.

func (*Termy) Escaped ΒΆ

func (t *Termy) Escaped() string

Escaped converts the colour and style sequence in an in-band command. prepending the CSI and appending a terminator string.

func (*Termy) ExitCaMode ΒΆ

func (t *Termy) ExitCaMode()

Exit alt buffer mode.

func (*Termy) HideCur ΒΆ

func (t *Termy) HideCur()

Make cursor invisible.

func (*Termy) Home ΒΆ

func (t *Termy) Home()

Cursor manipulation:

Home moves the cursor to the top left corner of the terminal.

func (*Termy) Left ΒΆ

func (t *Termy) Left()

Move cursor one column to the left.

func (*Termy) MoveDown ΒΆ

func (t *Termy) MoveDown(lines int)

Move cursor "lines" rows down.

func (*Termy) MoveLeft ΒΆ

func (t *Termy) MoveLeft(cols int)

Move cursor "cols" columns to the left.

func (*Termy) MoveRight ΒΆ

func (t *Termy) MoveRight(cols int)

Move cursor "cols" columns to the right.

func (*Termy) MoveTo ΒΆ

func (t *Termy) MoveTo(x, y int)

Move cursor to line "y" col "x"

func (*Termy) MoveUp ΒΆ

func (t *Termy) MoveUp(lines int)

Move cursor "lines" rows up.

func (*Termy) RestoreCurPos ΒΆ

func (t *Termy) RestoreCurPos()

Restore the cursor position to a previously saved one.

func (*Termy) Right ΒΆ

func (t *Termy) Right()

Move cursor one column to the right.

func (*Termy) SaveCurPos ΒΆ

func (t *Termy) SaveCurPos()

Save the current cursor position.

func (*Termy) Send ΒΆ

func (t *Termy) Send()

Send actually sends the in-band signal to the terminal/selected writer.

func (*Termy) ShowCur ΒΆ

func (t *Termy) ShowCur()

Make cursor visible.

func (*Termy) Up ΒΆ

func (t *Termy) Up()

Move cursor up one row.

Directories ΒΆ

Path Synopsis
Package colours generate the colour codes to be embedded in a colour escape sequence.
Package colours generate the colour codes to be embedded in a colour escape sequence.
Package styles serves to generate the sequence to signal in-band styles to the terminal.
Package styles serves to generate the sequence to signal in-band styles to the terminal.

Jump to

Keyboard shortcuts

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