diff --git a/public/assets/app.css b/public/assets/app.css index 9b87fa4..1d4960d 100644 --- a/public/assets/app.css +++ b/public/assets/app.css @@ -187,3 +187,36 @@ html[data-theme="light"] .pulse-running { .lt-form-group { display: flex }, or hidden sections still show (both Quick Command worker pickers were visible in either mode). */ [hidden] { display: none !important; } + +/* Command output blocks (#27): toolbar above a wrapping, collapsible
. */
+.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); }
diff --git a/public/assets/app.js b/public/assets/app.js
index 41ede6c..5ad83f9 100644
--- a/public/assets/app.js
+++ b/public/assets/app.js
@@ -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 '';
+  }
+
+  /** 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 '
' + + '
' + + (o.label ? '' + esc(o.label) + '' : '') + + 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') + + '
' + + '
' + esc(shown) + '
' + + (clean.length > OUT_MAX + ? '
Showing the first ' + OUT_MAX.toLocaleString() + ' of ' + + clean.length.toLocaleString() + ' characters. Copy and .txt include all of it.
' + : '') + + '
'; + } + + 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(); diff --git a/public/assets/pages/executions.js b/public/assets/pages/executions.js index 3a6f664..5f8d44e 100644 --- a/public/assets/pages/executions.js +++ b/public/assets/pages/executions.js @@ -282,8 +282,9 @@ return '
' + esc(label) + ': ' + value + '
'; } - function out(text, isErr) { - return '
' + esc(text) + '
'; + // Shared output block: ANSI stripped, Copy / Wrap / Expand / .txt (#27). + function out(text, isErr, name) { + return Pulse.output.render(text, { err: isErr, name: (name || 'pulse-output') + (isErr ? '-stderr' : '') }); } function promptOptions(options, executionId) { @@ -314,8 +315,8 @@ (ok ? '✓' : '✗') + ' Command Result', field('Status', ok ? 'Success' : 'Failed') + (log.duration ? field('Duration', esc(log.duration) + 'ms') : '') + - (log.stdout ? field('Output', out(log.stdout, false)) : '') + - (log.stderr ? field('Errors', out(log.stderr, true)) : '') + + (log.stdout ? field('Output', out(log.stdout, false, 'pulse-' + String(log.command_id || '').slice(0, 8))) : '') + + (log.stderr ? field('Errors', out(log.stderr, true, 'pulse-' + String(log.command_id || '').slice(0, 8))) : '') + (log.error ? field('Error', esc(log.error)) : '')); } diff --git a/public/assets/pages/quick.css b/public/assets/pages/quick.css index 5b18915..7ee8054 100644 --- a/public/assets/pages/quick.css +++ b/public/assets/pages/quick.css @@ -105,13 +105,6 @@ } .qc-run-time { color: var(--text-muted); 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 { color: var(--accent-red); border-left-color: var(--accent-red); diff --git a/public/assets/pages/quick.js b/public/assets/pages/quick.js index 9ebabfc..a9d3251 100644 --- a/public/assets/pages/quick.js +++ b/public/assets/pages/quick.js @@ -169,7 +169,6 @@ /* 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 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 _early = new Map(); // results that beat the POST response @@ -210,13 +209,6 @@ '
'; } - function clip(text) { - const t = String(text || ''); - if (t.length <= OUTPUT_MAX) return esc(t); - return esc(t.slice(0, OUTPUT_MAX)) + '\n[' + (t.length - OUTPUT_MAX).toLocaleString() + - ' more characters: see the full output in Executions]'; - } - function failureLabel(r) { if (r.timed_out) return 'Timed out'; if (r.signal) return 'Killed (' + r.signal + ')'; @@ -238,8 +230,9 @@ 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'; const parts = []; - if (r.stdout) parts.push('
' + clip(r.stdout) + '
'); - if (r.stderr) parts.push('
' + clip(r.stderr) + '
'); + const name = 'pulse-' + String(executionId).slice(0, 8); + 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('
' + esc(r.error) + '
'); if (!parts.length) parts.push('
No output
'); const body = run.card.querySelector('.qc-run-body'); diff --git a/tests/ui/quick-command.ui.js b/tests/ui/quick-command.ui.js index b8f5697..bde3db8 100644 --- a/tests/ui/quick-command.ui.js +++ b/tests/ui/quick-command.ui.js @@ -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-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); +});