Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func UpAndClear(n int)

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

## type [Area](<https://github.com/atomicgo/cursor/blob/main/area.go#L11-L13>)
## type [Area](<https://github.com/atomicgo/cursor/blob/main/area.go#L10-L12>)

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

Expand All @@ -263,23 +263,23 @@ type Area struct {
}
```

### func [NewArea](<https://github.com/atomicgo/cursor/blob/main/area.go#L16>)
### func [NewArea](<https://github.com/atomicgo/cursor/blob/main/area.go#L15>)

```go
func NewArea() Area
```

NewArea returns a new Area.

### func \(\*Area\) [Clear](<https://github.com/atomicgo/cursor/blob/main/area.go#L21>)
### func \(\*Area\) [Clear](<https://github.com/atomicgo/cursor/blob/main/area.go#L20>)

```go
func (area *Area) Clear()
```

Clear clears the content of the Area.

### func \(\*Area\) [Update](<https://github.com/atomicgo/cursor/blob/main/area.go#L29>)
### func \(\*Area\) [Update](<https://github.com/atomicgo/cursor/blob/main/area.go#L28>)

```go
func (area *Area) Update(content string)
Expand Down
19 changes: 2 additions & 17 deletions area.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cursor

import (
"fmt"
"runtime"
"strings"
)

Expand All @@ -28,22 +27,8 @@ func (area *Area) Clear() {
// Update overwrites the content of the Area.
func (area *Area) Update(content string) {
area.Clear()
lines := strings.Split(content, "\n")

fmt.Println(strings.Repeat("\n", len(lines)-1)) // This appends space if the terminal is at the bottom
Up(len(lines))

if runtime.GOOS == "windows" {
for _, line := range lines {
fmt.Print(line)
StartOfLineDown(1)
}
} else {
for _, line := range lines {
fmt.Println(line)
}
}
fmt.Println(content)
height = 0

area.height = len(lines)
area.height = len(strings.Split(content, "\n"))
}
2 changes: 1 addition & 1 deletion cursor_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func Hide() {
_, _, _ = procSetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&cci)))
}

// ClearLine clears the current line and moves the cursor to it's start position.
// ClearLine clears the current line and moves the cursor to its start position.
func ClearLine() {
handle := syscall.Handle(target.Fd())

Expand Down