From 081d4cf202308298c215e9ccd1f31830bbac6006 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Fri, 24 Jan 2025 16:59:03 -0500 Subject: [PATCH] feat(cellbuf): use ansi method type --- cellbuf/method.go | 11 ----------- cellbuf/window.go | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 22 deletions(-) delete mode 100644 cellbuf/method.go diff --git a/cellbuf/method.go b/cellbuf/method.go deleted file mode 100644 index 815e8a81..00000000 --- a/cellbuf/method.go +++ /dev/null @@ -1,11 +0,0 @@ -package cellbuf - -// Method is a type that represents the how the renderer should calculate the -// display width of cells. -type Method uint8 - -// Display width modes. -const ( - WcWidth Method = iota - GraphemeWidth -) diff --git a/cellbuf/window.go b/cellbuf/window.go index 243e7ecd..9ffa9573 100644 --- a/cellbuf/window.go +++ b/cellbuf/window.go @@ -11,11 +11,11 @@ import ( // Window represents a [Screen] 2D window. type Window struct { - s *Screen // the screen this window belongs to - cur Cursor // the current cursor pos, style, and link - method Method // the method to use for calculating the width of the cells - x, y int // the starting position of the window - w, h int // the width and height of the window + s *Screen // the screen this window belongs to + cur Cursor // the current cursor pos, style, and link + method ansi.Method // the method to use for calculating the width of the cells + x, y int // the starting position of the window + w, h int // the width and height of the window } // NewWindow creates a new window. Note that the window is not @@ -75,7 +75,7 @@ func (c *Window) CellAt(x, y int) *Cell { // SetMethod sets the method to use for calculating the width of the cells. // The default method is [WcWidth]. -func (c *Window) SetMethod(method Method) { +func (c *Window) SetMethod(method ansi.Method) { c.method = method } @@ -166,9 +166,9 @@ func (c *Window) Fill(cell *Cell) bool { // position, styles and attributes. func (c *Window) FillString(s string) (v bool) { switch c.method { - case WcWidth: + case ansi.WcWidth: v = c.Fill(NewCellString(s)) - case GraphemeWidth: + case ansi.GraphemeWidth: v = c.Fill(NewGraphemeCell(s)) } return @@ -262,7 +262,7 @@ func (c *Window) drawString(s string, x, y int, opts *drawOpts) { var tail Cell if opts.truncate && len(opts.tail) > 0 { - if c.method == WcWidth { + if c.method == ansi.WcWidth { tail = *NewCellString(opts.tail) } else { tail = *NewGraphemeCell(opts.tail) @@ -277,7 +277,7 @@ func (c *Window) drawString(s string, x, y int, opts *drawOpts) { switch width { case 1, 2, 3, 4: // wide cells can go up to 4 cells wide switch c.method { - case WcWidth: + case ansi.WcWidth: cell = NewCellString(seq) // We're breaking the grapheme to respect wcwidth's behavior @@ -288,7 +288,7 @@ func (c *Window) drawString(s string, x, y int, opts *drawOpts) { } newState = 0 - case GraphemeWidth: + case ansi.GraphemeWidth: // [ansi.DecodeSequence] already handles grapheme clusters cell = newGraphemeCell(seq, width) }