Commit Graph

150 Commits

Author SHA1 Message Date
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
Maas Lalani db4f6474c9
doc: Fix `Printf` typo (#358) 2022-06-28 15:34:22 -04:00
Max ebabec7008
feat: print unmanaged output above the application (#249)
* merge Adjective-Object/tea_log_renderer into standard renderer

* rename queuedMessages -> queuedMessageLines & break apart strings during message processing

* delete cursorDownBy

* += 1 -> ++ to make the linter happy

* add skipLines[] tracking back to standard renderer, and add rename skippedLines local to jumpedLines to clarify they are separate comments

* request repaint when a message is recieved

* Convert Println and Printf to commands

* Add package manager example demonstrating tea.Printf

* Use Unix instead of UnixMicro for Go 1.13 support in CI

* fix off by one in std renderer

* add Printf/Println to tea.go

* revert attempt at sequence compression + cursorUpBy

Co-authored-by: Maxwell Huang-Hobbs <mahuangh@microsoft.com>
Co-authored-by: Christian Rocha <christian@rocha.is>
2022-06-22 12:53:02 -04:00
Christian Muehlhaeuser 21de41ac02 docs: fix deprecation notes 2022-06-08 15:02:12 +02:00
Georgi Dimitrov 958dc20024 fix: race condition on repaint with alt screen
I didn't realise at the time, but the tea.Program and the renderer share
the mutex. This make the code difficult to reason about - it turns out
the program sometimes acquires the lock and then calls the
`setAltScreen` method of the renderer which in turns calls `repaint`.
That causes a deadlock as `repaint` is trying to acquire the lock too.
2022-06-07 06:47:46 +02:00
Christian Rocha 775dbfbeff
chore(exec): small API edits (#323)
* feat: add OSExec helper function for running exec.Cmds

* chore: for now, un-expose WrapExecCommand

* chore: move exec struff into its own file

* chore(exec): better name for Exec func that wraps exec.Cmd (thanks, @toby)
2022-06-01 17:12:21 -07:00
Carlos A Becker a5f28a3a04 docs: fixed mentions to exec.Command
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-05-16 16:46:27 +00:00
Christian Muehlhaeuser 3795c036c4
add: Exec, ReleaseTerminal and RestoreTerminal to re-use input and terminal (#237)
* add: program.ReleaseTerminal and RestoreTerminal to re-use input & terminal

* chore(examples): add altscreen toggling to exec demo

* chore: put low-level altscreen stuff alongside other screen funcs

* docs: edit GoDocs for ReleaseTerminal and RestoreTerminal

* feat(renderer): add internal Msg renderMsg to immediately repaint

* fix: repaint instantly on RestoreTerminal

* fix: restore the altscreen state when restoring the terminal

* feat: implement Cmd-based API for blocking *exec.Cmds

* feat: allow Exec to return custom messages

* feat: allow Exec to be run without a callback

* fix: separate parameters for exec.Command examples

* fix: error message would get printed over by prompt in exec example

* fix: ignore signals while child process is running

* feat: allow to execute other things besides exec.Commands (#280)

* feat: allow to execute other things besides exec.Commands.

* fix: lint issues

* fix: renames, examples

* fix: callback type should be exported

* docs(exce): tiny ExecCommand doc comment correction

* chore(exec): break out Cmd for clarity's sake in example

* fix(exec): give the terminal a moment to catch up if exiting altscreen

* docs(exec): tidy up doc comments

* chore(exec): disambiguate methods for restoring the terminal state vs input

Co-authored-by: Christian Rocha <christian@rocha.is>
Co-authored-by: Carlos A Becker <caarlos0@gmail.com>
2022-04-12 10:23:10 -04:00
Christian Muehlhaeuser 515ef02733 Move cancelreader into a separate package 2022-04-05 20:41:21 +02:00
Christian Rocha 9a1310846c docs: Program#Send, Program#Quit, and Program#Kill no longer provisional 2022-03-31 14:38:13 -04:00
Christian Muehlhaeuser 2296184dc5 fix: don't check terminal size if we're not writing to a terminal 2022-02-14 17:00:40 -05:00
Christian Muehlhaeuser 6301f93cb2 Support receiving batched mouse events
Mouse events may trigger more than a single events simultaneously.

Fixes #212.
2022-02-13 08:40:04 +01:00
Ayman Bagabas 42cd4c3191 feat: kill the program and restore terminal state
* Add Kill() to force kill the program from the outside
* Prevent renderer channel from being closed multiple times
2022-02-08 10:13:05 -08:00
Carlos Alexandro Becker 9a06319ff1
feat: tea.Batch returns nil if all cmds are nil (#217)
Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
2022-02-03 12:08:34 -03:00
Christian Stewart 608fde59ed fix(tea): allocate msgs channel in constructor
Race condition bug: Start() is called in a new gorotuine, then Send(). If the
Send happens before the msgs channel is allocated, the message is dropped.

Instead allocate the channel in the constructor, so msgs is never nil.

Signed-off-by: Christian Stewart <christian@paral.in>
2022-01-14 13:15:29 -05:00
Christian Rocha 119144e78c ANSI compression is now opt-in via the WithANSICompressor program option 2021-10-30 13:04:27 -04:00
Niklas Johansson 56aa4efb60 tea: Add StartReturningModel()
Sometimes it is useful to obtain the final model after the
program has finished. Add StartReturningModel() (Model, error),
so that it is possible to obtain the final model.

Make sure to keep the original Start() error function, so that
everything is backwards compatible.
2021-10-28 14:19:46 -04:00
Christian Rocha 1f12bda862 Add program-level quit convenience method 2021-10-15 10:37:25 -04:00
Christian Rocha 0e7cd09bf6 Tidy up comments 2021-09-28 14:00:29 -04:00
Erik G e402e8b567
Cancelable reads (#120)
This commit implements cancelable reads, which allows Bubble Tea programs to run in succession in a single application. It also makes sure all goroutines terminate before `Program.Start()` returns.

Closes #24.
2021-09-28 13:30:11 -04:00
Christian Rocha ad19c664fe Condense/scope init cmd 2021-09-07 15:37:14 -04:00
Christian Rocha ea0550121e Don't close the msgs channel on shutdown 2021-08-02 10:50:04 -04:00
Christian Rocha 5f41a91e02 Fix Windows stuff related to the refactor at 49a5d16 2021-08-02 10:50:04 -04:00
Christian Rocha 4bfad658ad Simplify how we listen for window resizes 2021-08-02 10:50:04 -04:00
Christian Rocha 30fd7a8f20 Better logic in input checks 2021-08-02 10:50:04 -04:00
Christian Rocha 9f9b3aea96 Read input regardless of whether or not it's a TTY
This commit also contains some refactors:

* Refactor away inputStatus type
* Refactor away program.inputIsTTY member
* Simplify how we setup and restore input when it's a TTY
2021-08-02 10:50:04 -04:00
Christian Rocha 9826251f08 Add WithInputTTY ProgramOption 2021-08-02 10:50:04 -04:00
Christian Rocha e87344b791 Move ProgramOptions into a separate file 2021-08-02 10:50:04 -04:00
Christian Rocha 3a9ede46f6 Condense a scoped if-statement 2021-08-02 10:50:04 -04:00
Christian Rocha 0886ee26b0 Msgs can now be sent to Programs with Program.Send(Msg) 2021-07-01 11:06:21 -04:00
Christian Rocha 1f773e8f20 Fix a race where artifacts could print when exiting a program
This commit also consolidates the exit operations for consistency's
sake, and adds a kill() method to renderers for stopping them without
performing any final rendering.
2021-06-02 14:49:54 -04:00
Christian Rocha 85ab476698 Add ProgramOptions for entering the altscreen and enabling the mouse
Because they run ansyncronously, the analogous commands, when run in
a Model's Init() function, could fire after the renderer has starting
writing to output, rendering artifacts to the commandline.
2021-06-02 14:49:54 -04:00
Christian Rocha 035d2abd3e Properly cast inputStatus types + mark related linter false positive 2021-05-31 10:43:31 -04:00
Christian Rocha 3e98f55adf Add linter ignore rule for windows-related false positive on unix 2021-05-31 10:43:31 -04:00