Skip to content

Commit

Permalink
feat: use image.Point instead of cellbuf.Position for cursor position
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Oct 15, 2024
1 parent 3259e0d commit 819b8b8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
15 changes: 8 additions & 7 deletions cell_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tea

import (
"bytes"
"image"
"io"
"strings"
"sync"
Expand All @@ -12,7 +13,7 @@ import (

// cursor represents a terminal cursor.
type cursor struct {
cellbuf.Position
image.Point
visible bool
}

Expand Down Expand Up @@ -215,7 +216,7 @@ func (c *cellRenderer) reset() {
// alt-screen buffer cursor always starts from where the main buffer cursor
// is. We need to set it to (-1,-1) to force the cursor to be moved to the
// origin on the first render.
c.scrs[1].cur.Position = cellbuf.Pos(-1, -1)
c.scrs[1].cur.Point = image.Pt(-1, -1)
if c.altScreen {
c.scr = &c.scrs[1]
c.lastRender = &c.lastRenders[1]
Expand Down Expand Up @@ -363,7 +364,7 @@ func (c *cellRenderer) changes() {
cell, _ := c.scr.At(x, y)
if !c.scr.isDirty(x, y) {
if seg != nil {
erased := c.flushSegment(seg, cellbuf.Pos(segX, y), eraser)
erased := c.flushSegment(seg, image.Pt(segX, y), eraser)
seg = nil
if erased {
// If the segment erased the rest of the line, we don't need to
Expand All @@ -387,7 +388,7 @@ func (c *cellRenderer) changes() {
}

if !seg.Style.Equal(cell.Style) || seg.Link != cell.Link {
erased := c.flushSegment(seg, cellbuf.Pos(segX, y), eraser)
erased := c.flushSegment(seg, image.Pt(segX, y), eraser)
if erased {
seg = nil
// If the segment erased the rest of the line, we don't need to
Expand All @@ -411,7 +412,7 @@ func (c *cellRenderer) changes() {
}

if seg != nil {
c.flushSegment(seg, cellbuf.Pos(segX, y), eraser)
c.flushSegment(seg, image.Pt(segX, y), eraser)
seg = nil
}
}
Expand All @@ -437,8 +438,8 @@ func (c *cellRenderer) changes() {

// flushSegment flushes the segment to the buffer. It returns true if the
// segment the rest of the line was erased.
func (c *cellRenderer) flushSegment(seg *cellbuf.Segment, to cellbuf.Position, eraser bool) (erased bool) {
if c.scr.cur.Position != to {
func (c *cellRenderer) flushSegment(seg *cellbuf.Segment, to image.Point, eraser bool) (erased bool) {
if c.scr.cur.Point != to {
c.renderReset(seg)
c.moveCursor(to.X, to.Y)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/charmbracelet/x/ansi v0.3.2
github.com/charmbracelet/x/cellbuf v0.0.0-20241014013228-327c48faaf2e
github.com/charmbracelet/x/cellbuf v0.0.0-20241015153255-110a4e49aee6
github.com/charmbracelet/x/term v0.2.0
github.com/charmbracelet/x/windows v0.2.0
github.com/muesli/cancelreader v0.2.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/charmbracelet/x/ansi v0.3.2 h1:wsEwgAN+C9U06l9dCVMX0/L3x7ptvY1qmjMwyf
github.com/charmbracelet/x/ansi v0.3.2/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
github.com/charmbracelet/x/cellbuf v0.0.0-20241014013228-327c48faaf2e h1:uCN5BuqaOSDlAfxLPmNmAK7jXzNXgKnC/irIEKXQD7Y=
github.com/charmbracelet/x/cellbuf v0.0.0-20241014013228-327c48faaf2e/go.mod h1:mFpvlGowTd0Fiv4TdoKyGZaZdigSUHtBJralbADonwE=
github.com/charmbracelet/x/cellbuf v0.0.0-20241015153255-110a4e49aee6 h1:z6Jq8MwJxOqzNSLEyAfRrHvUGFU7SgTFgZrqFHAJIu4=
github.com/charmbracelet/x/cellbuf v0.0.0-20241015153255-110a4e49aee6/go.mod h1:mFpvlGowTd0Fiv4TdoKyGZaZdigSUHtBJralbADonwE=
github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0=
github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0=
github.com/charmbracelet/x/wcwidth v0.0.0-20241011142426-46044092ad91 h1:D5OO0lVavz7A+Swdhp62F9gbkibxmz9B2hZ/jVdMPf0=
Expand Down

0 comments on commit 819b8b8

Please sign in to comment.