Commit Graph

174 Commits

Author SHA1 Message Date
Christian Muehlhaeuser cff7a5490b
chore: switch to soft fork of containerd/console
This fixes a couple of Windows-related issues. In the hope they will
eventually get merged upstream, at which point we can revert this
commit.
2023-03-07 16:15:32 +01: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
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