Documentation ¶
Overview ¶
Package cursor contains cross-platform methods to move the terminal cursor in different directions. This package can be used to create interactive CLI tools and games, live charts, algorithm visualizations and other updatable output of any kind.
Works niceley with https://github.com/atomicgo/keyboard
Special thanks to github.com/k0kubun/go-ansi which this project is based on.
Index ¶
- func Bottom()
- func ClearLine()
- func ClearLinesDown(n int)
- func ClearLinesUp(n int)
- func Down(n int)
- func DownAndClear(n int)
- func Hide()
- func HorizontalAbsolute(n int)
- func Left(n int)
- func Move(x, y int)
- func Right(n int)
- func SetTarget(w Writer)
- func Show()
- func StartOfLine()
- func StartOfLineDown(n int)
- func StartOfLineUp(n int)
- func TestCustomIOWriter(t *testing.T)
- func Up(n int)
- func UpAndClear(n int)
- type Area
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bottom ¶
func Bottom()
Bottom moves the cursor to the bottom of the terminal. This is done by calculating how many lines were moved by Up and Down.
func ClearLine ¶
func ClearLine()
ClearLine clears the current line and moves the cursor to it's start position.
func ClearLinesDown ¶
func ClearLinesDown(n int)
ClearLinesDown clears n lines downwards from the current position and moves the cursor.
func ClearLinesUp ¶
func ClearLinesUp(n int)
ClearLinesUp clears n lines upwards from the current position and moves the cursor.
func DownAndClear ¶
func DownAndClear(n int)
DownAndClear moves the cursor down by n lines, then clears the line.
func Hide ¶
func Hide()
Hide the cursor. Don't forget to show the cursor at least at the end of your application with Show. Otherwise the user might have a terminal with a permanently hidden cursor, until they reopen the terminal.
func HorizontalAbsolute ¶
func HorizontalAbsolute(n int)
HorizontalAbsolute moves the cursor to n horizontally. The position n is absolute to the start of the line.
func Left ¶
func Left(n int)
Left moves the cursor n characters to the left relative to the current position.
func Right ¶
func Right(n int)
Right moves the cursor n characters to the right relative to the current position.
func SetTarget ¶
func SetTarget(w Writer)
SetTarget allows for any arbitrary io.Writer to be used for cursor movement (will not work on Windows).
func Show ¶
func Show()
Show the cursor if it was hidden previously. Don't forget to show the cursor at least at the end of your application. Otherwise the user might have a terminal with a permanently hidden cursor, until they reopen the terminal.
func StartOfLine ¶
func StartOfLine()
StartOfLine moves the cursor to the start of the current line.
func StartOfLineDown ¶
func StartOfLineDown(n int)
StartOfLineDown moves the cursor down by n lines, then moves to cursor to the start of the line.
func StartOfLineUp ¶
func StartOfLineUp(n int)
StartOfLineUp moves the cursor up by n lines, then moves to cursor to the start of the line.
func TestCustomIOWriter ¶ added in v0.1.1
TestCustomIOWriter tests the cursor functions with a custom Writer.
func UpAndClear ¶
func UpAndClear(n int)
UpAndClear moves the cursor up by n lines, then clears the line.
Types ¶
type Area ¶
type Area struct {
// contains filtered or unexported fields
}
Area displays content which can be updated on the fly. You can use this to create live output, charts, dropdowns, etc.
func (Area) WithWriter ¶ added in v0.1.2
WithWriter sets a custom writer for the Area.