Skip to content

Commit

Permalink
refactor: rename CursorStyle to CursorShape
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Jan 23, 2025
1 parent 248ea91 commit 99e3bbf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
6 changes: 3 additions & 3 deletions cursed_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ func (s *cursedRenderer) flush() error {
s.scr.MoveTo(cur.Position.X, cur.Position.Y)
s.cursor.Position = cur.Position

if cur.Style != s.cursor.Style || cur.Blink != s.cursor.Blink {
cursorStyle := encodeCursorStyle(cur.Style, cur.Blink)
if cur.Shape != s.cursor.Shape || cur.Blink != s.cursor.Blink {
cursorStyle := encodeCursorStyle(cur.Shape, cur.Blink)
io.WriteString(s.w, ansi.SetCursorStyle(cursorStyle)) //nolint:errcheck
s.cursor.Style = cur.Style
s.cursor.Shape = cur.Shape
s.cursor.Blink = cur.Blink
}
if cur.Color != s.cursor.Color {
Expand Down
8 changes: 4 additions & 4 deletions cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ type Position image.Point
// CursorPositionMsg is a message that represents the terminal cursor position.
type CursorPositionMsg Position

// CursorStyle is a style that represents the terminal cursor.
type CursorStyle int
// CursorShape represents a terminal cursor shape.
type CursorShape int

// Cursor styles.
// Cursor shapes.
const (
CursorBlock CursorStyle = iota
CursorBlock CursorShape = iota
CursorUnderline
CursorBar
)
Expand Down
6 changes: 3 additions & 3 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ type Cursor struct {
// Color is a [color.Color] that determines the cursor's color.
Color color.Color

// Style is a [CursorStyle] that determines the cursor's style.
Style CursorStyle
// Shape is a [CursorShape] that determines the cursor's shape.
Shape CursorShape

// Blink is a boolean that determines whether the cursor should blink.
Blink bool
Expand All @@ -24,7 +24,7 @@ func NewCursor(x, y int) *Cursor {
return &Cursor{
Position: Position{X: x, Y: y},
Color: nil,
Style: CursorBlock,
Shape: CursorBlock,
Blink: true,
}
}
Expand Down
11 changes: 1 addition & 10 deletions renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func Printf(template string, args ...interface{}) Cmd {

// encodeCursorStyle returns the integer value for the given cursor style and
// blink state.
func encodeCursorStyle(style CursorStyle, blink bool) int {
func encodeCursorStyle(style CursorShape, blink bool) int {
// We're using the ANSI escape sequence values for cursor styles.
// We need to map both [style] and [steady] to the correct value.
style = (style * 2) + 1
Expand All @@ -104,12 +104,3 @@ func encodeCursorStyle(style CursorStyle, blink bool) int {
}
return int(style)
}

// decodeCursorStyle decodes the cursor style from the integer value into
// CursorStyle and blink state.
func decodeCursorStyle(style int) (CursorStyle, bool) {
style--
blink := style%2 == 0
style /= 2
return CursorStyle(style), blink
}

0 comments on commit 99e3bbf

Please sign in to comment.