From 45c33cb7b57a7d1dd28480f107f3af4a7ac02e9e Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 10 Dec 2024 18:00:33 -0500 Subject: [PATCH] refactor(cellbuf): rename FillInRect to FillRect and ClearInRect to ClearRect --- cellbuf/buffer.go | 14 ++++++------ cellbuf/screen_write.go | 6 ++--- cellbuf/window.go | 50 ++++++++++++++++++++--------------------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/cellbuf/buffer.go b/cellbuf/buffer.go index 94690c98..70ac8097 100644 --- a/cellbuf/buffer.go +++ b/cellbuf/buffer.go @@ -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 @@ -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 diff --git a/cellbuf/screen_write.go b/cellbuf/screen_write.go index ae25286a..52fe9de6 100644 --- a/cellbuf/screen_write.go +++ b/cellbuf/screen_write.go @@ -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 @@ -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 diff --git a/cellbuf/window.go b/cellbuf/window.go index c61144a4..af785d5f 100644 --- a/cellbuf/window.go +++ b/cellbuf/window.go @@ -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} @@ -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} @@ -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 @@ -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. @@ -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() @@ -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 @@ -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 }