Commit Graph

38 Commits

Author SHA1 Message Date
Raphael 'kena' Poss 2b46020ca0
feat: bracketed paste (#397)
* feat: bracketed paste

This introduces support for input via bracketed paste, where escape
characters in the pasted input are not interpreted.

Pasted input are marked as a special field in the KeyMsg. This is
useful because pasted input may need sanitation in individual widgets.

* fix(key): support bracketed paste with short reads

Some terminal emulators feed the bracketed paste data in multiple
chunks, which may not be aligned on a 256 byte boundary. So it's
possible for `input.Read` to return less than 256 bytes read
but while there's still more data to be read to complete a bracketed
paste input.

---------

Co-authored-by: Christian Muehlhaeuser <muesli@gmail.com>
2024-02-05 14:49:09 +01:00
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
Eng Zer Jun 12f405723d
refactor: remove redundant nil check in `flush` (#812)
From the Go docs:

  "If the map is nil, the number of iterations is 0." [1]

Therefore, an additional nil check for before the loop is unnecessary.

[1]: https://go.dev/ref/spec#For_range

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-08-24 09:17:44 -07: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 Muehlhaeuser 44f17fa1c0 fix: stop renderer before acquiring renderer mutex 2023-06-05 10:05:38 +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
Christian Muehlhaeuser a136799ed3 fix: renderer only stops once
Ensure the tea renderer can be stopped and restarted more than once.
2023-03-06 14:38:49 +01:00
Christian Muehlhaeuser 0f1ce7f2d9 fix: maintain cursor visibility across altscreen state switch
Based on #462 and #452 by @londek, but fixes maintaining the
current visibility state across altscreen state changes.

This makes the behavior consistent across terminals, some of which
keep separate state for altscreen and regular buffer.

Fixes #190.
2022-10-23 03:25:11 +02:00
Christian Muehlhaeuser a7067fbfa2 fix: prevent renderer from overflowing available height
Drops lines from the top when the render buffer is taller than the
available height.

Fixes #297.
2022-10-18 06:33:37 +02:00
Christian Muehlhaeuser 99ad2eda0d fix: also lock mutex when accessing state read-only 2022-10-13 06:56:45 +02:00
Christian Muehlhaeuser db664820d4 fix: lock mutex before checking altscreen state
This prevents the odd race condition where Enter- & ExitAltScreen
are called concurrently.
2022-10-13 04:50:50 +02:00
Christian Muehlhaeuser b9bd01b79a fix: lock renderer during stop/kill 2022-10-09 05:57:44 +02:00
Christian Muehlhaeuser f406999cba fix: don't try to set alt screen when already in desired mode 2022-10-06 12:50:51 +02:00
Christian Muehlhaeuser ca8b21a3e2 fix: force repaint after clearing the screen 2022-10-04 17:34:09 +02:00
Raphael 'kena' Poss 5d1a7264c5 fix: ensure alt screen switch always clears terminal 2022-10-04 06:01:52 +02:00
Raphael 'kena' Poss 6e1065830a feat: support a Clear command 2022-10-04 06:01:52 +02:00
Christian Muehlhaeuser ea36e19bee fix: move output handling to renderer 2022-10-04 05:06:42 +02:00
Christian Muehlhaeuser 6c449e55bf feat: use Termenv.Output to write to tty 2022-09-27 02:49:36 +02:00
bashbunni 2b9d4e3015 chore: fix Println typo 2022-07-20 01:46:48 +02: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
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
Georgi Dimitrov 50a8461fbf fix: race condition on repaint 2022-06-04 15:35:59 +02: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
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
Christian Rocha bef2c8ce66 Always redraw when toggling the altscreen 2022-01-07 13:21:43 -05:00
Christian Rocha 119144e78c ANSI compression is now opt-in via the WithANSICompressor program option 2021-10-30 13:04:27 -04:00
Christian Muehlhaeuser c29912c179 Enable ANSI compressor
With this change all ANSI output will be piped through an ANSI compressor that
eliminates redundant ANSI sequences. As such the compressor can be considered
"lossless".
2021-10-28 09:45:43 -04:00
Christian Rocha b957c32c18 Fix a bug where explicitly ignored lines weren't honored by the renderer 2021-06-22 13:06:55 -04:00
Christian Rocha 6547773a3f Clear output and render "nothing" when a view returns the empty string
Closes #100.
2021-06-02 14:49:54 -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 3256fae4d4 Force a full repaint when resizing the window
v0.13.4 introduced a regression where lines weren't always cleared when
resizing the window resulting in the presence of rendering artifacts.
This commit fixes that.
2021-05-31 10:37:32 -04:00
Christian Rocha 70be13948a Re-render all lines if the total number of lines increases
If the number of lines increased there's a chance that the increase in
lines caused the terminal to scroll (even in the altscreen). Because of
this we must repaint everything, as skipping lines will mis-render.

Thanks to @fiws for reporting this bug.
2021-05-14 20:04:40 -04:00
Christian Rocha fb64f34bd0 Only render lines that have changed since the last render 2021-05-10 12:28:49 -04:00
Kiyon 2d602a1244 Remove redundant lock in listen 2021-04-08 03:47:22 +02:00
Kiyon 1ee40507ef Add lock for updating width and height 2021-04-08 03:45:08 +02:00
Christian Rocha 9d89d162c2 Clear the bottom line before exiting 2021-03-18 13:10:32 -04:00
Christian Muehlhaeuser a72db29ae0 Mutex protect buffer access in standard renderer 2021-03-13 04:31:34 +01:00
Christian Rocha b3f62af8b5 Add nil renderer and combination TUI-daemon program example
The Nil Renderer essentially disables the Bubble Tea renderer sending
loggings and print statements to stdout. It can be enabled via the
ProgramOption WithoutRenderer.
2021-03-07 13:01:54 -05:00