cursor

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 6 Imported by: 34

README

AtomicGo | cursor

Downloads Latest Release Tests Coverage Unit test count Go report


Documentation | Contributing | Code of Conduct


AtomicGo

go get atomicgo.dev/cursor

cursor

import "atomicgo.dev/cursor"

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 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 Clear

func Clear()

Clear clears the current position and moves the cursor to the left.

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 Down

func Down(n int)

Down moves the cursor n lines down relative to the current position.

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 Move

func Move(x, y int)

Move moves the cursor relative by x and y.

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 sets to output target of the default curser to the provided cursor.Writer (wrapping io.Writer).

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

func TestCustomIOWriter(t *testing.T)

TestCustomIOWriter tests the cursor functions with a custom Writer.

func Up

func Up(n int)

Up moves the cursor n lines up relative to the current position.

func UpAndClear

func UpAndClear(n int)

UpAndClear moves the cursor up by n lines, then clears the line.

type Area

Area displays content which can be updated on the fly. You can use this to create live output, charts, dropdowns, etc.

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

func NewArea
func NewArea() Area

NewArea returns a new Area.

func (*Area) Bottom
func (area *Area) 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 (*Area) Clear
func (area *Area) Clear()

Clear clears the content of the Area.

func (*Area) ClearLinesDown
func (area *Area) ClearLinesDown(n int)

ClearLinesDown clears n lines downwards from the current position and moves the cursor.

func (*Area) ClearLinesUp
func (area *Area) ClearLinesUp(n int)

ClearLinesUp clears n lines upwards from the current position and moves the cursor.

func (*Area) Down
func (area *Area) Down(n int)

Down moves the cursor of the area down one line.

func (*Area) DownAndClear
func (area *Area) DownAndClear(n int)

DownAndClear moves the cursor down by n lines, then clears the line.

func (*Area) Move
func (area *Area) Move(x, y int)

Move moves the cursor relative by x and y.

func (*Area) StartOfLine
func (area *Area) StartOfLine()

StartOfLine moves the cursor to the start of the current line.

func (*Area) StartOfLineDown
func (area *Area) StartOfLineDown(n int)

StartOfLineDown moves the cursor down by n lines, then moves to cursor to the start of the line.

func (*Area) StartOfLineUp
func (area *Area) StartOfLineUp(n int)

StartOfLineUp moves the cursor up by n lines, then moves to cursor to the start of the line.

func (*Area) Top
func (area *Area) Top()

Top moves the cursor to the top of the area. This is done by calculating how many lines were moved by Up and Down.

func (*Area) Up
func (area *Area) Up(n int)

Up moves the cursor of the area up one line.

func (*Area) UpAndClear
func (area *Area) UpAndClear(n int)

UpAndClear moves the cursor up by n lines, then clears the line.

func (*Area) Update
func (area *Area) Update(content string)

Update overwrites the content of the Area and adjusts its height based on content.

func (Area) WithWriter
func (area Area) WithWriter(writer Writer) Area

WithWriter sets the custom writer.

type Cursor

Cursor displays content which can be updated on the fly. You can use this to create live output, charts, dropdowns, etc.

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

func NewCursor
func NewCursor() *Cursor

NewCursor creates a new Cursor instance writing to os.Stdout.

func (*Cursor) Clear
func (c *Cursor) Clear()

Clear clears the current position and moves the cursor to the left.

func (*Cursor) ClearLine
func (c *Cursor) ClearLine()

ClearLine clears the current line and moves the cursor to it's start position.

func (*Cursor) Down
func (c *Cursor) Down(n int)

Down moves the cursor n lines down relative to the current position.

func (*Cursor) Hide
func (c *Cursor) 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 (*Cursor) HorizontalAbsolute
func (c *Cursor) HorizontalAbsolute(n int)

HorizontalAbsolute moves the cursor to n horizontally. The position n is absolute to the start of the line.

func (*Cursor) Left
func (c *Cursor) Left(n int)

Left moves the cursor n characters to the left relative to the current position.

func (*Cursor) Right
func (c *Cursor) Right(n int)

Right moves the cursor n characters to the right relative to the current position.

func (*Cursor) Show
func (c *Cursor) 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 (*Cursor) Up
func (c *Cursor) Up(n int)

Up moves the cursor n lines up relative to the current position.

func (*Cursor) WithWriter
func (c *Cursor) WithWriter(w Writer) *Cursor

WithWriter allows for any arbitrary Writer to be used for cursor movement abstracted.

type Writer

Writer is an expanded io.Writer interface with a file descriptor.

type Writer interface {
    io.Writer
    Fd() uintptr
}

Generated by gomarkdoc


AtomicGo.dev  ·  with ❤️ by @MarvinJWendt | MarvinJWendt.com

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

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 Clear added in v0.2.0

func Clear()

Clear clears the current position and moves the cursor to the left.

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 Down

func Down(n int)

Down moves the cursor n lines down relative to the current position.

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 Move

func Move(x, y int)

Move moves the cursor relative by x and y.

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 sets to output target of the default curser to the provided cursor.Writer (wrapping io.Writer).

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

func TestCustomIOWriter(t *testing.T)

TestCustomIOWriter tests the cursor functions with a custom Writer.

func Up

func Up(n int)

Up moves the cursor n lines up relative to the current position.

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 NewArea

func NewArea() Area

NewArea returns a new Area.

func (*Area) Bottom added in v0.2.0

func (area *Area) 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 (*Area) Clear

func (area *Area) Clear()

Clear clears the content of the Area.

func (*Area) ClearLinesDown added in v0.2.0

func (area *Area) ClearLinesDown(n int)

ClearLinesDown clears n lines downwards from the current position and moves the cursor.

func (*Area) ClearLinesUp added in v0.2.0

func (area *Area) ClearLinesUp(n int)

ClearLinesUp clears n lines upwards from the current position and moves the cursor.

func (*Area) Down added in v0.2.0

func (area *Area) Down(n int)

Down moves the cursor of the area down one line.

func (*Area) DownAndClear added in v0.2.0

func (area *Area) DownAndClear(n int)

DownAndClear moves the cursor down by n lines, then clears the line.

func (*Area) Move added in v0.2.0

func (area *Area) Move(x, y int)

Move moves the cursor relative by x and y.

func (*Area) StartOfLine added in v0.2.0

func (area *Area) StartOfLine()

StartOfLine moves the cursor to the start of the current line.

func (*Area) StartOfLineDown added in v0.2.0

func (area *Area) StartOfLineDown(n int)

StartOfLineDown moves the cursor down by n lines, then moves to cursor to the start of the line.

func (*Area) StartOfLineUp added in v0.2.0

func (area *Area) StartOfLineUp(n int)

StartOfLineUp moves the cursor up by n lines, then moves to cursor to the start of the line.

func (*Area) Top added in v0.2.0

func (area *Area) Top()

Top moves the cursor to the top of the area. This is done by calculating how many lines were moved by Up and Down.

func (*Area) Up added in v0.2.0

func (area *Area) Up(n int)

Up moves the cursor of the area up one line.

func (*Area) UpAndClear added in v0.2.0

func (area *Area) UpAndClear(n int)

UpAndClear moves the cursor up by n lines, then clears the line.

func (*Area) Update

func (area *Area) Update(content string)

Update overwrites the content of the Area and adjusts its height based on content.

func (Area) WithWriter added in v0.1.2

func (area Area) WithWriter(writer Writer) Area

WithWriter sets the custom writer.

type Cursor added in v0.2.0

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

Cursor displays content which can be updated on the fly. You can use this to create live output, charts, dropdowns, etc.

func NewCursor added in v0.2.0

func NewCursor() *Cursor

NewCursor creates a new Cursor instance writing to os.Stdout.

func (*Cursor) Clear added in v0.2.0

func (c *Cursor) Clear()

Clear clears the current position and moves the cursor to the left.

func (*Cursor) ClearLine added in v0.2.0

func (c *Cursor) ClearLine()

ClearLine clears the current line and moves the cursor to it's start position.

func (*Cursor) Down added in v0.2.0

func (c *Cursor) Down(n int)

Down moves the cursor n lines down relative to the current position.

func (*Cursor) Hide added in v0.2.0

func (c *Cursor) 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 (*Cursor) HorizontalAbsolute added in v0.2.0

func (c *Cursor) HorizontalAbsolute(n int)

HorizontalAbsolute moves the cursor to n horizontally. The position n is absolute to the start of the line.

func (*Cursor) Left added in v0.2.0

func (c *Cursor) Left(n int)

Left moves the cursor n characters to the left relative to the current position.

func (*Cursor) Right added in v0.2.0

func (c *Cursor) Right(n int)

Right moves the cursor n characters to the right relative to the current position.

func (*Cursor) Show added in v0.2.0

func (c *Cursor) 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 (*Cursor) Up added in v0.2.0

func (c *Cursor) Up(n int)

Up moves the cursor n lines up relative to the current position.

func (*Cursor) WithWriter added in v0.2.0

func (c *Cursor) WithWriter(w Writer) *Cursor

WithWriter allows for any arbitrary Writer to be used for cursor movement abstracted.

type Writer added in v0.1.1

type Writer interface {
	io.Writer
	Fd() uintptr
}

Writer is an expanded io.Writer interface with a file descriptor.

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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