flagstaff 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,11 @@ export interface Writer {
8
8
  * TTY stream carries it, and a writer without it is taken to be `DEFAULT_COLUMNS` wide.
9
9
  */
10
10
  readonly columns?: number | undefined;
11
+ /**
12
+ * How tall the terminal is, read at every paint like the width (frames-fit-the-screen R1).
13
+ * A writer without it — a pipe — is unbounded, and no frame is clipped.
14
+ */
15
+ readonly rows?: number | undefined;
11
16
  }
12
17
  /** Time as the loop sees it: burgee's `Runtime.clock` satisfies it, so does `manualClock()`. */
13
18
  export interface Clock {
@@ -29,7 +34,9 @@ export declare const DEFAULT_INTERVAL = 80;
29
34
  *
30
35
  * Between paints the cursor rests at the end of the frame's last row, which is where the
31
36
  * hoisted projection has always left it. A frame taller than the terminal cannot be reached
32
- * above its top row; that is the terminal's limit, and a caller lays out within its height.
37
+ * above its top row, so one is clipped (frames-fit-the-screen R2): its tail, the lines that
38
+ * change, under one dim `… N more` line. `release` then writes the whole frame once, because
39
+ * a final write needs no repaint, so nothing the frame held is lost to the clip.
33
40
  */
34
41
  export interface FrameWriter {
35
42
  paint(lines: readonly string[]): void;
@@ -1,6 +1,7 @@
1
1
  import { onExit } from 'closeout';
2
2
  import { HIDE_CURSOR, SHOW_CURSOR } from 'closeout/cursor';
3
3
  import { lineCount } from 'linegauge';
4
+ import { muted } from 'roundel/tokens';
4
5
  export const DEFAULT_INTERVAL = 80;
5
6
  const DEFAULT_COLUMNS = 80;
6
7
  const CSI = '\u001B[';
@@ -40,20 +41,38 @@ function diff(was, now, sameWidth) {
40
41
  }
41
42
  export function frameWriter(out) {
42
43
  let shown;
43
- let width = 0;
44
+ let whole;
45
+ let size = '';
46
+ const write = (bytes) => {
47
+ if (bytes !== '')
48
+ out.write(`${BEGIN_SYNC}${bytes}${END_SYNC}`);
49
+ };
44
50
  return {
45
51
  paint(lines) {
46
- const frame = lines.length === 0 ? [''] : [...lines];
52
+ let frame = lines.length === 0 ? [''] : [...lines];
47
53
  const columns = columnsOf(out);
48
- const now = { lines: frame, rows: frame.map((line) => lineCount(line, columns)) };
49
- const bytes = shown === undefined ? frame.join('\n') : diff(shown, now, columns === width);
54
+ const tall = (out.rows ?? 0) > 0 ? out.rows : Number.POSITIVE_INFINITY;
55
+ const heights = () => frame.map((line) => lineCount(line, columns));
56
+ let rows = heights();
57
+ whole = undefined;
58
+ if (rows.reduce((sum, n) => sum + n, 0) > tall) {
59
+ let cut = frame.length;
60
+ for (let used = 1; cut > 0 && (used += rows[cut - 1]) <= tall;)
61
+ cut -= 1;
62
+ whole = frame;
63
+ frame = [muted(`… ${cut} more`), ...frame.slice(cut)];
64
+ rows = heights();
65
+ }
66
+ const now = { lines: frame, rows };
67
+ const at = `${columns} ${tall}`;
68
+ write(shown === undefined ? frame.join('\n') : diff(shown, now, at === size));
69
+ size = at;
50
70
  shown = now;
51
- width = columns;
52
- if (bytes !== '')
53
- out.write(`${BEGIN_SYNC}${bytes}${END_SYNC}`);
54
71
  },
55
72
  release() {
56
- shown = undefined;
73
+ if (shown !== undefined && whole !== undefined)
74
+ write(diff(shown, { lines: whole, rows: [] }, false));
75
+ shown = whole = undefined;
57
76
  },
58
77
  };
59
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flagstaff",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "Spinners, progress, boxes and tables on one terminal frame loop, with a static projection for pipes, screen readers and agents, and a plugin host. No dependency outside the burgee family. Drop-in paths for ora, log-update, boxen and cli-table3.",
5
5
  "license": "MIT",
6
6
  "type": "module",