Skip to content

Commit

Permalink
refactor(input): accept various XTWINOPS reports
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Jan 17, 2025
1 parent 2351af4 commit c0c2136
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
22 changes: 6 additions & 16 deletions input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,10 @@ type WindowSizeEvent struct {
Height int
}

// WindowAreaEvent is used to report the terminal area size in pixels. This is
// the response from a [ansi.WindowOp] [ansi.ReportWindowSizeWinOp] request.
// You can use this along with [WindowSizeEvent] to get the terminal cell size.
//
// Example:
//
// // Assuming we already have a WindowSizeEvent
// var winsize WindowSizeEvent
// switch ev := ev.(type) {
// case WindowAreaEvent:
// cellWidth := ev.Width / winsize.Width
// cellHeight := ev.Height / winsize.Height
// }
type WindowAreaEvent struct {
Width int
Height int
// WindowOpEvent is a window operation (XTWINOPS) report event. This is used to
// report various window operations such as reporting the window size or cell
// size.
type WindowOpEvent struct {
Op int
Args []int
}
2 changes: 1 addition & 1 deletion input/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestParseSequence(t *testing.T) {
seqTest{
[]byte("\x1b[4;24;80t"),
[]Event{
WindowAreaEvent{Width: 80, Height: 24},
WindowOpEvent{Op: 4, Args: []int{24, 80}},
},
},

Expand Down
15 changes: 7 additions & 8 deletions input/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,17 +520,16 @@ func (p *Parser) parseCsi(b []byte) (int, Event) {
break
}

switch param {
case 4:
// Text area size report CSI t
height, _ := csi.Param(1, 0)
width, _ := csi.Param(2, 0)
return i, WindowAreaEvent{
Height: height,
Width: width,
var winop WindowOpEvent
winop.Op = param
for j := 1; j < paramsLen; j++ {
val, ok := csi.Param(j, 0)
if ok {
winop.Args = append(winop.Args, val)
}
}

return i, winop
}
return i, UnknownEvent(b[:i])
}
Expand Down

0 comments on commit c0c2136

Please sign in to comment.