Readable command output: ANSI stripped, Copy / Wrap / Expand / .txt (#27)
CI / Lint (eslint) (pull_request) Successful in 18s
CI / Test (jest) (pull_request) Failing after 22s
CI / Security (npm audit) (pull_request) Successful in 15s
CI / Scan (secrets, workflows, shell) (pull_request) Successful in 1m42s
CI / Integration (api) (pull_request) Successful in 2m29s
CI / UI screenshots (before/after) (pull_request) Successful in 3m25s
CI / UI (playwright) (pull_request) Successful in 4m5s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / Notify (pull_request) Skipped
CI / Lint (eslint) (pull_request) Successful in 18s
CI / Test (jest) (pull_request) Failing after 22s
CI / Security (npm audit) (pull_request) Successful in 15s
CI / Scan (secrets, workflows, shell) (pull_request) Successful in 1m42s
CI / Integration (api) (pull_request) Successful in 2m29s
CI / UI screenshots (before/after) (pull_request) Successful in 3m25s
CI / UI (playwright) (pull_request) Successful in 4m5s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / Notify (pull_request) Skipped
A shared output block (Pulse.output.render) now draws every command output in Executions and Quick Command: - ANSI escape codes (colours, cursor moves, titles, charset switches) are stripped, so systemctl, ls --color and docker read cleanly. - Copy and .txt use the full, clean text; .txt downloads it as a file. - Wrap turns long-line wrapping on or off for every block, remembered. - Output over 25 lines starts at 24rem high with an Expand button. - Over 100,000 characters, the display is cut with a notice saying how much is hidden; Copy and .txt still include all of it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
33a3f7c0b9
commit
b1357cbccf
6 files changed
+162
-22
No files matched your search
@@ -187,3 +187,36 @@ html[data-theme="light"] .pulse-running {
|
|||||||
.lt-form-group { display: flex }, or hidden sections still show (both
|
.lt-form-group { display: flex }, or hidden sections still show (both
|
||||||
Quick Command worker pickers were visible in either mode). */
|
Quick Command worker pickers were visible in either mode). */
|
||||||
[hidden] { display: none !important; }
|
[hidden] { display: none !important; }
|
||||||
|
|
||||||
|
/* Command output blocks (#27): toolbar above a wrapping, collapsible <pre>. */
|
||||||
|
.pl-out { margin-top: 0.4rem; min-width: 0; }
|
||||||
|
.pl-out-bar {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 0.3rem;
|
||||||
|
}
|
||||||
|
.pl-out-label {
|
||||||
|
margin-right: auto;
|
||||||
|
font-size: 0.65rem;
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
.pl-out-btn { padding: 0.1rem 0.5rem; font-size: 0.62rem; }
|
||||||
|
.pl-out-pre {
|
||||||
|
margin: 0.3rem 0 0;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
.pl-out-pre.is-nowrap { white-space: pre; overflow-wrap: normal; }
|
||||||
|
.pl-out-pre.is-tall { max-height: 24rem; }
|
||||||
|
.pl-out-pre.is-tall.is-expanded { max-height: none; }
|
||||||
|
.pl-out-err {
|
||||||
|
color: var(--accent-red);
|
||||||
|
border-left-color: var(--accent-red);
|
||||||
|
text-shadow: none;
|
||||||
|
}
|
||||||
|
.pl-out-note { margin-top: 0.3rem; font-size: 0.7rem; color: var(--text-muted); }
|
||||||
+84
-1
@@ -163,6 +163,87 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------
|
||||||
|
Command output blocks (#27): ANSI codes stripped, Copy / Wrap / Expand /
|
||||||
|
.txt controls, and a notice when the display is cut short. Copy and the
|
||||||
|
download always use the full text, which is kept here by block id.
|
||||||
|
------------------------------------------------------------------- */
|
||||||
|
const OUT_MAX = 100000; // characters drawn per block
|
||||||
|
const OUT_TALL_LINES = 25; // taller than this starts collapsed
|
||||||
|
const OUT_WRAP_KEY = 'pulse_output_wrap';
|
||||||
|
// CSI (colours, cursor moves), OSC (titles, links), charset switches (ESC ( B)
|
||||||
|
// and other two-byte escapes.
|
||||||
|
// eslint-disable-next-line no-control-regex -- matching ESC/BEL is the point
|
||||||
|
const ANSI_RE = /\u001b(?:\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\[[0-?]*[ -/]*[@-~]|[()*+][0-9A-Za-z]|[@-Z\\-_])/g;
|
||||||
|
const _outTexts = new Map();
|
||||||
|
let _outSeq = 0;
|
||||||
|
|
||||||
|
function stripAnsi(text) {
|
||||||
|
return String(text == null ? '' : text).replace(ANSI_RE, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
function outButton(action, id, label, title) {
|
||||||
|
return '<button type="button" class="lt-btn lt-btn-ghost lt-btn-sm pl-out-btn" data-action="' + action +
|
||||||
|
'" data-out="' + id + '" title="' + title + '">' + label + '</button>';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** HTML for one output block. opts: { err, label, name (download file name), cls } */
|
||||||
|
function renderOutput(text, opts) {
|
||||||
|
const o = opts || {};
|
||||||
|
const clean = stripAnsi(text);
|
||||||
|
const id = 'pl-out-' + (++_outSeq);
|
||||||
|
_outTexts.set(id, { text: clean, name: String(o.name || 'output').replace(/[^\w.-]+/g, '-') });
|
||||||
|
if (_outTexts.size > 500) _outTexts.delete(_outTexts.keys().next().value);
|
||||||
|
const shown = clean.length > OUT_MAX ? clean.slice(0, OUT_MAX) : clean;
|
||||||
|
const tall = shown.split('\n').length > OUT_TALL_LINES;
|
||||||
|
const cls = ['lt-log-output', 'pl-out-pre'];
|
||||||
|
if (o.err) cls.push('pl-out-err');
|
||||||
|
if (o.cls) cls.push(o.cls);
|
||||||
|
if (storage.get(OUT_WRAP_KEY, true) === false) cls.push('is-nowrap');
|
||||||
|
if (tall) cls.push('is-tall');
|
||||||
|
return '<div class="pl-out" id="' + id + '">' +
|
||||||
|
'<div class="pl-out-bar">' +
|
||||||
|
(o.label ? '<span class="pl-out-label">' + esc(o.label) + '</span>' : '') +
|
||||||
|
outButton('out:copy', id, 'Copy', 'Copy the full output') +
|
||||||
|
outButton('out:wrap', id, 'Wrap', 'Wrap long lines on or off') +
|
||||||
|
(tall ? outButton('out:expand', id, 'Expand', 'Show every line') : '') +
|
||||||
|
outButton('out:download', id, '.txt', 'Download as a text file') +
|
||||||
|
'</div>' +
|
||||||
|
'<pre class="' + cls.join(' ') + '">' + esc(shown) + '</pre>' +
|
||||||
|
(clean.length > OUT_MAX
|
||||||
|
? '<div class="pl-out-note">Showing the first ' + OUT_MAX.toLocaleString() + ' of ' +
|
||||||
|
clean.length.toLocaleString() + ' characters. Copy and .txt include all of it.</div>'
|
||||||
|
: '') +
|
||||||
|
'</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
function outEntry(el) {
|
||||||
|
return _outTexts.get(el.getAttribute('data-out')) || { text: '', name: 'output' };
|
||||||
|
}
|
||||||
|
|
||||||
|
const outputActions = {
|
||||||
|
'out:copy': async (el) => {
|
||||||
|
const ok = LT().clipboard ? await LT().clipboard.copy(outEntry(el).text) : false;
|
||||||
|
toastSafe(ok ? 'success' : 'error', ok ? 'Output copied' : 'Copy failed');
|
||||||
|
},
|
||||||
|
'out:wrap': () => {
|
||||||
|
const wrap = storage.get(OUT_WRAP_KEY, true) === false; // currently off: turn on
|
||||||
|
storage.set(OUT_WRAP_KEY, wrap);
|
||||||
|
document.querySelectorAll('.pl-out-pre').forEach(p => p.classList.toggle('is-nowrap', !wrap));
|
||||||
|
},
|
||||||
|
'out:expand': (el) => {
|
||||||
|
const block = document.getElementById(el.getAttribute('data-out'));
|
||||||
|
const pre = block && block.querySelector('.pl-out-pre');
|
||||||
|
if (!pre) return;
|
||||||
|
const open = pre.classList.toggle('is-expanded');
|
||||||
|
el.textContent = open ? 'Collapse' : 'Expand';
|
||||||
|
},
|
||||||
|
'out:download': (el) => {
|
||||||
|
const e = outEntry(el);
|
||||||
|
download(e.name + '.txt', e.text);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
/* Verbatim localStorage keys: `commandHistory` and `pulse_executionView`
|
/* Verbatim localStorage keys: `commandHistory` and `pulse_executionView`
|
||||||
must keep working across the redesign, so NO prefix is applied. */
|
must keep working across the redesign, so NO prefix is applied. */
|
||||||
const storage = {
|
const storage = {
|
||||||
@@ -673,7 +754,8 @@
|
|||||||
get beep() { return LT().beep; },
|
get beep() { return LT().beep; },
|
||||||
esc: esc,
|
esc: esc,
|
||||||
fmt: fmt,
|
fmt: fmt,
|
||||||
util: { download: download, storage: storage, throttle: throttle },
|
util: { download: download, storage: storage, throttle: throttle, stripAnsi: stripAnsi },
|
||||||
|
output: { render: renderOutput },
|
||||||
|
|
||||||
/** Escape hatch for pages that need to push a frame upstream. */
|
/** Escape hatch for pages that need to push a frame upstream. */
|
||||||
ws: { send(d) { return _wsHandle && _wsHandle.send ? _wsHandle.send(d) : false; }, get handle() { return _wsHandle; } },
|
ws: { send(d) { return _wsHandle && _wsHandle.send ? _wsHandle.send(d) : false; }, get handle() { return _wsHandle; } },
|
||||||
@@ -691,6 +773,7 @@
|
|||||||
'open-cmdpalette': () => { if (LT().cmdPalette) LT().cmdPalette.open(); },
|
'open-cmdpalette': () => { if (LT().cmdPalette) LT().cmdPalette.open(); },
|
||||||
'app:keys-help': openKeysHelp,
|
'app:keys-help': openKeysHelp,
|
||||||
});
|
});
|
||||||
|
actions.registerAll(outputActions);
|
||||||
|
|
||||||
installDelegation();
|
installDelegation();
|
||||||
|
|
||||||
|
|||||||
@@ -282,8 +282,9 @@
|
|||||||
return '<div class="ex-log-field"><span class="ex-log-label">' + esc(label) + ':</span> ' + value + '</div>';
|
return '<div class="ex-log-field"><span class="ex-log-label">' + esc(label) + ':</span> ' + value + '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
function out(text, isErr) {
|
// Shared output block: ANSI stripped, Copy / Wrap / Expand / .txt (#27).
|
||||||
return '<pre class="lt-log-output' + (isErr ? ' ex-log-output-err' : '') + '">' + esc(text) + '</pre>';
|
function out(text, isErr, name) {
|
||||||
|
return Pulse.output.render(text, { err: isErr, name: (name || 'pulse-output') + (isErr ? '-stderr' : '') });
|
||||||
}
|
}
|
||||||
|
|
||||||
function promptOptions(options, executionId) {
|
function promptOptions(options, executionId) {
|
||||||
@@ -314,8 +315,8 @@
|
|||||||
(ok ? '✓' : '✗') + ' Command Result',
|
(ok ? '✓' : '✗') + ' Command Result',
|
||||||
field('Status', ok ? 'Success' : 'Failed') +
|
field('Status', ok ? 'Success' : 'Failed') +
|
||||||
(log.duration ? field('Duration', esc(log.duration) + 'ms') : '') +
|
(log.duration ? field('Duration', esc(log.duration) + 'ms') : '') +
|
||||||
(log.stdout ? field('Output', out(log.stdout, false)) : '') +
|
(log.stdout ? field('Output', out(log.stdout, false, 'pulse-' + String(log.command_id || '').slice(0, 8))) : '') +
|
||||||
(log.stderr ? field('Errors', out(log.stderr, true)) : '') +
|
(log.stderr ? field('Errors', out(log.stderr, true, 'pulse-' + String(log.command_id || '').slice(0, 8))) : '') +
|
||||||
(log.error ? field('Error', esc(log.error)) : ''));
|
(log.error ? field('Error', esc(log.error)) : ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,13 +105,6 @@
|
|||||||
}
|
}
|
||||||
.qc-run-time { color: var(--text-muted); font-size: 0.75rem; }
|
.qc-run-time { color: var(--text-muted); font-size: 0.75rem; }
|
||||||
.qc-run-link { margin-left: auto; font-size: 0.75rem; }
|
.qc-run-link { margin-left: auto; font-size: 0.75rem; }
|
||||||
.qc-run-body pre {
|
|
||||||
max-height: 24rem;
|
|
||||||
overflow: auto;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
overflow-wrap: anywhere;
|
|
||||||
margin: 0.5rem 0 0;
|
|
||||||
}
|
|
||||||
.qc-out-err {
|
.qc-out-err {
|
||||||
color: var(--accent-red);
|
color: var(--accent-red);
|
||||||
border-left-color: var(--accent-red);
|
border-left-color: var(--accent-red);
|
||||||
|
|||||||
@@ -169,7 +169,6 @@
|
|||||||
/* Results show here as they arrive, per worker, instead of only in Executions (#5).
|
/* Results show here as they arrive, per worker, instead of only in Executions (#5).
|
||||||
A card per run: "running" until its command_result comes in over the live
|
A card per run: "running" until its command_result comes in over the live
|
||||||
connection, or a poll finds it finished if that event was missed. */
|
connection, or a poll finds it finished if that event was missed. */
|
||||||
const OUTPUT_MAX = 100000; // characters shown per stream
|
|
||||||
const _runs = new Map(); // execution id -> { card, startedAt, timer }
|
const _runs = new Map(); // execution id -> { card, startedAt, timer }
|
||||||
const _early = new Map(); // results that beat the POST response
|
const _early = new Map(); // results that beat the POST response
|
||||||
|
|
||||||
@@ -210,13 +209,6 @@
|
|||||||
'<div class="qc-run-body"></div></div>';
|
'<div class="qc-run-body"></div></div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
function clip(text) {
|
|
||||||
const t = String(text || '');
|
|
||||||
if (t.length <= OUTPUT_MAX) return esc(t);
|
|
||||||
return esc(t.slice(0, OUTPUT_MAX)) + '\n<span class="qc-out-note">[' + (t.length - OUTPUT_MAX).toLocaleString() +
|
|
||||||
' more characters: see the full output in Executions]</span>';
|
|
||||||
}
|
|
||||||
|
|
||||||
function failureLabel(r) {
|
function failureLabel(r) {
|
||||||
if (r.timed_out) return 'Timed out';
|
if (r.timed_out) return 'Timed out';
|
||||||
if (r.signal) return 'Killed (' + r.signal + ')';
|
if (r.signal) return 'Killed (' + r.signal + ')';
|
||||||
@@ -238,8 +230,9 @@
|
|||||||
const ms = typeof r.duration === 'number' ? r.duration : Date.now() - run.startedAt;
|
const ms = typeof r.duration === 'number' ? r.duration : Date.now() - run.startedAt;
|
||||||
run.card.querySelector('.qc-run-time').textContent = ms < 1000 ? ms + ' ms' : (ms / 1000).toFixed(1) + ' s';
|
run.card.querySelector('.qc-run-time').textContent = ms < 1000 ? ms + ' ms' : (ms / 1000).toFixed(1) + ' s';
|
||||||
const parts = [];
|
const parts = [];
|
||||||
if (r.stdout) parts.push('<pre class="lt-log-output qc-out">' + clip(r.stdout) + '</pre>');
|
const name = 'pulse-' + String(executionId).slice(0, 8);
|
||||||
if (r.stderr) parts.push('<pre class="lt-log-output qc-out-err">' + clip(r.stderr) + '</pre>');
|
if (r.stdout) parts.push(Pulse.output.render(r.stdout, { cls: 'qc-out', name: name }));
|
||||||
|
if (r.stderr) parts.push(Pulse.output.render(r.stderr, { err: true, cls: 'qc-out-err', name: name + '-stderr' }));
|
||||||
if (!r.success && r.error && !r.stderr) parts.push('<pre class="lt-log-output qc-out-err">' + esc(r.error) + '</pre>');
|
if (!r.success && r.error && !r.stderr) parts.push('<pre class="lt-log-output qc-out-err">' + esc(r.error) + '</pre>');
|
||||||
if (!parts.length) parts.push('<div class="qc-out-note">No output</div>');
|
if (!parts.length) parts.push('<div class="qc-out-note">No output</div>');
|
||||||
const body = run.card.querySelector('.qc-run-body');
|
const body = run.card.querySelector('.qc-run-body');
|
||||||
|
|||||||
@@ -166,3 +166,40 @@ test('only the worker picker for the chosen mode is shown', async ({ page }) =>
|
|||||||
await expect(page.locator('#qc-multi-mode')).toBeVisible();
|
await expect(page.locator('#qc-multi-mode')).toBeVisible();
|
||||||
await expect(page.locator('#qc-single-mode')).toBeHidden();
|
await expect(page.locator('#qc-single-mode')).toBeHidden();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('output is readable: colours stripped, Copy / Wrap / Expand / .txt (#27)', async ({ page, context }) => {
|
||||||
|
await context.grantPermissions(['clipboard-read', 'clipboard-write']);
|
||||||
|
await page.goto('/quick');
|
||||||
|
await page.locator('#qc-mode-single').check();
|
||||||
|
await page.locator('#qc-worker').selectOption({ label: 'node-01 (online)' });
|
||||||
|
await page.locator('#qc-command').fill(`printf '\\033[1;32mgreen\\033[0m plain\\n'; seq 1 40`);
|
||||||
|
await page.locator('#qc-execute-btn').click();
|
||||||
|
|
||||||
|
const block = page.locator('#qc-result .pl-out').first();
|
||||||
|
const pre = block.locator('pre');
|
||||||
|
await expect(pre).toContainText('green plain');
|
||||||
|
expect(await pre.textContent()).not.toContain('\u001b'); // no raw escape codes
|
||||||
|
|
||||||
|
// 41 lines: starts collapsed, Expand shows everything.
|
||||||
|
await expect(pre).toHaveClass(/is-tall/);
|
||||||
|
await block.getByRole('button', { name: 'Expand' }).click();
|
||||||
|
await expect(pre).toHaveClass(/is-expanded/);
|
||||||
|
await expect(block.getByRole('button', { name: 'Collapse' })).toBeVisible();
|
||||||
|
|
||||||
|
// Wrap toggles long-line wrapping, and the choice sticks.
|
||||||
|
await block.getByRole('button', { name: 'Wrap' }).click();
|
||||||
|
await expect(pre).toHaveClass(/is-nowrap/);
|
||||||
|
await block.getByRole('button', { name: 'Wrap' }).click();
|
||||||
|
await expect(pre).not.toHaveClass(/is-nowrap/);
|
||||||
|
|
||||||
|
// Copy gives the full, clean text.
|
||||||
|
await block.getByRole('button', { name: 'Copy' }).click();
|
||||||
|
const copied = await page.evaluate(() => navigator.clipboard.readText());
|
||||||
|
expect(copied.startsWith('green plain\n1\n2\n')).toBe(true);
|
||||||
|
expect(copied.trim().endsWith('40')).toBe(true);
|
||||||
|
|
||||||
|
// .txt downloads the same text.
|
||||||
|
const [dl] = await Promise.all([page.waitForEvent('download'), block.getByRole('button', { name: '.txt' }).click()]);
|
||||||
|
expect(dl.suggestedFilename()).toMatch(/^pulse-[0-9a-f]{8}\.txt$/);
|
||||||
|
expect(require('fs').readFileSync(await dl.path(), 'utf8')).toBe(copied);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user