Skip to content

tui: implement scroll-back for pseudo term#195

Merged
kxxt merged 4 commits into
mainfrom
scroll
Mar 26, 2026
Merged

tui: implement scroll-back for pseudo term#195
kxxt merged 4 commits into
mainfrom
scroll

Conversation

@kxxt

@kxxt kxxt commented Mar 26, 2026

Copy link
Copy Markdown
Owner

It's still a little buggy because we are missing doy/vt100-rust#27.

But it's still better than not having it.

Summary by CodeRabbit

  • New Features

    • Added pseudo-terminal scrollback with configurable line count (defaults to 1,000).
    • Toggle scrollback mode with Ctrl+U to navigate terminal history via ↑/↓, PgUp/PgDn, and Home/End.
    • New CLI option and config setting to customize scrollback depth.
  • Documentation

    • Updated in-app help to show scrollback navigation controls.

@vercel

vercel Bot commented Mar 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tracexec Ready Ready Preview, Comment Mar 26, 2026 5:25am

@coderabbitai

coderabbitai Bot commented Mar 26, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 3f8ef891-3170-443f-beee-f2d67c950d89

📥 Commits

Reviewing files that changed from the base of the PR and between 2209333 and 4a30092.

📒 Files selected for processing (2)
  • README.md
  • config.toml
✅ Files skipped from review due to trivial changes (2)
  • config.toml
  • README.md

Walkthrough

Adds configurable PTY scrollback: new CLI/config option scrollback_lines, initializes the VT100 parser with that capacity, implements Ctrl+U scrollback toggle and navigation keys handling, updates help UI, adjusts PTY reader task, and expands tests.

Changes

Cohort / File(s) Summary
Configuration & CLI
crates/tracexec-core/src/cli/args.rs, crates/tracexec-core/src/cli/config.rs
Added scrollback_lines: Option<usize> to TuiModeArgs and TuiModeConfig; CLI value wins in merge_config.
App Initialization
crates/tracexec-tui/src/app.rs
Passes tui_args.scrollback_lines.unwrap_or(1000) into PseudoTerminalPane::new.
UI Help Rendering
crates/tracexec-tui/src/app/ui.rs
Footer help shows scrollback-specific controls when terminal is in scrollback mode (Ctrl+U, ↑↓, PgUp/PgDn, Home/End).
Scrollback Implementation & Tests
crates/tracexec-tui/src/pseudo_term.rs
PseudoTerminalPane::new gains scrollback_lines param; stores scrollback state; uses vt100::Parser with capacity; toggles scrollback on Ctrl+U; intercepts navigation keys to adjust scrollback offset; exposes is_scrollback_mode(), scrollback(), parser(); switches PTY reader to tokio::task::spawn_blocking; updates/extends tests.
Dev deps & Docs
crates/tracexec-tui/Cargo.toml, README.md, config.toml
Added tracing-test as a dev-dependency; documented --scrollback-lines CLI flag and commented scrollback_lines config entry in config.toml.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant PseudoTerminalPane
    participant PTY as PTY Master
    participant Parser as vt100::Parser

    User->>App: Key event (e.g., Ctrl+U / Up / PgUp)
    App->>PseudoTerminalPane: handle_key_event(key)
    alt key == Ctrl+U
        PseudoTerminalPane->>PseudoTerminalPane: toggle scrollback_mode, reset offset
        PseudoTerminalPane-->>App: consume key
    else scrollback_mode == true and navigation key
        PseudoTerminalPane->>Parser: adjust screen.set_scrollback(offset)
        PseudoTerminalPane-->>App: consume key
    else not consumed
        PseudoTerminalPane->>PTY: forward key to PTY
    end

    Note over PTY,Parser: PTY reader runs in spawn_blocking
    PTY->>Parser: write bytes from master pty
    Parser->>PseudoTerminalPane: update screen buffer (with configured scrollback cap)
    PseudoTerminalPane->>App: render using Parser.screen()
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I nibble on bytes in a cosy stream,
Ctrl+U hops—now follow my dream,
Up, Down, PgUp—through history I prance,
A thousand lines—give the terminal a chance!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 52.94% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'tui: implement scroll-back for pseudo term' directly and clearly describes the main change: implementing scrollback functionality for the TUI pseudo terminal.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch scroll

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Mar 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.41497% with 37 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.28%. Comparing base (34168f3) to head (4a30092).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
crates/tracexec-tui/src/pseudo_term.rs 92.75% 20 Missing ⚠️
crates/tracexec-tui/src/app/ui.rs 0.00% 16 Missing ⚠️
crates/tracexec-tui/src/app.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #195      +/-   ##
==========================================
+ Coverage   71.83%   72.28%   +0.45%     
==========================================
  Files          71       71              
  Lines       14033    14323     +290     
==========================================
+ Hits        10081    10354     +273     
- Misses       3952     3969      +17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
crates/tracexec-tui/src/pseudo_term.rs (1)

726-730: Potential race: waitpid called before output is fully processed.

In scrollback_home_end_navigation, tokio::time::sleep is called before waitpid, unlike the other tests which call waitpid first. This ordering inconsistency could lead to test flakiness if the child exits before sleep completes, though it's unlikely to cause issues in practice since the output is typically flushed before exit.

Consider reordering for consistency with the other tests:

Suggested reorder for consistency
     let child_pid = pty::spawn_command(Some(&pty_pair.slave), cmd, move |_| {
       tracee::lead_session_and_control_terminal()?;
       Ok(())
     })?;
-    // Give the reader task time to process the output
-    tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
 
     // Reap child
     waitpid(child_pid, None)?;
+
+    // Give the reader task time to process the output
+    tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/tracexec-tui/src/pseudo_term.rs` around lines 726 - 730, In
scrollback_home_end_navigation, the ordering is inconsistent: tokio::time::sleep
is awaited before waitpid(child_pid, None) which can cause a race; move the
waitpid(child_pid, None)? call to occur before the tokio::time::sleep(...)
.await so the child is reaped first (matching other tests) while retaining the
sleep to give the reader task time to process output.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/tracexec-tui/src/pseudo_term.rs`:
- Around line 726-730: In scrollback_home_end_navigation, the ordering is
inconsistent: tokio::time::sleep is awaited before waitpid(child_pid, None)
which can cause a race; move the waitpid(child_pid, None)? call to occur before
the tokio::time::sleep(...) .await so the child is reaped first (matching other
tests) while retaining the sleep to give the reader task time to process output.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: f6abcd7d-0ccc-4210-add3-f0f254d6faca

📥 Commits

Reviewing files that changed from the base of the PR and between 34168f3 and 2209333.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • crates/tracexec-core/src/cli/args.rs
  • crates/tracexec-core/src/cli/config.rs
  • crates/tracexec-tui/Cargo.toml
  • crates/tracexec-tui/src/app.rs
  • crates/tracexec-tui/src/app/ui.rs
  • crates/tracexec-tui/src/pseudo_term.rs

@kxxt
kxxt merged commit 5b85ffd into main Mar 26, 2026
23 checks passed
@kxxt
kxxt deleted the scroll branch March 26, 2026 05:51
@kxxt kxxt mentioned this pull request Mar 26, 2026
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.

1 participant