Skip to content

Commit

Permalink
feat: support changing the cursor style
Browse files Browse the repository at this point in the history
This commit adds support for changing the cursor style. The new
`SetCursorStyle` command can be used to change the cursor style to one of
the following:

- `CursorBlock`
- `CursorUnderline`
- `CursorBar`
  • Loading branch information
aymanbagabas committed Oct 16, 2024
1 parent d26972f commit aef9fdd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,26 @@ type CursorPositionMsg struct {
// Column is the column number.
Column int
}

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

// Cursor styles.
const (
CursorBlock CursorStyle = 1
CursorUnderline CursorStyle = 3
CursorBar CursorStyle = 5
)

// setCursorStyle is an internal message that sets the cursor style.
type setCursorStyle int

// SetCursorStyle is a command that sets the terminal cursor style.
func SetCursorStyle(style CursorStyle, blink bool) Cmd {
if !blink {
style++
}
return func() Msg {
return setCursorStyle(style)
}
}
3 changes: 3 additions & 0 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {
p.suspend()
}

case setCursorStyle:
p.execute(ansi.SetCursorStyle(int(msg)))

case modeReportMsg:
switch msg.Mode {
case graphemeClustering:
Expand Down

0 comments on commit aef9fdd

Please sign in to comment.