You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Current Bubble Tea input handling is quite limiting as it doesn't support parsing input events such as cursor position report, fixterms & Kitty keyboard, and other terminal features. This is because we only do map lookups for common key sequences used by most terminals.
This is where the work on charmbracelet/x/input began. This new input package can replace the existing Bubble Tea input handler to enhance and improve parsing input events and support. This means we can support more terminal features since we can now parse input sequences such as the ones found in the Kitty keyboard protocol and others.
Advanced Bubble Tea Input Handling
This gives us high fidelity input events like key up events and formerly unavailable keybindings like shift+enter!
So what’s new?
Well the big news is that, in modern terminals, you are freed from the shackles of old terminal ways and now have access to a bunch of key and mouse commands that weren’t previously available. That’s right the shift+enter dream is now a reality. Bubble Tea game engine? Now you can.
Mouse events also received an upgrade, now you can distingiush between mouse events based on the msg type.
switchmsg:=msg.(type) {
case tea.KeyDownMsg:
switchmsg.String() {
case"space":
// Push-to-talk: mic on
}
case tea.KeyUpMsg:
switchmsg.String() {
case"space":
// Push-to-talk: mic off
}
case tea.MouseDownMsg:
// Pen: start drawingcase tea.MouseUpMsg:
// Pen: stop drawingcase tea.MouseWheelMsg:
// View: scroll up/down/left/right?case tea.MouseMotionMsg:
// Drag-n-drop
}
You can still use tea.KeyMsg since it's just an alias to tea.KeyDownMsg. The same goes for tea.MouseMsg and tea.MouseDownMsg.
Keep in mind that, at the moment, the enhanced keyboard is only supported on Windows and the following terminals…
Ghostty
Kitty
Alacrity
iTerm2
Foot
WezTerm
Rio
Windows Terminal
Note: on non-Windows platforms, the enhanced keyboard relies on the Kitty Keyboard protocol which all the above (except Windows Terminal) support. In case of an unsupported terminal, the application won't get tea.KeyUpMsgs. You can check ctx.SupportsEnhancedKeyboard() from the Bubble Tea Context proposal to check whether the terminal supports enhanced keyboard.
Common keys are still the same except that the KeyCtrl and KeyShift variants and the key.Alt property are now merged into tea.KeyMod. Here's a some of the common keys available.
// Beforeswitchmsg.Type {
casetea.Runes== []rune{'a'}:
// The letter a
}
// Afterswitchmsg.Type {
casetea.Rune=='a':
// The letter a
}
If bracketed paste is enabled, which it is by default, you now need to handle pastes like so:
switchmsg {
casetea.PasteMsg:
// Here’s a big ol’ paste!
}
Matching against mouse events is almost the same. We've dropped msg.Action and msg.Ctrl|Alt|Shift in favor of msg.Mod. The action is now split into different types and the modifiers are combinied into a single field msg.Mod.
A mouse message can have on of the following msg.Buttons:
Current Bubble Tea input handling is quite limiting as it doesn't support parsing input events such as cursor position report, fixterms & Kitty keyboard, and other terminal features. This is because we only do map lookups for common key sequences used by most terminals.
This is where the work on
charmbracelet/x/input
began. This newinput
package can replace the existing Bubble Tea input handler to enhance and improve parsing input events and support. This means we can support more terminal features since we can now parse input sequences such as the ones found in the Kitty keyboard protocol and others.Advanced Bubble Tea Input Handling
This gives us high fidelity input events like key up events and formerly unavailable keybindings like shift+enter!
So what’s new?
Well the big news is that, in modern terminals, you are freed from the shackles of old terminal ways and now have access to a bunch of key and mouse commands that weren’t previously available. That’s right the shift+enter dream is now a reality. Bubble Tea game engine? Now you can.
Mouse events also received an upgrade, now you can distingiush between mouse events based on the msg type.
You can still use
tea.KeyMsg
since it's just an alias totea.KeyDownMsg
. The same goes fortea.MouseMsg
andtea.MouseDownMsg
.Keep in mind that, at the moment, the enhanced keyboard is only supported on Windows and the following terminals…
Note: on non-Windows platforms, the enhanced keyboard relies on the Kitty Keyboard protocol which all the above (except Windows Terminal) support. In case of an unsupported terminal, the application won't get
tea.KeyUpMsg
s. You can checkctx.SupportsEnhancedKeyboard()
from the Bubble Tea Context proposal to check whether the terminal supports enhanced keyboard.Common keys are still the same except that the
KeyCtrl
andKeyShift
variants and thekey.Alt
property are now merged intotea.KeyMod
. Here's a some of the common keys available.How to upgrade
If you’re matching strings, there’s nothing to do:
Special keys are now indicated in
tea.KeySym
:If you’re going for ultimate safety:
If you're matching a modifier key:
If you're matching multiple modifier keys:
If you’re matching runes:
If bracketed paste is enabled, which it is by default, you now need to handle pastes like so:
Matching against mouse events is almost the same. We've dropped
msg.Action
andmsg.Ctrl|Alt|Shift
in favor ofmsg.Mod
. The action is now split into different types and the modifiers are combinied into a single fieldmsg.Mod
.A mouse message can have on of the following
msg.Button
s:Use the
fmt.Stringer
interface to easily match against different button combos:You can now use the same string matchin to match against release, motion, and wheel events.
If you're matching against mouse clicks:
Wanna also capture wheel events?
Track mouse movements?
If you want to detect modifier keys:
You can try this proposal in the
beta
branch hereThe text was updated successfully, but these errors were encountered: