This commit refactors the keyboard enhancements functionality by
splitting the `WithKeyboardEnhancements` function into three separate
functions:
- `WithKeyReleases`: Enables support for reporting key release events.
- `WithUniformKeyLayout`: Enables support for reporting key events in a
uniform layout format.
- `RequestKeyDisambiguation`: Enables support for disambiguated key events.
This change improves clarity and usability by allowing users to enable
specific keyboard enhancements individually, rather than requiring them
to use a single function with multiple options.
Right now, there is inconsistencies between Windows and other
*nix platforms when it comes to keyboard enhancement handling.
Since we use the Windows Console API on Windows, we always get
disambiguated keys and release events.
To make the experience consistent across platforms, we always enable
disambiguated keys for *nix platforms, and we ignore release events on
Windows unless they are explicitly requested, the same way we do for
*nix platforms.
This change separates the viw from the main model by introducing new
interfaces `ViewModel` and `CursorModel`. The `ViewModel` interface
provides a view method that returns the string to render, while the
`CursorModel` interface provides a view method that returns the string
to render and the cursor position.
If a program does not implement a view interface, the program won't
render anything. This removes the need for the `WithoutRenderer` option.
This adds a new option to set the initial window size of the terminal
window. This is useful in testing and required for teatest/v2 after the
changes in the renderer. The cell-based cursed renderer heavily relies
on the terminal size, and it's important to have a way to set the size
manually for tests to run in a non-interactive environment.
refactor: keyboard: expose type and track requested and active
enhancements
This change exposes the `KeyboardEnhancements` type and tracks requested
and active enhancements in the `Program` struct. This change also
renames the `KeyboardEnhancement` type to `KeyboardEnhancementOption`
as well as`EnableKeyboardEnhancements` to `RequestKeyboardEnhancements`.
Fixes: https://github.com/charmbracelet/bubbletea/issues/1283
This change exposes the `KeyboardEnhancements` type and tracks requested
and active enhancements in the `Program` struct. This change also
renames the `KeyboardEnhancement` type to `KeyboardEnhancementOption`
and `keyboardEnhancements` to `KeyboardEnhancements` as well as
`EnableKeyboardEnhancements` to `RequestKeyboardEnhancements`.
* feat(SIGINT): better handle interrupts
This PR introduces `Interrupt()`, `InterruptMsg{}`, and
`ErrInterrupted`.
Users can still handle "ctrl+c" as before, but instead of return
`tea.Quit`, they can return `tea.Interrupt`.
Later on, they can `errors.If(err, tea.ErrInterrupted)` and
`os.Exit(130)` if they want to.
* chore: fix unrelated typo
it was bothering me
This commit changes the behavior of grapheme clustering to be opt-in
instead of opt-out. This is because some terminals like Apple Terminal
don't support DECRQM and DECRPM, which are required for querying and
setting the grapheme clustering state.
Apple Terminal, instead, replies with a `p` character when querying the
grapheme clustering state, which is not a valid response and breaks the
program output.
Right now, we only have one experimental feature to use the new cell buffer as a default renderer.
Use `TEA_EXPERIMENTAL=cellbuf` environment variable to enable the use of the cell buffer as the default renderer.
* feat: combine keyboard enhancements into a nicer API
This change combines the keyboard enhancements into a nicer API. Kitty
keyboard protocol and XTerm modifyOtherKeys are now combined into a
single API. This makes it easier to enable keyboard enhancements.
Use `WithKeyboardEnhancements` to enable keyboard enhancements. This
function accepts a list of `KeyboardEnhancement` functions that can be
used to enable different keyboard features.
For now, we only support the `WithReleaseKeys` enhancement which enables
support for reporting release key events.
* Update options.go
Co-authored-by: Christian Rocha <christian@rocha.is>
* chore: go mod tidy
* chore: gofumpt
* fix: simplify keyboard enhancements disambiguation
* feat: make KeyboardEnhancementsMsg helpers always return true on Windows
* fix: remove unused win32input mode
* refactor: rename KeyboardEnhancementsMsg methods
---------
Co-authored-by: Christian Rocha <christian@rocha.is>
This adds support for detecting the terminal's color profile. It adds a
new `ColorProfileMsg` message that get sent when the program starts. You
can force a specific color profile using the `WithColorProfile` option.
When a program requests the `RGB` or `Tc` terminfo capabilities, Bubble
Tea will read the response, if there is one, and upgrade the cached
color profile and send the new profile to the program again.
Supersedes: https://github.com/charmbracelet/bubbletea/pull/1142
Supersedes: https://github.com/charmbracelet/bubbletea/pull/1143