@noisybrood/cli 0.0.0-stage → 0.2.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/LICENSE +202 -0
- package/README.md +83 -2
- package/dist/brood/api/src/client.js +58 -0
- package/dist/brood/api/src/origin.js +7 -0
- package/dist/brood/api/src/values.js +96 -0
- package/dist/brood/figures/index.js +4 -0
- package/dist/brood/tokens/dark.js +2 -0
- package/dist/brood/tokens/src/wren.js +58 -0
- package/dist/brood.js +33 -0
- package/dist/client.js +100 -0
- package/dist/commands.js +596 -0
- package/dist/io.js +50 -0
- package/dist/keychain.js +104 -0
- package/dist/main.js +213 -0
- package/dist/out.js +53 -0
- package/dist/sign-in.js +129 -0
- package/dist/store.js +138 -0
- package/dist/version.js +16 -0
- package/dist/wren.js +147 -0
- package/package.json +37 -4
package/dist/wren.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { DARK_BARN } from "./brood/tokens/dark.js";
|
|
2
|
+
import { BODY, DETAIL_WEIGHT, EYE, WING } from "./brood/tokens/src/wren.js";
|
|
3
|
+
/** A path of M, L and C commands, as the wren's are, as polylines. */
|
|
4
|
+
function polylines(d) {
|
|
5
|
+
const tokens = d.match(/[MLCZ]|-?\d*\.?\d+/g) ?? [];
|
|
6
|
+
const lines = [];
|
|
7
|
+
let line = [];
|
|
8
|
+
let at = [0, 0];
|
|
9
|
+
let command = "";
|
|
10
|
+
const num = () => Number(tokens.shift());
|
|
11
|
+
while (tokens.length) {
|
|
12
|
+
if (/[MLCZ]/.test(tokens[0]))
|
|
13
|
+
command = tokens.shift();
|
|
14
|
+
if (command === "M") {
|
|
15
|
+
if (line.length)
|
|
16
|
+
lines.push(line);
|
|
17
|
+
at = [num(), num()];
|
|
18
|
+
line = [at];
|
|
19
|
+
}
|
|
20
|
+
else if (command === "L") {
|
|
21
|
+
at = [num(), num()];
|
|
22
|
+
line.push(at);
|
|
23
|
+
}
|
|
24
|
+
else if (command === "C") {
|
|
25
|
+
const c1 = [num(), num()];
|
|
26
|
+
const c2 = [num(), num()];
|
|
27
|
+
const end = [num(), num()];
|
|
28
|
+
const from = at;
|
|
29
|
+
for (let i = 1; i <= 16; i++) {
|
|
30
|
+
const t = i / 16;
|
|
31
|
+
const u = 1 - t;
|
|
32
|
+
line.push([
|
|
33
|
+
u ** 3 * from[0] +
|
|
34
|
+
3 * u * u * t * c1[0] +
|
|
35
|
+
3 * u * t * t * c2[0] +
|
|
36
|
+
t ** 3 * end[0],
|
|
37
|
+
u ** 3 * from[1] +
|
|
38
|
+
3 * u * u * t * c1[1] +
|
|
39
|
+
3 * u * t * t * c2[1] +
|
|
40
|
+
t ** 3 * end[1],
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
at = end;
|
|
44
|
+
}
|
|
45
|
+
else if (command === "Z") {
|
|
46
|
+
if (line[0])
|
|
47
|
+
line.push(line[0]);
|
|
48
|
+
command = "";
|
|
49
|
+
}
|
|
50
|
+
else
|
|
51
|
+
throw new Error(`the wren's path has a command this does not draw: ${command}`);
|
|
52
|
+
}
|
|
53
|
+
if (line.length)
|
|
54
|
+
lines.push(line);
|
|
55
|
+
return lines;
|
|
56
|
+
}
|
|
57
|
+
const body = polylines(BODY)[0];
|
|
58
|
+
const wing = polylines(WING)[0];
|
|
59
|
+
/** Even-odd: whether a point is inside the closed outline. */
|
|
60
|
+
function inside(p, outline) {
|
|
61
|
+
let within = false;
|
|
62
|
+
for (let i = 0, j = outline.length - 1; i < outline.length; j = i++) {
|
|
63
|
+
const [xi, yi] = outline[i];
|
|
64
|
+
const [xj, yj] = outline[j];
|
|
65
|
+
if (yi > p[1] !== yj > p[1] &&
|
|
66
|
+
p[0] < ((xj - xi) * (p[1] - yi)) / (yj - yi) + xi)
|
|
67
|
+
within = !within;
|
|
68
|
+
}
|
|
69
|
+
return within;
|
|
70
|
+
}
|
|
71
|
+
/** How far a point is from an open polyline. */
|
|
72
|
+
function distance(p, line) {
|
|
73
|
+
let best = Infinity;
|
|
74
|
+
for (let i = 1; i < line.length; i++) {
|
|
75
|
+
const [ax, ay] = line[i - 1];
|
|
76
|
+
const [bx, by] = line[i];
|
|
77
|
+
const dx = bx - ax;
|
|
78
|
+
const dy = by - ay;
|
|
79
|
+
const t = Math.max(0, Math.min(1, ((p[0] - ax) * dx + (p[1] - ay) * dy) / (dx * dx + dy * dy)));
|
|
80
|
+
best = Math.min(best, Math.hypot(p[0] - (ax + t * dx), p[1] - (ay + t * dy)));
|
|
81
|
+
}
|
|
82
|
+
return best;
|
|
83
|
+
}
|
|
84
|
+
/** Whether the wren is inked at a point: in the body, and not in the eye or the wing. */
|
|
85
|
+
const inked = (p) => inside(p, body) &&
|
|
86
|
+
Math.hypot(p[0] - EYE.cx, p[1] - EYE.cy) > EYE.r &&
|
|
87
|
+
distance(p, wing) > DETAIL_WEIGHT / 2;
|
|
88
|
+
/** From an empty cell to a full one. */
|
|
89
|
+
const RAMP = " .:-=+*#%@";
|
|
90
|
+
/** The wren, `columns` characters wide, as lines, trimmed to the bird. */
|
|
91
|
+
export function wrenArt(columns = 32) {
|
|
92
|
+
const xs = body.map((p) => p[0]);
|
|
93
|
+
const ys = body.map((p) => p[1]);
|
|
94
|
+
const [left, right] = [Math.min(...xs), Math.max(...xs)];
|
|
95
|
+
const [top, bottom] = [Math.min(...ys), Math.max(...ys)];
|
|
96
|
+
const cell = (right - left) / columns;
|
|
97
|
+
const rows = Math.ceil((bottom - top) / (cell * 2));
|
|
98
|
+
const SAMPLES = 4;
|
|
99
|
+
const lines = [];
|
|
100
|
+
for (let r = 0; r < rows; r++) {
|
|
101
|
+
let line = "";
|
|
102
|
+
for (let c = 0; c < columns; c++) {
|
|
103
|
+
let hits = 0;
|
|
104
|
+
for (let sy = 0; sy < SAMPLES * 2; sy++)
|
|
105
|
+
for (let sx = 0; sx < SAMPLES; sx++)
|
|
106
|
+
if (inked([
|
|
107
|
+
left + (c + (sx + 0.5) / SAMPLES) * cell,
|
|
108
|
+
top + (r * 2 + (sy + 0.5) / SAMPLES) * cell,
|
|
109
|
+
]))
|
|
110
|
+
hits++;
|
|
111
|
+
line +=
|
|
112
|
+
RAMP[Math.round((hits / (SAMPLES * SAMPLES * 2)) * (RAMP.length - 1))] ?? " ";
|
|
113
|
+
}
|
|
114
|
+
lines.push(line.trimEnd());
|
|
115
|
+
}
|
|
116
|
+
return lines;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Barn, as the dark scheme sets it (`DARK_BARN`). A terminal does not say
|
|
120
|
+
* whether its ground is light or dark, and this one holds 3:1 on white, on
|
|
121
|
+
* black and on Ink, where the light scheme's falls short on a dark ground. It
|
|
122
|
+
* is the screen's one drop of Barn.
|
|
123
|
+
*/
|
|
124
|
+
function barn() {
|
|
125
|
+
const [r, g, b] = [1, 3, 5].map((i) => parseInt(DARK_BARN.slice(i, i + 2), 16));
|
|
126
|
+
return [r, g, b];
|
|
127
|
+
}
|
|
128
|
+
/** The levels of xterm's 256-colour cube, for a terminal with no true colour. */
|
|
129
|
+
const CUBE = [0, 95, 135, 175, 215, 255];
|
|
130
|
+
const nearest = (c) => CUBE.reduce((best, level, i) => Math.abs(level - c) < Math.abs(CUBE[best] - c) ? i : best, 0);
|
|
131
|
+
/** How much colour a terminal shows, as it says in its environment. */
|
|
132
|
+
export const depthOf = (env) => env.COLORTERM === "truecolor" || env.COLORTERM === "24bit"
|
|
133
|
+
? "true"
|
|
134
|
+
: env.TERM?.includes("256color")
|
|
135
|
+
? "256"
|
|
136
|
+
: "none";
|
|
137
|
+
/** The wren's lines, inked in Barn as deep as the terminal shows it. */
|
|
138
|
+
export function wrenIn(depth, columns) {
|
|
139
|
+
const art = wrenArt(columns);
|
|
140
|
+
if (depth === "none")
|
|
141
|
+
return art;
|
|
142
|
+
const [r, g, b] = barn();
|
|
143
|
+
const ink = depth === "true"
|
|
144
|
+
? `\u001b[38;2;${r};${g};${b}m`
|
|
145
|
+
: `\u001b[38;5;${16 + 36 * nearest(r) + 6 * nearest(g) + nearest(b)}m`;
|
|
146
|
+
return art.map((line) => (line ? `${ink}${line}\u001b[39m` : line));
|
|
147
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noisybrood/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "brood, the command line over Noisy Brood's index of who writes to you. It never reads a message.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"brood": "dist/brood.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=24"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"cli",
|
|
18
|
+
"email",
|
|
19
|
+
"gmail",
|
|
20
|
+
"metadata",
|
|
21
|
+
"privacy"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"provenance": true
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -p .",
|
|
29
|
+
"test": "node --test src/*.test.ts"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "26.6.6",
|
|
33
|
+
"typescript": "6.0.3"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/Noisy-Brood/brood-cli.git"
|
|
38
|
+
}
|
|
39
|
+
}
|