* 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>
`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.
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>
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.
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>
* 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>
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.
* 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)
* 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>