Skip to content

Commit

Permalink
fix: use x and y instead of row and column for CursorPositionMsg
Browse files Browse the repository at this point in the history
This means we're now 0-indexed, which is consistent with the rest of the
library.
  • Loading branch information
aymanbagabas committed Oct 21, 2024
1 parent 8f0d124 commit b9292e7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
8 changes: 1 addition & 7 deletions cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ package tea
import "image"

// CursorPositionMsg is a message that represents the terminal cursor position.
type CursorPositionMsg struct {
// Row is the row number.
Row int

// Column is the column number.
Column int
}
type CursorPositionMsg image.Point

// CursorStyle is a style that represents the terminal cursor.
type CursorStyle int
Expand Down
2 changes: 1 addition & 1 deletion key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func buildBaseSeqTests() []seqTest {
// position report having the same sequence. See [parseCsi] for more
// information.
if f3CurPosRegexp.MatchString(seq) {
st.msgs = []Msg{k, CursorPositionMsg{Row: 1, Column: int(key.Mod) + 1}}
st.msgs = []Msg{k, CursorPositionMsg{Y: 0, X: int(key.Mod)}}
}
td = append(td, st)
}
Expand Down
4 changes: 2 additions & 2 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func parseCsi(b []byte) (int, Msg) {
// This report may return a third parameter representing the page
// number, but we don't really need it.
if paramsLen >= 2 && csi.Param(0) != -1 && csi.Param(1) != -1 {
return i, CursorPositionMsg{Row: csi.Param(0), Column: csi.Param(1)}
return i, CursorPositionMsg{Y: csi.Param(0) - 1, X: csi.Param(1) - 1}
}
case 'm' | '<'<<parser.MarkerShift, 'M' | '<'<<parser.MarkerShift:
// Handle SGR mouse
Expand All @@ -275,7 +275,7 @@ func parseCsi(b []byte) (int, Msg) {
case 'R':
// Cursor position report OR modified F3
if paramsLen == 2 && csi.Param(0) != -1 && csi.Param(1) != -1 {
m := CursorPositionMsg{Row: csi.Param(0), Column: csi.Param(1)}
m := CursorPositionMsg{Y: csi.Param(0) - 1, X: csi.Param(1) - 1}
if csi.Param(0) == 1 && csi.Param(1)-1 <= int(ModMeta|ModShift|ModAlt|ModCtrl) {
// XXX: We cannot differentiate between cursor position report and
// CSI 1 ; <mod> R (which is modified F3) when the cursor is at the
Expand Down

0 comments on commit b9292e7

Please sign in to comment.