Documentation | Contributing | Code of Conduct
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.
- func Bottom()
- func Clear()
- 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
- func NewArea() Area
- func (area *Area) Bottom()
- func (area *Area) Clear()
- func (area *Area) ClearLinesDown(n int)
- func (area *Area) ClearLinesUp(n int)
- func (area *Area) Down(n int)
- func (area *Area) DownAndClear(n int)
- func (area *Area) Move(x, y int)
- func (area *Area) StartOfLine()
- func (area *Area) StartOfLineDown(n int)
- func (area *Area) StartOfLineUp(n int)
- func (area *Area) Top()
- func (area *Area) Up(n int)
- func (area *Area) UpAndClear(n int)
- func (area *Area) Update(content string)
- func (area Area) WithWriter(writer Writer) Area
- type Cursor
- func NewCursor() *Cursor
- func (c *Cursor) Clear()
- func (c *Cursor) ClearLine()
- func (c *Cursor) Down(n int)
- func (c *Cursor) Hide()
- func (c *Cursor) HorizontalAbsolute(n int)
- func (c *Cursor) Left(n int)
- func (c *Cursor) Right(n int)
- func (c *Cursor) Show()
- func (c *Cursor) Up(n int)
- func (c *Cursor) WithWriter(w Writer) *Cursor
- type Writer
func Bottom
funcBottom()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
funcClear()Clear clears the current position and moves the cursor to the left.
func ClearLine
funcClearLine()ClearLine clears the current line and moves the cursor to it's start position.
func ClearLinesDown
funcClearLinesDown(nint)ClearLinesDown clears n lines downwards from the current position and moves the cursor.
func ClearLinesUp
funcClearLinesUp(nint)ClearLinesUp clears n lines upwards from the current position and moves the cursor.
func Down
funcDown(nint)Down moves the cursor n lines down relative to the current position.
func DownAndClear
funcDownAndClear(nint)DownAndClear moves the cursor down by n lines, then clears the line.
func Hide
funcHide()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
funcHorizontalAbsolute(nint)HorizontalAbsolute moves the cursor to n horizontally. The position n is absolute to the start of the line.
func Left
funcLeft(nint)Left moves the cursor n characters to the left relative to the current position.
func Move
funcMove(x, yint)Move moves the cursor relative by x and y.
func Right
funcRight(nint)Right moves the cursor n characters to the right relative to the current position.
func SetTarget
funcSetTarget(wWriter)SetTarget sets to output target of the default curser to the provided cursor.Writer (wrapping io.Writer).
func Show
funcShow()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
funcStartOfLine()StartOfLine moves the cursor to the start of the current line.
func StartOfLineDown
funcStartOfLineDown(nint)StartOfLineDown moves the cursor down by n lines, then moves to cursor to the start of the line.
func StartOfLineUp
funcStartOfLineUp(nint)StartOfLineUp moves the cursor up by n lines, then moves to cursor to the start of the line.
func TestCustomIOWriter
funcTestCustomIOWriter(t*testing.T)TestCustomIOWriter tests the cursor functions with a custom Writer.
func Up
funcUp(nint)Up moves the cursor n lines up relative to the current position.
func UpAndClear
funcUpAndClear(nint)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.
typeAreastruct {
// contains filtered or unexported fields
}func NewArea
funcNewArea() AreaNewArea 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(nint)ClearLinesDown clears n lines downwards from the current position and moves the cursor.
func (*Area) ClearLinesUp
func (area*Area) ClearLinesUp(nint)ClearLinesUp clears n lines upwards from the current position and moves the cursor.
func (*Area) Down
func (area*Area) Down(nint)Down moves the cursor of the area down one line.
func (*Area) DownAndClear
func (area*Area) DownAndClear(nint)DownAndClear moves the cursor down by n lines, then clears the line.
func (*Area) Move
func (area*Area) Move(x, yint)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(nint)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(nint)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(nint)Up moves the cursor of the area up one line.
func (*Area) UpAndClear
func (area*Area) UpAndClear(nint)UpAndClear moves the cursor up by n lines, then clears the line.
func (*Area) Update
func (area*Area) Update(contentstring)Update overwrites the content of the Area and adjusts its height based on content.
func (Area) WithWriter
func (areaArea) WithWriter(writerWriter) AreaWithWriter 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.
typeCursorstruct {
// contains filtered or unexported fields
}func NewCursor
funcNewCursor() *CursorNewCursor 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(nint)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(nint)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(nint)Left moves the cursor n characters to the left relative to the current position.
func (*Cursor) Right
func (c*Cursor) Right(nint)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(nint)Up moves the cursor n lines up relative to the current position.
func (*Cursor) WithWriter
func (c*Cursor) WithWriter(wWriter) *CursorWithWriter 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.
typeWriterinterface {
io.WriterFd() uintptr
}Generated by gomarkdoc
AtomicGo.dev · with ❤️ by @MarvinJWendt | mjw.dev
