Commit Graph

183 Commits

Author SHA1 Message Date
Ayman Bagabas a154847611
feat: extended Coordinates mouse reporting & additional buttons support (#594)
* feat(mouse): add extended mouse & shift key support

Support SGR(1006) mouse mode
Support parsing shift key press
Support additional mouse buttons
Report which button was released
Report button motion

* fix: key.go sgr len missing calculation (#841)

* chore(test): add sgr mouse msg detect test

---------

Co-authored-by: robinsamuel <96998379+robin-samuel@users.noreply.github.com>
2023-12-04 11:50:59 -05:00
Ayman Bagabas 2bcb0af2e2
feat: add set-window-title command (#611)
Set the terminal window title using termenv.

Fixes: https://github.com/charmbracelet/bubbletea/issues/610
2023-12-04 11:50:27 -05:00
Carlos Alexandro Becker 5984e69f09
fix: race changing ignoreSignals (#791)
* fix: race changing ignoreSignals

* fix: atomic.Uint32
2023-11-07 13:49:00 -03:00
Christian Rocha f75684c986 chore: group handler type and methods together 2023-06-20 07:21:54 -04:00
tomfeigin f3e1b67605
(feat): Add option to set max FPS (#578)
* (feat): add option for setting FPS on renderer

Co-authored-by: Christian Rocha <christian@rocha.is>
2023-06-06 17:49:11 +02:00
Christian Rocha c267762438
fix(regression): auto-open a TTY when stdin is not a TTY (#746)
The regression was introduced in precisely this revision:
fcc805f3da

Closes #745.
2023-05-24 12:31:00 -04:00
Christian Rocha fcc805f3da chore: make input options mutually exclusive 2023-05-05 15:41:46 -04:00
Carlos Alexandro Becker 9cc3861bab
feat: tea.Wait (#722)
* feat: tea.Wait

wait for the underlying context to finish.

extract from #352

* fix: wait til the end of shutdown

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2023-05-04 16:30:30 -03:00
Christian Muehlhaeuser c56884c0e2
feat: add generic event filter (#536)
`WithFilter` lets you supply an event filter that will be invoked
before Bubble Tea processes a `tea.Msg`. The event filter can return
any `tea.Msg` which will then get handled by Bubble Tea instead of
the original event. If the event filter returns nil, the event
will be ignored and Bubble Tea will not process it.

As an example, this could be used to prevent a program from
shutting down if there are unsaved changes.

Based on the fantastic work by @aschey and supersedes #521.

Resolves #472.
2023-04-17 22:02:55 +02:00
Christian Muehlhaeuser 58c5e01d8c chore: fix linter warnings 2023-04-04 13:27:12 +02:00
Christian Muehlhaeuser 402d2b4e2b fix: stop renderer before launching a child process.
Stops the renderer before starting a child process, which prevents
the repaint race condition that writes to non-altscreen.
2023-03-07 10:09:36 +01:00
Alexander Jung 331a63bdca fix: Check if program cancelReader is is nil before invoking
This commit fixes an issue where a user may provider a nil input via
`tea.WithInput(nil)`.  This option method does not check if the input
is nil and sets the `withCustomInput` attribute with a nil input.
This logic is sound since a Tea program may not necessarily want to
handle any inputs from users (such as those in non-TTY environments).

However, a nil pointer exception is thrown during `tea.Run` because a
`cancelReader` is always invoked after the main renderer.  However,
its instantiation is variable and dependent on whether an input is
provided. To mitigate against this, this commit checks if a
`cancelReader` is non-nil.

Signed-off-by: Alexander Jung <alex@nderjung.net>
2023-02-08 17:04:49 +01:00
Christoffer Åström e95e1a0db5 feat: `sequence` support `BatchMsg` 2023-02-07 10:06:46 -05:00
Alexander Jung b217449c8e fix: Check msg cmd is not nil before invoking
GitHub-Fixes: #639
Signed-off-by: Alexander Jung <alex@nderjung.net>
2023-01-23 09:47:19 -05:00
Christian Muehlhaeuser 9c20a804d7 fix: don't close stdin
This allows programs to re-use stdin after the tea.Program has
finished.

Fixes #595.
2022-11-13 23:55:44 +01:00
Christian Muehlhaeuser 4f83c621fb chore: apply ProgramOptions before checking context
We don't need to set the background context if an outside context
was supplied.
2022-10-30 06:17:27 +01:00
Christian Muehlhaeuser e15bcb7e0e feat: tea.WithContext ProgramOption to supply a context
WithContext lets you specify a context in which to run the Program.
This is useful if you want to cancel the execution from outside.
When a Program gets cancelled it will exit with an error
ErrProgramKilled.
2022-10-23 05:59:10 +02:00
treilik 918d35746b feat: export BatchMsg
There's no good reason to keep it private. Exporting it helps
testability, debugging, and allows for a few special model.Update
implementations.
2022-10-22 22:51:46 +02:00
Christian Muehlhaeuser 80f44c9384 fix: detect terminal size after exec
Based on @knz's work in #499, but slightly supersedes this change.

A little more coupling in the resize handling, but a lot less code
& logic repetition.

Co-authored-by: Raphael 'kena' Poss <knz@thaumogen.net>
2022-10-22 22:02:56 +02:00
Christian Muehlhaeuser 9bcfc026a2 fix: restore Windows console mode on shutdown
The deferred Close call on our input reader caused the console mode
to be reset twice, and the incorrect, inner mode was applied last.
2022-10-20 20:38:33 +02:00
Raphael 'kena' Poss cbe309d624 fix: don't delay messages behind a long command 2022-10-16 17:06:27 +02:00
Christian Muehlhaeuser 3609d87e70 fix: don't block in Send after shutdown
Send should block before a tea.Program has been started, but result
in a no-op when it has already been terminated.

Fixed godocs.
2022-10-15 04:21:44 +02:00
Christian Muehlhaeuser a520b7f4e1 fix: ensure a final render before a clean shutdown
Fixes #274.
2022-10-13 07:55:48 +02:00
Christian Muehlhaeuser 1ed623fdc0 fix: kill should result in Start returning an error
This fixes Kill resulting in a final nil model being returned.

We can also drop the kill channel and rely on our existing context
channel.
2022-10-12 05:26:39 +02:00
Christian Muehlhaeuser fd18c149df fix: restoreTerminalState resets mouse handling state
- fixes mouse handling being enabled during sub commands
- fixes shutdown order: restore mouse state before alt screen
2022-10-12 00:36:09 +02:00
Josh Soref 4aa9ce489b
docs: fix spelling / various typos (#526) 2022-10-11 14:40:01 +02:00
Christian Muehlhaeuser 8703897aad fix: timeout when waiting for CancelReader
Fixes #524.
2022-10-11 12:42:40 +02:00
Christian Muehlhaeuser e119cd88b2 fix: prevent double repaint when restoring terminal 2022-10-09 05:57:23 +02:00
Christian Muehlhaeuser 1c3b792596 chore: don't use deprecated methods internally 2022-10-09 05:33:32 +02:00
Christian Muehlhaeuser 6b77c8fc10 chore: rename StartReturningModel to Run
Added aliases for the old functions, but deprecated them.
2022-10-08 01:34:17 +02:00
Leandro López (inkel) 8b8fd12201 Update Program.Start docs to indicate it's a blocking operation
This addresses one of the concerns in #299.
2022-10-08 00:51:36 +02:00
Christian Muehlhaeuser 9bde73bd4e chore: reorganize Program struct 2022-10-07 23:39:36 +02:00
Christian Muehlhaeuser fbb00cc71e fix: close input on shutdown whenever possible 2022-10-07 23:38:27 +02:00
Christian Muehlhaeuser 6477a53545 chore: store handlers and simplify teardown 2022-10-07 23:18:35 +02:00
Christian Muehlhaeuser 76ce669474 chore: make CatchPanics an option flag 2022-10-07 22:33:06 +02:00
Christian Muehlhaeuser 0ac6702e11 feat: make signal handler optional
You can now initialize a tea app without a signal handler:

p := NewProgram(model, WithoutSignalHandler())
2022-10-07 21:46:06 +02:00
Christian Muehlhaeuser 2696b2f339 chore: break up Start into several, more maintainable methods 2022-10-07 20:13:57 +02:00
Christian Muehlhaeuser 6b6bf6ab6d fix: don't access output from outside renderer 2022-10-04 06:12:17 +02:00
Raphael 'kena' Poss 6e1065830a feat: support a Clear command 2022-10-04 06:01:52 +02:00
Christian Muehlhaeuser 37b79f55f1 feat: add tea.ShowCursor, complementing tea.HideCursor 2022-10-04 05:39:38 +02:00
Christian Muehlhaeuser 8d6bdcf2fd chore: reorganize command helpers 2022-10-04 05:29:41 +02:00
Christian Muehlhaeuser e4ca150210 chore: reorganize screen commands & messages 2022-10-04 05:20:07 +02:00
Christian Muehlhaeuser ea36e19bee fix: move output handling to renderer 2022-10-04 05:06:42 +02:00
Christian Muehlhaeuser b404baff60 chore: remove incorrect space before nolint directives 2022-09-27 10:02:34 +02:00
Christian Muehlhaeuser b1c9d80603 fix: wait for read-loop to finish before spawning child process 2022-09-27 09:10:54 +02:00
Raphael 'kena' Poss cb4ff09b13 Fix 1-indexing when entering alt screen 2022-09-27 03:46:19 +02:00
Christian Muehlhaeuser 6c449e55bf feat: use Termenv.Output to write to tty 2022-09-27 02:49:36 +02:00
Christian Rocha 989d49f3e6 feat: add Sequence for running commands in order. Closes #413.
This deprecates Sequentially.
2022-08-30 13:07:05 -07:00
Johann Cruz 636f2c2726
feat: catch SIGTERM (#412)
* Added SIGTERM Signal.

* docs: cleanup SIGINT/SIGTERM doc comment

Co-authored-by: Christian Rocha <christian@rocha.is>
2022-08-24 20:32:12 -07:00
Christian Muehlhaeuser 1e1b5f716d chore: gofmt sources 2022-08-15 12:25:55 +02:00