Repository navigation
Description
wmux: v2.64.1 · Windows 11 · PowerShell panes
What happens
wmux read-screen --lines N returns {"text": "", "lines": 0} whenever the last N rows of the terminal buffer are blank, even though there is output higher up in the pane.
That is the usual state of a freshly opened pane: a short command's output sits at the top, and every row below the prompt is empty. Asking for "the last few lines" (the most common use) returns nothing.
Steps to reproduce
- Open a new terminal pane (about 24 rows tall).
- Run a command with a few lines of output, e.g.
python --version; node --version; Get-Date. - Read it back:
$ wmux read-screen --surface <id> --lines 12
{ "text": "", "lines": 0, ... }
$ wmux read-screen --surface <id> --lines 20
{ "text": "\nThursday, November 19, 2026 9:49:16 AM\n\n\nPS C:\\Users\\me> ", "lines": 5, ... }
$ wmux read-screen --surface <id> # default 50
{ "text": "PS C:\\Users\\me> python --version; node --version; Get-Date\nPython 3.12.0\nv24.13.1\n\n...", "lines": 8, ... }
Results for different N on the same pane:
--lines |
Returned |
|---|---|
| 1, 5, 12 | empty |
| 20 | only the last 5 lines |
| 30 and up, or no flag | all 8 lines |
Expected
--lines N returns the last N lines of content, so --lines 3 after echo hi gives:
PS C:\Users\me> echo hi
hi
PS C:\Users\me>
Cause
window.__wmux_readScreen (renderer) takes the last N rows of buffer.active first and trims trailing blank rows afterwards:
let a = i.buffer.active, o = clamp(n ?? 50, 1, 1e4), s = a.length, c = [];
for (let e = Math.max(0, s - o); e < s; e++)
c.push(a.getLine(e)?.translateToString(true) ?? ``);
for (; c.length && c[c.length - 1] === ``;) c.pop(); // trims AFTER slicingIf every row in that window is blank, the trim leaves nothing.
Suggested fix
Find the last non-blank row first, then take N rows ending there:
let end = a.length;
while (end > 0 && (a.getLine(end - 1)?.translateToString(true) ?? ``) === ``) end--;
for (let e = Math.max(0, end - o); e < end; e++)
c.push(a.getLine(e)?.translateToString(true) ?? ``);Workaround
Patching cmd 'read-screen' in resources/cli/wmux.js to always request lines: 10000, strip trailing blank lines from text, and keep the last N lines client-side fixes it for the CLI. It is overwritten on update, and other surface.read_text callers still see the bug.
Related: #76 (original read-screen implementation).
Activity
fix(read-screen): count --lines N from the last row of content (amirl…