Skip to content

Bubbletea-ify shell - #9620

Merged
vito merged 56 commits into
dagger:mainfrom
vito:shell-bbt
Feb 27, 2025
Merged

vito merged 56 commits into
dagger:mainfrom
vito:shell-bbt

Conversation

@vito

@vito vito commented Feb 18, 2025 •

Copy link
Copy Markdown
Contributor

Fixes #8990
Fixes #9202
Fixes #9281

This is a somewhat dramatic change to the dagger shell UX and implementation.

Previously shell started the TUI and backgrounded it to show the prompt and accept user input. After accepting user input it would foreground the TUI to show progress, and then background it when its command completed. This had the downside of not being able to let progress "linger" in the scrollback.

Now shell is directly integrated into the TUI, where we show a prompt and history of commands (using the regular progress output, zoomed to the shell's span).

  • To switch from the input prompt to navigating the progress, press Esc.
  • To switch back to the input prompt, press Tab or i.
  • The prompt should accept all the usual readline keybinds. Let me know if something's broken.
  • Autocomplete should also work, but could use a bit more love.
    • Not sure if the keybinds are good here.
    • Would be nice to use the full completion features (categories + descriptions).

Major change: don't print object leaf fields

Instead of auto-selecting an object's scalar/leaf fields and printing them in YAML format, this PR also changes objects to simply print as TypeName@xxh3:....

A few motivations:

  • Sometimes those fields are extremely verbose, which sometimes negatively influences API design
  • Most of the time those fields aren't very illustrative (e.g. Container doesn't show its imageRef or the command that it runs)
  • It's possible that selecting those fields is destructive

Open question: scroll wheel/mouse input handling

Now the entire shell session is rendered in our TUI, rather than printed plainly to the terminal scrollback. The TUI isn't able to rendering anything offscreen, so if you scroll the terminal it'll just be cut off at the top.

To handle that, currently our TUI hijacks mouse events so that it can approximate1 scrolling. There's no way to only intercept scroll events, and we don't do anything with click events, so if you try to select text nothing happens. Annoying!

The workaround for that is to just hold Shift while using the mouse, which is the universal2 technique to bypass sending mouse input to the program. But not everyone knows that.

Eating mouse input got in the way for the demo so I hastily removed it, which is a "breaking" change across the entire TUI.

The question: (when) should we eat mouse input?

There are a few options:

Mouse handling Scroll prompt progress Scroll outer terminal Copy/paste
A Always consume Scroll Shift + scroll Shift + select
B Never consume Esc + arrows/hjkl Scroll Select
C Only consume in nav mode Esc + arrows/hjkl/scroll Scroll (prompt mode)
Shift + scroll (nav mode)
Select (prompt mode)
Shift + select (nav mode)

Some notes:

  • Option A is the current default on main and v0.15.x.
  • Option B is implemented by this PR, but it was a hasty change, and is a change across-the-board (not just for shell).
  • Option C is a compromise, but I'm not sure if it's intuitive.

Footnotes

  1. It switches focus between spans and renders outward from the focused span, it doesn't act like a pager. ↩

  2. By my measurement, anyway; never ran into a terminal where this didn't work. ↩

@helderco

helderco commented Feb 19, 2025 •

Copy link
Copy Markdown
Contributor

Doing Ctrl+D (in prompt) exits with status 2.

EDIT: actually, stderr says 2, but my shell says 1:

...

exit status 2

✗ echo $?
1

@helderco

Copy link
Copy Markdown
Contributor

To handle that, currently our TUI hijacks mouse events so that it can approximate1 scrolling. There's no way to only intercept scroll events, and we don't do anything with click events, so if you try to select text nothing happens. Annoying!

The workaround for that is to just hold Shift while using the mouse, which is the universal2 technique to bypass sending mouse input to the program. But not everyone knows that.

Isn't only when something is in progress though?

When I have output from a command that is bigger than the terminal height, and I'm at the prompt, that output is cropped. Holding Shift makes not difference.

@vito
vito force-pushed the shell-bbt branch 4 times, most recently from c58ef46 to 64b2fe6 Compare February 24, 2025 20:30
vito added 20 commits February 25, 2025 21:40
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
we only use this for scrolling, doesn't seem worth

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
TODO: how should concurrency be handled?

Signed-off-by: Alex Suraci <[email protected]>
otherwise it can fail with concurrent runs

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Auto-selecting object fields hasn't really turned out to be a great DX:

* Sometimes those fields are extremely verbose
* Most of the time those fields aren't very illustrative (e.g. container
  doesn't show its imageRef or the command that it runs)
* It's possible that selecting those fields is destructive

So instead we'll just print the object type and hash. This way you still
get an idea about what's returned and can tell if it's the same as
another object.

Signed-off-by: Alex Suraci <[email protected]>
vito added 6 commits February 26, 2025 00:50
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
a bit weird, but apparently this is reality

Signed-off-by: Alex Suraci <[email protected]>
vito added 17 commits February 26, 2025 12:42
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
now toggles, and just JSON dumps the snapshot like the web version

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
there's a sneaky \b in there now

Signed-off-by: Alex Suraci <[email protected]>
@vito

vito commented Feb 27, 2025

Copy link
Copy Markdown
Contributor Author

For continuity: I went with a new option D:

  • Never consume mouse input, but only in shell mode
  • As top-level shell commands complete, print them to a scrollback, so you can just scroll up like normal
  • In-progress commands are displayed with a highlighted background, if supported
  • Switching to nav keeps same highlighted background to distinguish from completed items in the scrollback

This feels like a good balance to me: mouse actions "just work" as you would expect, scrollback behaves like a normal shell, and we don't break any behavior outside of shell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shell: write files with special characters shell: readline wipes entire line when deleting the first word shell: don't print objects by default

3 participants