ansi

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: MPL-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package ansi provides helper functions for writing ANSI terminal escape codes.

Index

Constants

View Source
const (
	// SaveCursorPosition saves the current cursor position.
	SaveCursorPosition = "\u001b7"
	// RestoreCursorPosition restores the cursor position to the saved position.
	RestoreCursorPosition = "\u001b8"
)

Variables

This section is empty.

Functions

func ClearLine

func ClearLine(method ClearLineMethod) string

ClearLine clears the current line according to the given method. The cursor position within the line does not change.

func ClearScreen

func ClearScreen(method ClearScreenMethod) string

ClearScreen clears the screen according to the given method.

func MoveCursorLeft

func MoveCursorLeft(n int) string

MoveCursorLeft moves the cursor left n cells. If the cursor is already at the edge of the screen it has no effect. If n is negative it moves to the right instead.

func MoveCursorRight

func MoveCursorRight(n int) string

MoveCursorRight moves the cursor right n cells. If the cursor is already at the edge of the screen it has no effect. If n is negative it moves to the left instead.

func SetCursorPosition

func SetCursorPosition(row, col int) string

SetCursorPosition returns the ANSI escape code for setting the cursor position. The rows and columns are one-based. If <=0 they default to the first row/column.

Types

type ClearLineMethod

type ClearLineMethod int
const (
	CursorToEnd   ClearLineMethod = 0 // cursor to end of line
	CursorToStart ClearLineMethod = 1 // cursor to start of line
	WholeLine     ClearLineMethod = 2
)

type ClearScreenMethod

type ClearScreenMethod int
const (
	CursorToBottom           ClearScreenMethod = 0
	CursorToTop              ClearScreenMethod = 1
	WholeScreen              ClearScreenMethod = 2
	WholeScreenAndScrollback ClearScreenMethod = 3
)

Jump to

Keyboard shortcuts

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