terminal

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: Apache-2.0 Imports: 2 Imported by: 1

README

terminal - Simple Terminal manipulation methods

terminal implements various functions for doing sophisticated terminal manipulation, including cursor movement, screen erasing, and others.

Installation

go get -u laptudirm.com/x/terminal

Examples

import (
        "os"
        "laptudirm.com/x/terminal"
)

// create an *terminal.Terminal from os.Stdout
term := terminal.New(os.Stdout)

// various terminal manipulation functions
term.EraseScreen()
term.HideCursor()
term.MoveCursorHome()

// all the fmt functions are also defined
term.Print("Hello, ")
term.Println("World!")
term.Printf("PI: %d", 3.1415)

Documentation

The documentation and a comprehensive list of all the manipulation functions can be found at https://laptudirm.com/x/terminal.

References

Documentation

Index

Constants

View Source
const (
	Esc = "\x1b"
	Csi = Esc + "["
)

Constants representing escape headers.

Variables

This section is empty.

Functions

This section is empty.

Types

type Terminal

type Terminal struct {
	*os.File
}

Terminal represents a terminal supporting ansi escape sequences.

func New added in v0.2.0

func New(w *os.File) *Terminal

New creates an instance of a Terminal from the given *os.File.

func (*Terminal) DisableAlternateBuffer

func (t *Terminal) DisableAlternateBuffer()

DisableAlternateBuffer disables the alternate screen buffer.

func (*Terminal) EnableAlternateBuffer

func (t *Terminal) EnableAlternateBuffer()

EnableAlternateBuffer enables the alternate screen buffer.

func (*Terminal) EraseLine

func (t *Terminal) EraseLine()

EraseLine erases the entire current line.

func (*Terminal) EraseScreen

func (t *Terminal) EraseScreen()

EraseScreen erases the entire screen.

func (*Terminal) EraseTillLineBeginning

func (t *Terminal) EraseTillLineBeginning()

EraseTillLineBeginning erases everything from the cursor to the beginning of the current line.

func (*Terminal) EraseTillLineEnd

func (t *Terminal) EraseTillLineEnd()

EraseTillLineEnd erases everything from the cursor to the end of the current line.

func (*Terminal) EraseTillScreenBeginning

func (t *Terminal) EraseTillScreenBeginning()

EraseTillScreenBeginning erases everything from the cursor to the beginning of the screen.

func (*Terminal) EraseTillScreenEnd

func (t *Terminal) EraseTillScreenEnd()

EraseTillScreenEnd erases everything from the cursor to the end of the screen.

func (*Terminal) HideCursor

func (t *Terminal) HideCursor()

HideCursor makes the cursor invisible on the screen.

func (*Terminal) MoveCursor

func (t *Terminal) MoveCursor(line, column int)

MoveCursor moves the cursor to the given line and column.

func (*Terminal) MoveCursorDown

func (t *Terminal) MoveCursorDown(lines int)

MoveCursorDown moves the cursor down by the given amount of lines.

func (*Terminal) MoveCursorHome

func (t *Terminal) MoveCursorHome()

MoveCursorHome moves the cursor to it's home(0,0) position.

func (*Terminal) MoveCursorLeft

func (t *Terminal) MoveCursorLeft(columns int)

MoveCursorLeft moves te cursor left by the given amount of columns.

func (*Terminal) MoveCursorRight

func (t *Terminal) MoveCursorRight(columns int)

MoveCursorRight moves the cursor right by the given amount of columns.

func (*Terminal) MoveCursorToColumn

func (t *Terminal) MoveCursorToColumn(column int)

MoveCursorToColumn moves the cursor to the given column.

func (*Terminal) MoveCursorUp

func (t *Terminal) MoveCursorUp(lines int)

MoveCursorUp moves the cursor up by the given amount of lines.

func (*Terminal) Print

func (t *Terminal) Print(a ...any) (int, error)

Print acts like the fmt.Fprint function on a Terminal io.Writer.

func (*Terminal) PrintCSI

func (t *Terminal) PrintCSI(format string, a ...any)

PrintCSI prints the given escape sequence appended to a CSI(ESC [) escape header.

func (*Terminal) Printf

func (t *Terminal) Printf(format string, a ...any) (int, error)

Printf acts like the fmt.Fprintf function on a Terminal io.Writer.

func (*Terminal) Println

func (t *Terminal) Println(a ...any) (int, error)

Println acts like the fmt.Fprintln function on a Terminal io.Writer.

func (*Terminal) RestoreCursorPosition

func (t *Terminal) RestoreCursorPosition()

Restore cursor position restores the cursor to the most recently saved position.

func (*Terminal) RestoreScreen

func (t *Terminal) RestoreScreen()

RestoreScreen restores the saved screen back state into the terminal.

func (*Terminal) SaveCursorPosition

func (t *Terminal) SaveCursorPosition()

SaveCursorPosition saves the current position of the cursor.

func (*Terminal) SaveScreen

func (t *Terminal) SaveScreen()

SaveScreen saves the state of the current screen of the terminal.

func (*Terminal) ShowCursor

func (t *Terminal) ShowCursor()

ShowCursor makes the cursor visible on the screen.

Jump to

Keyboard shortcuts

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