-
Notifications
You must be signed in to change notification settings - Fork 806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: reimplement the event loop with a sequence parser #1080
Conversation
Currently, Bubble Tea uses a simple lookup table to detect input events. Here, we're introducing an actual input sequence parser instead of simply using a lookup table. This will allow Bubble Tea programs to read all sorts of input events such Kitty keyboard, background color, mode report, and all sorts of ANSI sequence input events. Supersedes: #1079 Supersedes: #1014 Related: #869 Related: #163 Related: #918 Related: #850 Related: #207
go 1.21 | ||
|
||
toolchain go1.22.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this on purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, examples/
wouldn't build on go1.18 and this is what go mod tidy
gave me
This replaces enable/disable directives with exception to alt-screen and cursor visibility since those affect the renderer.
We need to initialize the tty and the input handler before writing to it.
) | ||
|
||
func TestParseSequence_Events(t *testing.T) { | ||
input := []byte("\x1b\x1b[Ztest\x00\x1b]10;rgb:1234/1234/1234\x07\x1b[27;2;27~\x1b[?1049;2$y") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we maybe be generating the input here programmatically? If this test fails, it seems like it might be a bit of a headache to figure out what went wrong with this sequence
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always good to have more tests. We already do for key sequences in key_test.go
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added more tests for Kitty/fixterms, Xterm modifyOtherKeys, and terminal bg/fg/cur colors in their respective PRs.
A modified F3 key press has the same sequence as cursor position report. We need to handle that by reporting both messages and letting the program determine which one to listen for. On most cases, programs don't care about modified F3 key press since terminals tend to have different sequences for it.
Move tracking bp to the program instead of the renderer. The renderer doesn't need to know about the state of bp and gains nothing from that information.
Use bitmap matching to check if a modifier contains another
Currently, Bubble Tea uses a simple lookup table to detect input events. Here, we're introducing an actual input sequence parser instead of simply using a lookup table. This will allow Bubble Tea programs to read all sorts of input events such Kitty keyboard, background color, mode report, and all sorts of ANSI sequence input events.
This PR includes the following changes:
OSC 52 ?
)KeyMsg
API in favor ofKeyPressMsg
andKeyReleaseMsg
KeyType
const values are different now. Programs that use int value comparison will break. E.g.key.Type == 13
where13
is the control code forCR
that corresponds to the enter key. (BREAKING CHANGE!)KeyMsg
and the second of typeKeyPressMsg
. This is to keep backwards compatibility and not break the APItea.Key
contains breaking changes (BREAKING CHANGE!)MouseMsg
in favor ofMouseClickMsg
,MouseReleaseMsg
,MouseWheelMsg
, andMouseMotionMsg
MouseMsg
type. And the second will have the new corresponding type. This is to keep backwards compatibility and not break the APItea.Mouse
contains breaking changes (BREAKING CHANGE!)CSI ? u
to the terminal)CSI u
PasteMsg
. UsePasteStartMsg
andPasteEndMsg
to listen to the start/end of the paste message.KeyMsg
and the second is of typePasteMsg
. This is to keep backwards compatibility and not break the APIXTGETTCAP
. These capabilities will get reported asTermcapMsg
modifyOtherKeys
keysTODO:
KeyPressMsg
storing it inkey.Runes
Supersedes: #1079
Supersedes: #1014
Related: #869
Related: #163
Related: #918
Related: #850
Related: #207