From c0c213657577c20a4a82f469ebaa9c3af626907c Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Fri, 17 Jan 2025 14:20:18 +0300 Subject: [PATCH] refactor(input): accept various XTWINOPS reports --- input/input.go | 22 ++++++---------------- input/key_test.go | 2 +- input/parse.go | 15 +++++++-------- 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/input/input.go b/input/input.go index 6d92891d..d7624423 100644 --- a/input/input.go +++ b/input/input.go @@ -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 } diff --git a/input/key_test.go b/input/key_test.go index 45b325fb..b7719299 100644 --- a/input/key_test.go +++ b/input/key_test.go @@ -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}}, }, }, diff --git a/input/parse.go b/input/parse.go index 750115c9..c6453d12 100644 --- a/input/parse.go +++ b/input/parse.go @@ -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]) }