feat(chisel): TUI support#14748
Open
mablr wants to merge 2 commits into
Open
Conversation
Adds an interactive ratatui-based TUI to the chisel REPL when running in
a TTY, with a 3-region layout (output history, live variable state pane,
syntax-highlighted input). Falls back to the existing plain rustyline
loop in non-TTY / CI / TERM=dumb environments.
Key changes:
* Unified output buffer: introduces ReplMessage { kind, text } and
push_out/push_err helpers on ChiselDispatcher; converts every
sh_println!/sh_err! in REPL paths (all ! commands, traces, logs) to
push into the buffer so the TUI can render them in its output pane.
* Plain REPL drains the buffer through sh_println!/sh_err! so existing
behavior (and rexpect tests) stays intact.
* show_traces -> render_traces returning Option<String>; inspect()'s
error path bundles traces/logs into the returned error.
* foundry-tui: adds with_suspended_terminal + thread-local TUI marker;
TerminalGuard now also enables/disables bracketed paste. !edit and
!exec wrap their child-process calls so the editor/shell command gets
direct access to the terminal.
* Live state pane via batched abi.encode(v1, v2, ...) snapshot
(snapshot_session_variables) + tuple decode -> 2 compiles per refresh
instead of N+1.
* Input widget: persistent multi-line history (escapes embedded \n in
~/.foundry/.chisel_history), bracketed-paste support, horizontal
scrolling so the cursor is always visible, Backspace at column 0 pops
a pending continuation, Esc/Ctrl+D only quit when both buf and
pending are empty, blank Enter does not pollute history.
* Adds DumbTerminal fallback reason; cargo test -p chisel and
-p foundry-tui all green; clippy clean.
Amp-Thread-ID:
https://ampcode.com/threads/T-019e2231-66cc-7558-a0ec-279836f8a6dd
Co-authored-by: Amp <amp@ampcode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds an interactive ratatui-based TUI to the chisel REPL when running in a TTY, with a 3-region layout (output history, live variable state pane, syntax-highlighted input). Falls back to the existing plain rustyline loop in non-TTY / CI / TERM=dumb environments.
Key changes:
Unified output buffer: introduces
ReplMessage { kind, text }andpush_out/push_errhelpers onChiselDispatcherconverts everysh_println!/sh_err!in REPL paths (all ! commands, traces, logs) to push into the buffer so the TUI can render them in its output pane.Plain REPL drains the buffer through
sh_println!/sh_err!so existing behavior (and rexpect tests) stays intact.show_traces->render_tracesreturningOption<String>inspect()'s error path bundles traces/logs into the returned error.foundry-tui: adds
with_suspended_terminal+ thread-local TUI marker;TerminalGuardnow also enables/disables bracketed paste.!edit and!execwrap their child-process calls so the editor/shell command gets direct access to the terminal.Live state pane via
batched abi.encode(v1, v2, ...)-> 2 compiles per refresh instead of N+1.Input widget: persistent multi-line history (escapes embedded \n in
~/.foundry/.chisel_history), bracketed-paste support, horizontal scrolling so the cursor is always visible, Backspace at column 0 pops a pending continuation, Esc/Ctrl+D only quit when both buf and pending are empty, blank Enter does not pollute history.Adds
DumbTerminalfallback reason