@promptctl/rich-js 0.20.0 → 0.21.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.
- package/dist/core/anchor.d.ts +5 -0
- package/dist/core/anchor.js +10 -0
- package/dist/core/color.js +11 -1
- package/dist/core/strip.d.ts +81 -29
- package/dist/core/strip.js +190 -66
- package/dist/core/style.js +1 -0
- package/dist/host/input.d.ts +5 -2
- package/dist/host/input.js +29 -10
- package/dist/index.d.ts +6 -6
- package/dist/index.js +3 -3
- package/dist/renderables/effect.d.ts +66 -8
- package/dist/renderables/effect.js +74 -23
- package/dist/renderables/effects.d.ts +28 -20
- package/dist/renderables/effects.js +54 -23
- package/dist/renderables/flexStrip.d.ts +1 -1
- package/dist/renderables/flexStrip.js +10 -9
- package/dist/renderables/progressBar.js +3 -2
- package/dist/widgets/hit.js +2 -4
- package/package.json +6 -2
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* FlexStrip reuses it verbatim. There is no second concept of "join."
|
|
17
17
|
*/
|
|
18
18
|
import { Segment } from "../core/segment.js";
|
|
19
|
+
import { drawItem, drawJoin } from "../core/strip.js";
|
|
19
20
|
function renderToBlock(r, options) {
|
|
20
21
|
const segments = [...r.render(options)];
|
|
21
22
|
let width = 0;
|
|
@@ -63,10 +64,10 @@ export class FlexStrip {
|
|
|
63
64
|
const joiner = this.joiner;
|
|
64
65
|
// Pre-render every item and every joiner form we might need. Doing this
|
|
65
66
|
// up-front turns packing into a pure data computation over widths.
|
|
66
|
-
const itemBlocks = items.map((it) => renderToBlock(it, options));
|
|
67
|
-
const startCap = (i) => joiner ? renderToBlock(joiner
|
|
68
|
-
const endCap = (i) => joiner ? renderToBlock(joiner
|
|
69
|
-
const midJoin = (i, j) => joiner ? renderToBlock(joiner
|
|
67
|
+
const itemBlocks = items.map((it) => renderToBlock(drawItem(it), options));
|
|
68
|
+
const startCap = (i) => joiner ? renderToBlock(drawJoin(joiner, null, items[i], { index: i }), options) : EMPTY_BLOCK;
|
|
69
|
+
const endCap = (i) => joiner ? renderToBlock(drawJoin(joiner, items[i], null, { index: i + 1 }), options) : EMPTY_BLOCK;
|
|
70
|
+
const midJoin = (i, j) => joiner ? renderToBlock(drawJoin(joiner, items[i], items[j], { index: j }), options) : EMPTY_BLOCK;
|
|
70
71
|
const lines = [];
|
|
71
72
|
let line = null;
|
|
72
73
|
const gapBlock = gap > 0
|
|
@@ -177,23 +178,23 @@ export class FlexStrip {
|
|
|
177
178
|
for (let i = 0; i < items.length; i++) {
|
|
178
179
|
const itemWidth = renderToBlock(items[i], options).width;
|
|
179
180
|
const sc = this.joiner
|
|
180
|
-
? renderToBlock(this.joiner
|
|
181
|
+
? renderToBlock(drawJoin(this.joiner, null, items[i], { index: i }), options).width
|
|
181
182
|
: 0;
|
|
182
183
|
const ec = this.joiner
|
|
183
|
-
? renderToBlock(this.joiner
|
|
184
|
+
? renderToBlock(drawJoin(this.joiner, items[i], null, { index: i + 1 }), options).width
|
|
184
185
|
: 0;
|
|
185
186
|
minimum = Math.max(minimum, itemWidth + sc + ec);
|
|
186
187
|
maximum += itemWidth;
|
|
187
188
|
if (i > 0) {
|
|
188
189
|
maximum += this.gap * 2;
|
|
189
190
|
if (this.joiner) {
|
|
190
|
-
maximum += renderToBlock(this.joiner
|
|
191
|
+
maximum += renderToBlock(drawJoin(this.joiner, items[i - 1], items[i], { index: i }), options).width;
|
|
191
192
|
}
|
|
192
193
|
}
|
|
193
194
|
}
|
|
194
195
|
if (this.joiner) {
|
|
195
|
-
maximum += renderToBlock(this.joiner
|
|
196
|
-
maximum += renderToBlock(this.joiner
|
|
196
|
+
maximum += renderToBlock(drawJoin(this.joiner, null, items[0], { index: 0 }), options).width;
|
|
197
|
+
maximum += renderToBlock(drawJoin(this.joiner, items[items.length - 1], null, { index: items.length }), options).width;
|
|
197
198
|
}
|
|
198
199
|
return { minimum, maximum };
|
|
199
200
|
}
|
|
@@ -7,7 +7,7 @@ import { Segment } from "../core/segment.js";
|
|
|
7
7
|
import { Style } from "../core/style.js";
|
|
8
8
|
import { drawable, getStyle } from "../core/protocol.js";
|
|
9
9
|
import { Effected } from "./effect.js";
|
|
10
|
-
import { EFFECT_CURVES,
|
|
10
|
+
import { EFFECT_CURVES, atShares, shimmer } from "./effects.js";
|
|
11
11
|
const BAR = "━";
|
|
12
12
|
const ASCII_BAR = "-";
|
|
13
13
|
const HALF_BAR_RIGHT = "╸";
|
|
@@ -70,7 +70,8 @@ export class ProgressBar {
|
|
|
70
70
|
const ink = back.drawnColors(depth).color ?? ColorSpec.default();
|
|
71
71
|
const glow = getStyle(options, "bar.pulse").drawnColors(depth).color ?? ColorSpec.default();
|
|
72
72
|
const loop = shimmer(PULSE_CURVE, width, PULSE_REACH, glow.getTruecolor(theme, true), 0);
|
|
73
|
-
|
|
73
|
+
const whole = new Map([[ink.getTruecolor(theme, true).hex, 1]]);
|
|
74
|
+
return atShares(loop, () => whole);
|
|
74
75
|
}
|
|
75
76
|
/** Rich 9d8f9a3 `__rich_console__`: the fill is counted in half cells, and a total of zero is a bar already full. */
|
|
76
77
|
completeHalves(width) {
|
package/dist/widgets/hit.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* answer "what is under the pointer", so the answer cannot disagree with what
|
|
12
12
|
* the user sees. Z-order is paint order — whoever painted a cell last owns it.
|
|
13
13
|
*/
|
|
14
|
+
import { drawnBy } from "../core/anchor.js";
|
|
14
15
|
import { Segment } from "../core/segment.js";
|
|
15
16
|
import { isScrollable } from "../core/protocol.js";
|
|
16
17
|
import { WidgetBase } from "./widget-base.js";
|
|
@@ -72,10 +73,7 @@ export function originOf(frame, widget) {
|
|
|
72
73
|
* or through a widget nested in its output.
|
|
73
74
|
*/
|
|
74
75
|
export function drew(frame, widget, x, y) {
|
|
75
|
-
|
|
76
|
-
if (a.owner === widget)
|
|
77
|
-
return true;
|
|
78
|
-
return false;
|
|
76
|
+
return drawnBy(Segment.anchorAt(frame, x, y), widget);
|
|
79
77
|
}
|
|
80
78
|
/**
|
|
81
79
|
* Where `widget`'s footprint sits in `frame`: the cell its row 0, column 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptctl/rich-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Rich text and beautiful formatting in the terminal — a TypeScript port of Python's Rich",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -99,7 +99,11 @@
|
|
|
99
99
|
],
|
|
100
100
|
"license": "MIT",
|
|
101
101
|
"devEngines": {
|
|
102
|
-
"runtime": {
|
|
102
|
+
"runtime": {
|
|
103
|
+
"name": "node",
|
|
104
|
+
"version": "^22.18.0 || >=23.6.0",
|
|
105
|
+
"onFail": "error"
|
|
106
|
+
}
|
|
103
107
|
},
|
|
104
108
|
"engines": {
|
|
105
109
|
"node": ">=20"
|