-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(tui): live shell output during execution - show real-time progress #2048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
donglovejava
wants to merge
1
commit into
Hmbown:main
Choose a base branch
from
donglovejava:feat/shell-live-progress
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2514,6 +2514,75 @@ impl App { | |
| self.needs_redraw = true; | ||
| } | ||
|
|
||
| /// Poll shell manager for live output of running exec cells and update | ||
| /// their `live_output` field so the TUI shows incremental progress. | ||
| /// Called from the idle frame handler in `run_event_loop`. | ||
| pub fn poll_shell_progress(&mut self) { | ||
| use crate::tui::history::{ExecCell, ToolCell}; | ||
|
|
||
| let Some(ref shell_mgr) = self.runtime_services.shell_manager else { | ||
| return; | ||
| }; | ||
| let Some(ref active) = self.active_cell else { | ||
| return; | ||
| }; | ||
|
|
||
| // Collect (index, command) of running exec cells | ||
| let mut running_execs: Vec<(usize, String)> = Vec::new(); | ||
| for (i, entry) in active.entries().iter().enumerate() { | ||
| if let HistoryCell::Tool(ToolCell::Exec(ExecCell { | ||
| command, | ||
| status: crate::tui::history::ToolStatus::Running, | ||
| .. | ||
| })) = entry | ||
| { | ||
| running_execs.push((i, command.clone())); | ||
| } | ||
| } | ||
| if running_execs.is_empty() { | ||
| return; | ||
| } | ||
|
|
||
| // Get live output from shell manager | ||
| let jobs = match shell_mgr.lock() { | ||
| Ok(mut mgr) => mgr.list_jobs(), | ||
| Err(_) => return, | ||
| }; | ||
|
|
||
| let active_ref = self.active_cell.as_mut().expect("active_cell just checked"); | ||
| let mut updated = false; | ||
| for (idx, cmd) in &running_execs { | ||
| let cmd_prefix: String = cmd.chars().take(100).collect(); | ||
| for job in &jobs { | ||
| if job.status == crate::tools::shell::ShellStatus::Running { | ||
| let job_prefix: String = job.command.chars().take(100).collect(); | ||
| if cmd_prefix == job_prefix { | ||
| let tail = if !job.stderr_tail.trim().is_empty() { | ||
| job.stderr_tail.trim() | ||
| } else { | ||
| job.stdout_tail.trim() | ||
| }; | ||
| if !tail.is_empty() { | ||
| if let Some(HistoryCell::Tool(ToolCell::Exec(ref mut ec))) = | ||
| active_ref.entry_mut(*idx) | ||
| { | ||
| let new_output = tail.to_string(); | ||
| if ec.live_output.as_deref() != Some(&new_output) { | ||
| ec.live_output = Some(new_output); | ||
| updated = true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+2554
to
+2579
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The matching and output selection logic can be significantly optimized and improved:
for idx in &running_exec_indices {
let cmd = if let HistoryCell::Tool(ToolCell::Exec(ec)) = &active_ref.entries()[*idx] { &ec.command } else { continue };
for job in &jobs {
if job.status == crate::tools::shell::ShellStatus::Running && &job.command == cmd {
let tail = if !job.stderr_tail.is_empty() {
&job.stderr_tail
} else {
&job.stdout_tail
};
if !tail.is_empty() {
if let Some(HistoryCell::Tool(ToolCell::Exec(ref mut ec))) = active_ref.entry_mut(*idx) {
if ec.live_output.as_deref() != Some(tail) {
ec.live_output = Some(tail.to_string());
updated = true;
}
}
}
}
}
} |
||
| if updated { | ||
| self.bump_active_cell_revision(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /// Total number of cells in the *virtual* transcript: `history.len()` | ||
| /// plus active cell entries (if any). | ||
| #[must_use] | ||
|
|
||
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
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
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cloning the
commandstring for every running execution cell on every frame is inefficient. You can store just the indices and retrieve the command from theactive_cellwhen needed to avoid unnecessary allocations.