diff --git a/src/renderer/src/components/orca-cloud/offline/CloudAsleepTerminalNotice.tsx b/src/renderer/src/components/orca-cloud/offline/CloudAsleepTerminalNotice.tsx index 752dfe959c7..fb439fe2905 100644 --- a/src/renderer/src/components/orca-cloud/offline/CloudAsleepTerminalNotice.tsx +++ b/src/renderer/src/components/orca-cloud/offline/CloudAsleepTerminalNotice.tsx @@ -24,12 +24,18 @@ export function formatAsleepSince(at: number, now = Date.now()): string { export function CloudAsleepTerminalNotice({ workspaceId, asleepSince, - waking = false + waking = false, + historyEndPx = null }: { workspaceId: string asleepSince: number | null /** Waking: the waking pill speaks; keep only the greyed history and its divider. */ waking?: boolean + /** + * Where the pre-sleep output ends, in px from the top of the pane: the divider sits right under + * the last line. Null when unknown or the history fills the pane (then it ends at the bottom). + */ + historyEndPx?: number | null }): React.JSX.Element { const t = useTranslate() return ( @@ -47,7 +53,13 @@ export function CloudAsleepTerminalNotice({ {asleepSince !== null ? (
diff --git a/src/renderer/src/components/orca-cloud/offline/CloudWakeTerminalNotices.fixture.tsx b/src/renderer/src/components/orca-cloud/offline/CloudWakeTerminalNotices.fixture.tsx index 5055b789c48..af5d8c14e1f 100644 --- a/src/renderer/src/components/orca-cloud/offline/CloudWakeTerminalNotices.fixture.tsx +++ b/src/renderer/src/components/orca-cloud/offline/CloudWakeTerminalNotices.fixture.tsx @@ -39,6 +39,8 @@ export const asleepTerminalHistory = defineFixture({ ) diff --git a/src/renderer/src/components/orca-cloud/offline/CloudWakeTerminalNotices.test.tsx b/src/renderer/src/components/orca-cloud/offline/CloudWakeTerminalNotices.test.tsx index 650b7996f2f..6b3f5326dee 100644 --- a/src/renderer/src/components/orca-cloud/offline/CloudWakeTerminalNotices.test.tsx +++ b/src/renderer/src/components/orca-cloud/offline/CloudWakeTerminalNotices.test.tsx @@ -33,6 +33,15 @@ describe('CloudAsleepTerminalNotice', () => { ) }) + it('puts the divider right under the last line of history', () => { + const { container } = render( + + ) + const divider = container.querySelector('[data-cloud-asleep-divider]') + expect(divider?.style.top).toBe('44px') + expect(divider?.className).toContain('absolute') + }) + it('omits the divider when the sleep time is unknown', () => { const { container } = render() expect(container.querySelector('[data-cloud-asleep-divider]')).toBeNull() diff --git a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/recovery/TerminalPaneRecoveryPortals.tsx b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/recovery/TerminalPaneRecoveryPortals.tsx index b7bac4f15c1..88af2b0ae46 100644 --- a/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/recovery/TerminalPaneRecoveryPortals.tsx +++ b/src/renderer/src/components/terminal-pane/pty-transport/remote-runtime/recovery/TerminalPaneRecoveryPortals.tsx @@ -25,6 +25,7 @@ import { captureWakeProcessHint, dismissWakeProcessHint, getWakeProcessHint, + historyEndOffsetPx, readTerminalTail, resetWakeProcessCapture, wakeShowsStaleHistory, @@ -228,6 +229,7 @@ export function TerminalPaneRecoveryPortals({ , pane.container, `cloud-asleep-${pane.id}` @@ -239,6 +241,7 @@ export function TerminalPaneRecoveryPortals({ , pane.container, diff --git a/src/renderer/src/lib/orca-cloud/cloud-wake-process-hints.test.ts b/src/renderer/src/lib/orca-cloud/cloud-wake-process-hints.test.ts index a8bdf713ac5..d542c86a77b 100644 --- a/src/renderer/src/lib/orca-cloud/cloud-wake-process-hints.test.ts +++ b/src/renderer/src/lib/orca-cloud/cloud-wake-process-hints.test.ts @@ -4,6 +4,7 @@ import { detectForegroundCommand, dismissWakeProcessHint, getWakeProcessHint, + historyEndRow, readTerminalTail, resetWakeProcessCapture, resetWakeProcessHintsForTests @@ -60,6 +61,22 @@ describe('wake process hints', () => { expect(getWakeProcessHint('leaf-1')).toEqual({ command: 'pnpm dev' }) }) + it('finds where the history ends on screen, or null when it fills the pane', () => { + const screen = (lines: string[], rows: number) => ({ + rows, + buffer: { + active: { + length: lines.length, + viewportY: 0, + getLine: (index: number) => ({ translateToString: () => lines[index] ?? '' }) + } + } + }) + expect(historyEndRow(screen(['$ python3 -m http.server', 'Serving…', '', ''], 4))).toBe(2) + expect(historyEndRow(screen(['a', 'b', 'c', 'd'], 4))).toBeNull() + expect(historyEndRow(screen(['', '', ''], 3))).toBeNull() + }) + it('reads the tail of an xterm buffer', () => { const lines = ['a', 'b', 'c'] const terminal = { diff --git a/src/renderer/src/lib/orca-cloud/cloud-wake-process-hints.ts b/src/renderer/src/lib/orca-cloud/cloud-wake-process-hints.ts index 80245a52520..73da2056cd8 100644 --- a/src/renderer/src/lib/orca-cloud/cloud-wake-process-hints.ts +++ b/src/renderer/src/lib/orca-cloud/cloud-wake-process-hints.ts @@ -65,6 +65,41 @@ export function readTerminalTail(terminal: TailSource, count = 200): string[] { return lines } +type ViewportSource = TailSource & { + rows: number + buffer: TailSource['buffer'] & { active: TailSource['buffer']['active'] & { viewportY: number } } +} + +/** + * Rows from the top of the visible screen through the last one with text, or null when the text + * reaches the last row (the history fills the pane) or the screen is empty. + */ +export function historyEndRow(terminal: ViewportSource): number | null { + const { viewportY } = terminal.buffer.active + for (let row = terminal.rows - 1; row >= 0; row--) { + const text = terminal.buffer.active.getLine(viewportY + row)?.translateToString(true) ?? '' + if (text.trim() !== '') { + return row === terminal.rows - 1 ? null : row + 1 + } + } + return null +} + +/** `historyEndRow` in px from the top of `container`, measured from the rendered xterm screen. */ +export function historyEndOffsetPx( + terminal: ViewportSource & { element?: HTMLElement | undefined }, + container: HTMLElement +): number | null { + const rows = historyEndRow(terminal) + const screen = terminal.element?.querySelector('.xterm-screen') + if (rows === null || !screen || terminal.rows <= 0) { + return null + } + const rowHeight = screen.clientHeight / terminal.rows + const top = screen.getBoundingClientRect().top - container.getBoundingClientRect().top + return Math.round(top + rows * rowHeight + 4) +} + // Keyed by the pane's durable leaf id; cleared once the pane has shown (or dismissed) its line. const hints = new Map() // Panes already looked at in this sleep: the first look sees the pre-sleep scrollback.