Replace mattn/isatty and containerd/console with golang.org/x/term.
This mostly affects Windows. On Windows, unlike Unix, the console (TTY)
has different handles for input/output. Using the Console API, we need
to enable VT input on the input handle (CONIN) and VT processing on the
output handle (CONOUT). Doing so enables processing VT sequences on
Windows i.e. ANSI colors, mouse sequences, cursor movements, etc.
We already handle enabling VT processing for the program output using
Termenv `EnableVirtualTerminalProcessing`. For the input side, we enable
VT input right before setting the console to raw.
By doing this, we can drop both containerd/console and mattn/isatty.
* 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>