Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions crates/shell-use/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,27 @@ fn do_snapshot(
}
}

/// Where to draw the cursor within `rows`, or `None` when the terminal is not
/// showing one.
///
/// `Emulator::cursor` is relative to the visible screen, so a full screenshot
/// has to push it down past the scrollback that precedes it.
fn cursor_in(
rows: &[Vec<EmuCell>],
emu: &dyn crate::terminal::emu::Emulator,
) -> Option<(u16, usize)> {
if !emu.cursor_visible() {
return None;
}
let (x, y) = emu.cursor();
let (_, screen) = emu.size();
// Counted in `usize`: a full render is as long as the scrollback, which a
// profile can set past what a `u16` row would hold, and a wrapped offset
// draws the cursor on a plausible but wrong line.
let history = rows.len().saturating_sub(screen as usize);
Some((x, history + y as usize))
}

fn screenshot(
session: &TerminalSession,
full: bool,
Expand All @@ -1186,16 +1207,14 @@ fn screenshot(
let rows = grid(session, full);
match path {
Some(path) => {
let svg = crate::render::svg::render_svg(
&rows,
session.cols,
session
.state
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.emu
.as_ref(),
);
let state = session
.state
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner);
let emu = state.emu.as_ref();
let svg =
crate::render::svg::render_svg(&rows, session.cols, emu, cursor_in(&rows, emu));
drop(state);
std::fs::write(&path, svg)
.map_err(|error| ShellUseError::internal(error.to_string()))?;
Ok(ScreenshotResult::Path(path))
Expand Down
Loading
Loading