Skip to content

Commit

Permalink
fix: key.go sgr len missing calculation (#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-samuel authored Oct 16, 2023
1 parent 19d760d commit e07c862
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions key.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,14 +575,16 @@ var mouseSGRRegex = regexp.MustCompile(`(\d+);(\d+);(\d+)([Mm])`)
func detectOneMsg(b []byte) (w int, msg Msg) {
// Detect mouse events.
// X10 mouse events have a length of 6 bytes
const mouseEventLen = 6
if len(b) >= mouseEventLen && b[0] == '\x1b' && b[1] == '[' {
const mouseEventX10Len = 6
if len(b) >= mouseEventX10Len && b[0] == '\x1b' && b[1] == '[' {
switch b[2] {
case 'M':
return mouseEventLen, MouseMsg(parseX10MouseEvent(b))
return mouseEventX10Len, MouseMsg(parseX10MouseEvent(b))
case '<':
if mouseSGRRegex.Match(b[3:]) {
return mouseEventLen, MouseMsg(parseSGRMouseEvent(b))
if matchIndices := mouseSGRRegex.FindSubmatchIndex(b[3:]); matchIndices != nil {
// SGR mouse events length is the length of the match plus the length of the escape sequence
mouseEventSGRLen := matchIndices[1] + 3

Check failure on line 586 in key.go

View workflow job for this annotation

GitHub Actions / lint-soft

mnd: Magic number: 3, in <operation> detected (gomnd)

Check failure on line 586 in key.go

View workflow job for this annotation

GitHub Actions / lint-soft

mnd: Magic number: 3, in <operation> detected (gomnd)
return mouseEventSGRLen, MouseMsg(parseSGRMouseEvent(b))
}
}
}
Expand Down

0 comments on commit e07c862

Please sign in to comment.