Skip to content

Commit

Permalink
refactor(cellbuf): rename FillInRect to FillRect and ClearInRect to C…
Browse files Browse the repository at this point in the history
…learRect
  • Loading branch information
aymanbagabas committed Dec 10, 2024
1 parent bfa18c6 commit 45c33cb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
14 changes: 7 additions & 7 deletions cellbuf/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ func (b *Buffer) Resize(width int, height int) {
}
}

// FillInRect fills the buffer with the given cell and rectangle.
func (b *Buffer) FillInRect(c *Cell, rect Rectangle) {
// FillRect fills the buffer with the given cell and rectangle.
func (b *Buffer) FillRect(c *Cell, rect Rectangle) {
cellWidth := 1
if c != nil && c.Width > 1 {
cellWidth = c.Width
Expand All @@ -279,18 +279,18 @@ func (b *Buffer) FillInRect(c *Cell, rect Rectangle) {

// Fill fills the buffer with the given cell and rectangle.
func (b *Buffer) Fill(c *Cell) {
b.FillInRect(c, b.Bounds())
b.FillRect(c, b.Bounds())
}

// Clear clears the buffer with space cells and rectangle.
func (b *Buffer) Clear() {
b.ClearInRect(b.Bounds())
b.ClearRect(b.Bounds())
}

// ClearInRect clears the buffer with space cells within the specified
// ClearRect clears the buffer with space cells within the specified
// rectangles. Only cells within the rectangle's bounds are affected.
func (b *Buffer) ClearInRect(rect Rectangle) {
b.FillInRect(nil, rect)
func (b *Buffer) ClearRect(rect Rectangle) {
b.FillRect(nil, rect)
}

// InsertLine inserts n lines at the given line position, with the given
Expand Down
6 changes: 3 additions & 3 deletions cellbuf/screen_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func setContent(
}
case ansi.Equal(seq, "\n"):
// Reset the rest of the line
d.ClearInRect(Rect(x, y, rect.Width()+rect.X()-x, 1))
d.ClearRect(Rect(x, y, rect.Width()+rect.X()-x, 1))

y++
// XXX: We gotta reset the x position here because we're moving
Expand All @@ -127,12 +127,12 @@ func setContent(
}

// Don't forget to clear the last line
d.ClearInRect(Rect(x, y, rect.Width()+rect.X()-x, 1))
d.ClearRect(Rect(x, y, rect.Width()+rect.X()-x, 1))

y++
if y < rect.Height() {
// Clear the rest of the lines
d.ClearInRect(Rect(rect.X(), y, rect.X()+rect.Width(), rect.Y()+rect.Height()))
d.ClearRect(Rect(rect.X(), y, rect.X()+rect.Width(), rect.Y()+rect.Height()))
}

return linew
Expand Down
50 changes: 25 additions & 25 deletions cellbuf/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,12 @@ func (s *Screen) Cell(x int, y int) *Cell {
// Clear implements Window.
func (s *Screen) Clear() bool {
s.clear = true
return s.ClearInRect(s.newbuf.Bounds())
return s.ClearRect(s.newbuf.Bounds())
}

// ClearInRect implements Window.
func (s *Screen) ClearInRect(r Rectangle) bool {
s.newbuf.ClearInRect(r)
// ClearRect implements Window.
func (s *Screen) ClearRect(r Rectangle) bool {
s.newbuf.ClearRect(r)
s.mu.Lock()
for i := r.Min.Y; i < r.Max.Y; i++ {
s.touch[i] = [2]int{r.Min.X, r.Width() - 1}
Expand Down Expand Up @@ -343,12 +343,12 @@ func (s *Screen) Draw(x int, y int, cell *Cell) (v bool) {

// Fill implements Window.
func (s *Screen) Fill(cell *Cell) bool {
return s.FillInRect(cell, s.newbuf.Bounds())
return s.FillRect(cell, s.newbuf.Bounds())
}

// FillInRect implements Window.
func (s *Screen) FillInRect(cell *Cell, r Rectangle) bool {
s.newbuf.FillInRect(cell, r)
// FillRect implements Window.
func (s *Screen) FillRect(cell *Cell, r Rectangle) bool {
s.newbuf.FillRect(cell, r)
s.mu.Lock()
for i := r.Min.Y; i < r.Max.Y; i++ {
s.touch[i] = [2]int{r.Min.X, r.Width() - 1}
Expand Down Expand Up @@ -867,8 +867,8 @@ func (s *Screen) clearToBottom(w io.Writer, blank *Cell) {

s.updatePen(w, blank)
io.WriteString(w, ansi.EraseScreenBelow) //nolint:errcheck
s.curbuf.ClearInRect(Rect(col, row, s.curbuf.Width(), row+1))
s.curbuf.ClearInRect(Rect(0, row+1, s.curbuf.Width(), s.curbuf.Height()))
s.curbuf.ClearRect(Rect(col, row, s.curbuf.Width(), row+1))
s.curbuf.ClearRect(Rect(0, row+1, s.curbuf.Width(), s.curbuf.Height()))
}

// clearBottom tests if clearing the end of the screen would satisfy part of
Expand Down Expand Up @@ -934,7 +934,7 @@ func (s *Screen) clearBelow(w io.Writer, blank *Cell, row int) {
s.moveCursor(w, 0, row, false)
s.clearToBottom(w, blank)
s.cur.X, s.cur.Y = 0, row
s.curbuf.FillInRect(blank, Rect(0, row, s.curbuf.Width(), s.curbuf.Height()))
s.curbuf.FillRect(blank, Rect(0, row, s.curbuf.Width(), s.curbuf.Height()))
}

// clearUpdate forces a screen redraw.
Expand Down Expand Up @@ -1146,15 +1146,15 @@ func (s *Screen) Resize(width, height int) bool {

// Clear new columns and lines
if width > oldh {
s.ClearInRect(Rect(oldw-2, 0, width-oldw, height))
s.ClearRect(Rect(oldw-2, 0, width-oldw, height))
} else if width < oldw {
s.ClearInRect(Rect(width-1, 0, oldw-width, height))
s.ClearRect(Rect(width-1, 0, oldw-width, height))
}

if height > oldh {
s.ClearInRect(Rect(0, oldh-1, width, height-oldh))
s.ClearRect(Rect(0, oldh-1, width, height-oldh))
} else if height < oldh {
s.ClearInRect(Rect(0, height-1, width, oldh-height))
s.ClearRect(Rect(0, height-1, width, oldh-height))
}

s.mu.Lock()
Expand Down Expand Up @@ -1210,9 +1210,9 @@ func (s *Screen) newWindow(x, y, width, height int) (w *SubWindow, err error) {
type Window interface {
Cell(x int, y int) *Cell
Fill(cell *Cell) bool
FillInRect(cell *Cell, r Rectangle) bool
FillRect(cell *Cell, r Rectangle) bool
Clear() bool
ClearInRect(r Rectangle) bool
ClearRect(r Rectangle) bool
Draw(x int, y int, cell *Cell) (v bool)
Bounds() Rectangle
Resize(width, height int) bool
Expand Down Expand Up @@ -1262,33 +1262,33 @@ func (w *SubWindow) Cell(x int, y int) *Cell {

// Fill implements Window.
func (w *SubWindow) Fill(cell *Cell) bool {
return w.FillInRect(cell, w.Bounds())
return w.FillRect(cell, w.Bounds())
}

// FillInRect fills the cells in the specified rectangle with the specified
// FillRect fills the cells in the specified rectangle with the specified
// cell.
func (w *SubWindow) FillInRect(cell *Cell, r Rectangle) bool {
func (w *SubWindow) FillRect(cell *Cell, r Rectangle) bool {
if !r.In(w.Bounds().Rectangle) {
return false
}

w.scr.FillInRect(cell, r)
w.scr.FillRect(cell, r)
return true
}

// Clear implements Window.
func (w *SubWindow) Clear() bool {
return w.ClearInRect(w.Bounds())
return w.ClearRect(w.Bounds())
}

// ClearInRect clears the cells in the specified rectangle based on the current
// ClearRect clears the cells in the specified rectangle based on the current
// cursor background color. Use [SetPen] to set the background color.
func (w *SubWindow) ClearInRect(r Rectangle) bool {
func (w *SubWindow) ClearRect(r Rectangle) bool {
if !r.In(w.Bounds().Rectangle) {
return false
}

w.scr.ClearInRect(r)
w.scr.ClearRect(r)
return true
}

Expand Down

0 comments on commit 45c33cb

Please sign in to comment.