Readable command output: ANSI stripped, Copy / Wrap / Expand / .txt (#27)
CI / Lint (eslint) (pull_request) Successful in 20s
CI / Test (jest) (pull_request) Successful in 21s
CI / Security (npm audit) (pull_request) Successful in 15s
CI / Integration (api) (pull_request) Successful in 2m43s
CI / Scan (secrets, workflows, shell) (pull_request) Successful in 2m44s
CI / UI (playwright) (pull_request) Successful in 2m35s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / Notify (pull_request) Skipped
CI / UI screenshots (before/after) (pull_request) Successful in 1m54s
CI / Lint (eslint) (pull_request) Successful in 20s
CI / Test (jest) (pull_request) Successful in 21s
CI / Security (npm audit) (pull_request) Successful in 15s
CI / Integration (api) (pull_request) Successful in 2m43s
CI / Scan (secrets, workflows, shell) (pull_request) Successful in 2m44s
CI / UI (playwright) (pull_request) Successful in 2m35s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / Notify (pull_request) Skipped
CI / UI screenshots (before/after) (pull_request) Successful in 1m54s
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
64703482fd
commit
ecc1b447be
6 files changed
+162
-22
No files matched your search
+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`
|
||||
must keep working across the redesign, so NO prefix is applied. */
|
||||
const storage = {
|
||||
@@ -673,7 +754,8 @@
|
||||
get beep() { return LT().beep; },
|
||||
esc: esc,
|
||||
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. */
|
||||
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(); },
|
||||
'app:keys-help': openKeysHelp,
|
||||
});
|
||||
actions.registerAll(outputActions);
|
||||
|
||||
installDelegation();
|
||||
|
||||
|
||||
Reference in new issue
Block a user