Skip to content

Commit

Permalink
Merge pull request #78 from mjarkk/fix-clear-function
Browse files Browse the repository at this point in the history
Fix #77 panic when executing clear and set cursor afterwards
  • Loading branch information
mjarkk authored Feb 26, 2021
2 parents a0f5add + 3a4e596 commit f08cd7a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions view.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ func (v *View) setRune(x, y int, ch rune, fgColor, bgColor Attribute) error {
// y < total lines && y > 0
// (x < view width || x < y's line width) && x > 0
func (v *View) SetCursor(x, y int) error {
maxX, _ := v.Size()
if x < 0 || y < 0 || y >= len(v.lines) || (len(v.lines[y]) >= x && x >= maxX) {
if x < 0 || y < 0 || (y >= len(v.lines) && y != 0) || (x > 0 && (len(v.lines) == 0 || len(v.lines[y]) < x)) {
return ErrInvalidPoint
}

Expand Down Expand Up @@ -598,14 +597,15 @@ func (v *View) draw() error {
return nil
}

// Clear empties the view's internal buffer.
// And resets reading and writing offsets.
// Clear empties the view and resets the view offsets, cursor position, read offsets and write offsets
func (v *View) Clear() {
v.writeMutex.Lock()
v.Rewind()
v.tainted = true
v.ei.reset()
v.lines = nil
v.lines = [][]cell{}
v.SetCursor(0, 0)
v.SetOrigin(0, 0)
v.clearRunes()
v.writeMutex.Unlock()
}
Expand Down

0 comments on commit f08cd7a

Please sign in to comment.