https://github.com/atomicgo/cursor
🖱️ Go module to move the terminal cursor in any direction on every operating system.
https://github.com/atomicgo/cursor
atomicgo cursor go golang golang-library terminal tui
Last synced: about 1 month ago
JSON representation
🖱️ Go module to move the terminal cursor in any direction on every operating system.
- Host: GitHub
- URL: https://github.com/atomicgo/cursor
- Owner: atomicgo
- License: mit
- Created: 2021-04-11T21:20:45.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-08T17:04:12.000Z (10 months ago)
- Last Synced: 2024-11-10T13:09:22.128Z (7 months ago)
- Topics: atomicgo, cursor, go, golang, golang-library, terminal, tui
- Language: Go
- Homepage: https://atomicgo.dev
- Size: 89.8 KB
- Stars: 92
- Watchers: 3
- Forks: 9
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
AtomicGo | cursor
---
Documentation
|
Contributing
|
Code of Conduct---
![]()
go get atomicgo.dev/cursor
# cursor
```go
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\(\)](<#Bottom>)
- [func Clear\(\)](<#Clear>)
- [func ClearLine\(\)](<#ClearLine>)
- [func ClearLinesDown\(n int\)](<#ClearLinesDown>)
- [func ClearLinesUp\(n int\)](<#ClearLinesUp>)
- [func Down\(n int\)](<#Down>)
- [func DownAndClear\(n int\)](<#DownAndClear>)
- [func Hide\(\)](<#Hide>)
- [func HorizontalAbsolute\(n int\)](<#HorizontalAbsolute>)
- [func Left\(n int\)](<#Left>)
- [func Move\(x, y int\)](<#Move>)
- [func Right\(n int\)](<#Right>)
- [func SetTarget\(w Writer\)](<#SetTarget>)
- [func Show\(\)](<#Show>)
- [func StartOfLine\(\)](<#StartOfLine>)
- [func StartOfLineDown\(n int\)](<#StartOfLineDown>)
- [func StartOfLineUp\(n int\)](<#StartOfLineUp>)
- [func TestCustomIOWriter\(t \*testing.T\)](<#TestCustomIOWriter>)
- [func Up\(n int\)](<#Up>)
- [func UpAndClear\(n int\)](<#UpAndClear>)
- [type Area](<#Area>)
- [func NewArea\(\) Area](<#NewArea>)
- [func \(area \*Area\) Bottom\(\)](<#Area.Bottom>)
- [func \(area \*Area\) Clear\(\)](<#Area.Clear>)
- [func \(area \*Area\) ClearLinesDown\(n int\)](<#Area.ClearLinesDown>)
- [func \(area \*Area\) ClearLinesUp\(n int\)](<#Area.ClearLinesUp>)
- [func \(area \*Area\) Down\(n int\)](<#Area.Down>)
- [func \(area \*Area\) DownAndClear\(n int\)](<#Area.DownAndClear>)
- [func \(area \*Area\) Move\(x, y int\)](<#Area.Move>)
- [func \(area \*Area\) StartOfLine\(\)](<#Area.StartOfLine>)
- [func \(area \*Area\) StartOfLineDown\(n int\)](<#Area.StartOfLineDown>)
- [func \(area \*Area\) StartOfLineUp\(n int\)](<#Area.StartOfLineUp>)
- [func \(area \*Area\) Top\(\)](<#Area.Top>)
- [func \(area \*Area\) Up\(n int\)](<#Area.Up>)
- [func \(area \*Area\) UpAndClear\(n int\)](<#Area.UpAndClear>)
- [func \(area \*Area\) Update\(content string\)](<#Area.Update>)
- [func \(area Area\) WithWriter\(writer Writer\) Area](<#Area.WithWriter>)
- [type Cursor](<#Cursor>)
- [func NewCursor\(\) \*Cursor](<#NewCursor>)
- [func \(c \*Cursor\) Clear\(\)](<#Cursor.Clear>)
- [func \(c \*Cursor\) ClearLine\(\)](<#Cursor.ClearLine>)
- [func \(c \*Cursor\) Down\(n int\)](<#Cursor.Down>)
- [func \(c \*Cursor\) Hide\(\)](<#Cursor.Hide>)
- [func \(c \*Cursor\) HorizontalAbsolute\(n int\)](<#Cursor.HorizontalAbsolute>)
- [func \(c \*Cursor\) Left\(n int\)](<#Cursor.Left>)
- [func \(c \*Cursor\) Right\(n int\)](<#Cursor.Right>)
- [func \(c \*Cursor\) Show\(\)](<#Cursor.Show>)
- [func \(c \*Cursor\) Up\(n int\)](<#Cursor.Up>)
- [func \(c \*Cursor\) WithWriter\(w Writer\) \*Cursor](<#Cursor.WithWriter>)
- [type Writer](<#Writer>)```go
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.
```go
func Clear()
```Clear clears the current position and moves the cursor to the left.
```go
func ClearLine()
```ClearLine clears the current line and moves the cursor to it's start position.
```go
func ClearLinesDown(n int)
```ClearLinesDown clears n lines downwards from the current position and moves the cursor.
```go
func ClearLinesUp(n int)
```ClearLinesUp clears n lines upwards from the current position and moves the cursor.
```go
func Down(n int)
```Down moves the cursor n lines down relative to the current position.
```go
func DownAndClear(n int)
```DownAndClear moves the cursor down by n lines, then clears the line.
```go
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]()```go
func HorizontalAbsolute(n int)
```HorizontalAbsolute moves the cursor to n horizontally. The position n is absolute to the start of the line.
```go
func Left(n int)
```Left moves the cursor n characters to the left relative to the current position.
```go
func Move(x, y int)
```Move moves the cursor relative by x and y.
```go
func Right(n int)
```Right moves the cursor n characters to the right relative to the current position.
```go
func SetTarget(w Writer)
```SetTarget sets to output target of the default curser to the provided cursor.Writer \(wrapping io.Writer\).
```go
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.
```go
func StartOfLine()
```StartOfLine moves the cursor to the start of the current line.
```go
func StartOfLineDown(n int)
```StartOfLineDown moves the cursor down by n lines, then moves to cursor to the start of the line.
```go
func StartOfLineUp(n int)
```StartOfLineUp moves the cursor up by n lines, then moves to cursor to the start of the line.
## func [TestCustomIOWriter]()```go
func TestCustomIOWriter(t *testing.T)
```TestCustomIOWriter tests the cursor functions with a custom Writer.
```go
func Up(n int)
```Up moves the cursor n lines up relative to the current position.
```go
func UpAndClear(n int)
```UpAndClear moves the cursor up by n lines, then clears the line.
Area displays content which can be updated on the fly. You can use this to create live output, charts, dropdowns, etc.
```go
type Area struct {
// contains filtered or unexported fields
}
``````go
func NewArea() Area
```NewArea returns a new Area.
### func \(\*Area\) [Bottom]()```go
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.
```go
func (area *Area) Clear()
```Clear clears the content of the Area.
### func \(\*Area\) [ClearLinesDown]()```go
func (area *Area) ClearLinesDown(n int)
```ClearLinesDown clears n lines downwards from the current position and moves the cursor.
### func \(\*Area\) [ClearLinesUp]()```go
func (area *Area) ClearLinesUp(n int)
```ClearLinesUp clears n lines upwards from the current position and moves the cursor.
```go
func (area *Area) Down(n int)
```Down moves the cursor of the area down one line.
### func \(\*Area\) [DownAndClear]()```go
func (area *Area) DownAndClear(n int)
```DownAndClear moves the cursor down by n lines, then clears the line.
```go
func (area *Area) Move(x, y int)
```Move moves the cursor relative by x and y.
### func \(\*Area\) [StartOfLine]()```go
func (area *Area) StartOfLine()
```StartOfLine moves the cursor to the start of the current line.
### func \(\*Area\) [StartOfLineDown]()```go
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]()```go
func (area *Area) StartOfLineUp(n int)
```StartOfLineUp moves the cursor up by n lines, then moves to cursor to the start of the line.
```go
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.
```go
func (area *Area) Up(n int)
```Up moves the cursor of the area up one line.
### func \(\*Area\) [UpAndClear]()```go
func (area *Area) UpAndClear(n int)
```UpAndClear moves the cursor up by n lines, then clears the line.
### func \(\*Area\) [Update]()```go
func (area *Area) Update(content string)
```Update overwrites the content of the Area and adjusts its height based on content.
### func \(Area\) [WithWriter]()```go
func (area Area) WithWriter(writer Writer) Area
```WithWriter sets the custom writer.
Cursor displays content which can be updated on the fly. You can use this to create live output, charts, dropdowns, etc.
```go
type Cursor struct {
// contains filtered or unexported fields
}
``````go
func NewCursor() *Cursor
```NewCursor creates a new Cursor instance writing to os.Stdout.
### func \(\*Cursor\) [Clear]()```go
func (c *Cursor) Clear()
```Clear clears the current position and moves the cursor to the left.
### func \(\*Cursor\) [ClearLine]()```go
func (c *Cursor) ClearLine()
```ClearLine clears the current line and moves the cursor to it's start position.
### func \(\*Cursor\) [Down]()```go
func (c *Cursor) Down(n int)
```Down moves the cursor n lines down relative to the current position.
### func \(\*Cursor\) [Hide]()```go
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]()```go
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]()```go
func (c *Cursor) Left(n int)
```Left moves the cursor n characters to the left relative to the current position.
### func \(\*Cursor\) [Right]()```go
func (c *Cursor) Right(n int)
```Right moves the cursor n characters to the right relative to the current position.
### func \(\*Cursor\) [Show]()```go
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.
```go
func (c *Cursor) Up(n int)
```Up moves the cursor n lines up relative to the current position.
### func \(\*Cursor\) [WithWriter]()```go
func (c *Cursor) WithWriter(w Writer) *Cursor
```WithWriter allows for any arbitrary Writer to be used for cursor movement abstracted.
Writer is an expanded io.Writer interface with a file descriptor.
```go
type Writer interface {
io.Writer
Fd() uintptr
}
```Generated by [gomarkdoc]()
---
> [AtomicGo.dev](https://atomicgo.dev) ·
> with ❤️ by [@MarvinJWendt](https://github.com/MarvinJWendt) |
> [MarvinJWendt.com](https://marvinjwendt.com)