spider-paint 26.11.25004 → 26.11.26002
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/MCP.md +1 -1
- package/README.md +57 -3
- package/bin/cloud-run.mjs +2 -2
- package/bin/spider-md.mjs +88 -0
- package/bin/spider-paint.mjs +3 -0
- package/bin/spider-term.mjs +55 -4
- package/bin/term-app.mjs +417 -0
- package/bin/term-help.mjs +102 -0
- package/bin/term-image.mjs +217 -0
- package/help/building.md +66 -0
- package/help/commands.md +27 -0
- package/help/edit.md +56 -0
- package/help/flying.md +23 -0
- package/help/index.md +22 -0
- package/help/more.md +12 -0
- package/help/saving.md +32 -0
- package/help/screen.md +39 -0
- package/help/space.md +19 -0
- package/help/stories.md +25 -0
- package/help/vr.md +26 -0
- package/help/writing.md +46 -0
- package/index.html +86 -87
- package/mcp/serve.js +2 -2
- package/mcp/workshop-native-inline.js +1 -1
- package/package.json +5 -4
- package/src/md/help.js +40 -0
- package/src/md/highlight.js +560 -0
- package/src/md/markdown.js +384 -0
- package/sw.js +1 -1
- package/help.md +0 -334
package/MCP.md
CHANGED
|
@@ -166,7 +166,7 @@ A command reaches only viewers that are open: the result's `sent_to` says how ma
|
|
|
166
166
|
|
|
167
167
|
### What the person can do in the viewer
|
|
168
168
|
|
|
169
|
-
Enter: find a target by name. Tab: next target. W/S, A/D, R/F: speed forward, sideways, up. [ / ő and ] / ú: roll. 0 / ö: orbit. Space: stop. Esc: let go. `?` opens the full help (help
|
|
169
|
+
Enter: find a target by name. Tab: next target. W/S, A/D, R/F: speed forward, sideways, up. [ / ő and ] / ú: roll. 0 / ö: orbit. Space: stop. Esc: let go. `?` opens the full help (the `help/` folder: one markdown file a section).
|
|
170
170
|
|
|
171
171
|
## Tools
|
|
172
172
|
|
package/README.md
CHANGED
|
@@ -55,12 +55,66 @@ Open http://localhost:5173. No application build system is needed.
|
|
|
55
55
|
### In a terminal
|
|
56
56
|
|
|
57
57
|
```sh
|
|
58
|
-
npm run term --
|
|
59
|
-
npx spider-paint-term
|
|
58
|
+
npm run term -- bridge # a scene name (default: the app's start scene)
|
|
59
|
+
npx spider-paint-term deepsky
|
|
60
|
+
node bin/spider-term.mjs globe --native # the terminal's own renderer (no Chrome needed)
|
|
60
61
|
node bin/spider-term.mjs lark-4 --once --cols 100 --rows 30 > frame.ans
|
|
61
62
|
```
|
|
62
63
|
|
|
63
|
-
The
|
|
64
|
+
**The app way (the default when a Chrome / Chromium / Edge is found; `CHROME_PATH` names one):** the real spider-paint runs
|
|
65
|
+
in a headless Chrome from this checkout (`bin/term-app.mjs`, the DevTools protocol over node's own WebSocket, node 22+), so
|
|
66
|
+
**every key and mode works** as in the browser: flying (W A S D R F, Space), T, Tab, M, X, G, B, P, Q and the edit keys,
|
|
67
|
+
J, E, L, N, K, C, 9, Z… The picture is the app's own view in half blocks (rough, that is fine). Under it: **an info line**
|
|
68
|
+
with the HUD's important bits (EDIT, speed, the target, the object under the cross, fps; a command's answer for a moment)
|
|
69
|
+
and **the Enter line**, lighter while the Enter box is open (focused): what you type goes into the app's box, its list (the
|
|
70
|
+
targets, `/l` scenes, `/mat`, `/help`…) covers the bottom of the view, ↑↓ / Tab / Enter / Esc and a click on a row work
|
|
71
|
+
as in the app; in the edit mode (Q), where Enter builds, cuts or turns, **Shift+Enter** opens the box (the terminal is asked
|
|
72
|
+
for the kitty keyboard protocol so that it can tell Shift+Enter apart; **Alt+Enter** does the same in every terminal).
|
|
73
|
+
**`/q`** (`/quit`) in the box leaves. The mouse is the app's (the cross follows it, drag turns, the wheel zooms; Shift / Option + drag selects
|
|
74
|
+
terminal text). Ctrl+C quits. On WSL: install a Chrome or Chromium inside Ubuntu, or the native viewer starts.
|
|
75
|
+
|
|
76
|
+
A scene **file** (`.json`, `.3draft`, a sky catalogue, a story) is packed into the page's address, as an MCP link is, and
|
|
77
|
+
**loaded again whenever the file is saved** — edit the JSON in one window, watch it in the other.
|
|
78
|
+
|
|
79
|
+
### In VS Code
|
|
80
|
+
|
|
81
|
+
`vscode/` is a VS Code extension: the app itself in a webview tab (sharp, every key). Commands: **Spider Paint: Open**,
|
|
82
|
+
**Open a scene from the list…**, **Show this scene file in 3D** (the editor's `.json` / `.3draft` beside it, reloaded on
|
|
83
|
+
every save; also a button in the editor's title bar). Try it from the checkout: open the `vscode` folder in VS Code and
|
|
84
|
+
press F5 (it uses the checkout's app), or build a `.vsix` (`cd vscode && npm run package`, then
|
|
85
|
+
`code --install-extension spider-paint-*.vsix`); the *VS Code extension (.vsix)* workflow builds one on every push.
|
|
86
|
+
|
|
87
|
+
### The help and the markdown reader
|
|
88
|
+
|
|
89
|
+
The in-app help is the `help/` folder: `index.md` lists the sections, one markdown file each. `src/md/` reads them
|
|
90
|
+
(no dependencies, its own tests in `tests/md.mjs`, ready to live in a repository of its own): `markdown.js` turns the
|
|
91
|
+
blocks into the smallest HTML or into terminal lines, `highlight.js` colours code blocks and does not stop where the
|
|
92
|
+
languages nest — an ```html block's `<script>` is JavaScript, its `/** jsDoc */` gets its tags, names and `{TypeScript
|
|
93
|
+
types}` coloured, a `<style>` is CSS. The page's help panel and the terminal's help view (`?` in the app view, `/help
|
|
94
|
+
[word]` in the native one) show the same files with the same colours.
|
|
95
|
+
|
|
96
|
+
Markdown in colour on the console, with the same reader: `spider-paint -md file.md` (or `spider-md file.md`,
|
|
97
|
+
`npx spider-md README.md`; `-` reads stdin, `--width N`, `--page` through `less -R`, `--plain` without colours). A code
|
|
98
|
+
file (`.js`, `.html`, `.json`, `.rs`, `.sh`…) is shown as one coloured block. Pictures in the markdown (``, a path
|
|
99
|
+
beside the file or `https://…`) are drawn the way the 3D view is: half blocks, two pixels a cell (`--image-rows N`,
|
|
100
|
+
`--no-images`). PNG and GIF are read in node; JPEG, SVG and WebP go through a headless Chrome when there is one.
|
|
101
|
+
|
|
102
|
+
### In Vim / Neovim
|
|
103
|
+
|
|
104
|
+
The checkout is a Vim plugin too (`vim/plugin/spider-paint.vim`):
|
|
105
|
+
|
|
106
|
+
```vim
|
|
107
|
+
" vim-plug (lazy.nvim: { 'Pengeszikra/Spider-Paint', config = function(p) vim.opt.rtp:append(p.dir .. '/vim') end })
|
|
108
|
+
Plug 'Pengeszikra/Spider-Paint', { 'rtp': 'vim', 'do': 'npm install --omit=dev' }
|
|
109
|
+
set termguicolors mouse=a
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
`:SpiderPaint` opens spider-paint in a vertical terminal split: the buffer's scene file if it is one (saving it reloads the
|
|
113
|
+
view), else the start scene; `:SpiderPaint bridge` a scene of the + scene list; `:SpiderPaint path.json` a file.
|
|
114
|
+
`g:spider_paint_split` = `'vertical'` | `'horizontal'` | `'tab'`. In the split every key belongs to spider-paint; Ctrl+W
|
|
115
|
+
(Vim) or Ctrl+\ Ctrl+N (Neovim) gets back to the editor, Ctrl+C quits spider-paint. Vim 8.1+ or Neovim, node 22+.
|
|
116
|
+
|
|
117
|
+
**The native viewer (`--native`, or when there is no Chrome):** The scene is drawn with 24-bit colour half blocks (two pixels a character cell), a depth buffer and one shaded colour a
|
|
64
118
|
face (`src/term-render.js`, pure: no node, no DOM), with dark outlines at the silhouettes, folds and depth jumps in place of
|
|
65
119
|
the GPU's light play (`/outline` or `--flat` turns them off). The model fills the window. It is zen: only the picture. The mouse belongs to the program (the
|
|
66
120
|
terminal does not select the picture; Shift / Option + drag still selects): **drag** turns, the **wheel** zooms, the object
|
package/bin/cloud-run.mjs
CHANGED
|
@@ -32,9 +32,9 @@ const types = {
|
|
|
32
32
|
const publicFiles = new Set([
|
|
33
33
|
'index.html', 'player.html', 'emulator.html', 'sky.html',
|
|
34
34
|
'xr-test.html', 'xr-compare.html', 'workshop.html',
|
|
35
|
-
'favicon.svg', 'manifest.webmanifest', 'sw.js', '
|
|
35
|
+
'favicon.svg', 'manifest.webmanifest', 'sw.js', 'sky.md',
|
|
36
36
|
]);
|
|
37
|
-
const publicDirs = new Set(['src', 'engine', 'models', 'media', 'icons', 'app']);
|
|
37
|
+
const publicDirs = new Set(['src', 'engine', 'models', 'media', 'icons', 'app', 'help']);
|
|
38
38
|
async function serveStatic(req, res, url) {
|
|
39
39
|
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
40
40
|
res.writeHead(405, { Allow: 'GET, HEAD' }).end();
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Markdown in colour in the terminal (src/md: the same reader and code colours as the help):
|
|
3
|
+
// spider-md file.md [more.md …] [--width N] [--page] (- reads stdin; spider-paint -md file.md does the same)
|
|
4
|
+
// A file that is not markdown (.js, .html, .json, .rs, .sh…) is shown as one coloured code block.
|
|
5
|
+
// Pictures (, https://…) are drawn in half blocks (--image-rows N, --no-images).
|
|
6
|
+
// --page: through `less -R` when it is longer than the screen. --plain: no colours (a pipe gets them unless asked).
|
|
7
|
+
import { readFileSync, realpathSync } from 'node:fs';
|
|
8
|
+
import { spawnSync } from 'node:child_process';
|
|
9
|
+
import { extname, basename } from 'node:path';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { toAnsi, parse, inline } from '../src/md/markdown.js';
|
|
12
|
+
import { dirname, resolve as resolvePath } from 'node:path';
|
|
13
|
+
import { decodeImage, imageLines, closeImages } from './term-image.mjs';
|
|
14
|
+
|
|
15
|
+
const LANG = { '.js': 'js', '.mjs': 'js', '.cjs': 'js', '.jsx': 'js', '.ts': 'ts', '.tsx': 'ts', '.html': 'html', '.htm': 'html', '.svg': 'html', '.xml': 'html', '.css': 'css', '.json': 'json', '.3draft': 'json', '.sh': 'sh', '.bash': 'sh', '.zsh': 'sh', '.rs': 'rust', '.c': 'c', '.h': 'c', '.cpp': 'c', '.go': 'go', '.py': 'python', '.wat': 'wat', '.hexaw': 'wat' };
|
|
16
|
+
|
|
17
|
+
export const mdToTerminal = (text, { file = '', width = 100, images = null, rows = 20 } = {}) => {
|
|
18
|
+
const lang = LANG[extname(file).toLowerCase()];
|
|
19
|
+
const fence = '`'.repeat(Math.max(3, ...[...text.matchAll(/`{3,}/g)].map((m) => m[0].length + 1)));
|
|
20
|
+
const md = lang ? `${fence}${lang}\n${text.replace(/\n$/, '')}\n${fence}` : text;
|
|
21
|
+
const image = images ? (src, alt, cols) => (images.get(src) ? imageLines(images.get(src), { cols, rows }) : null) : null;
|
|
22
|
+
return toAnsi(md, { width, image }).join('\n');
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// the pictures a markdown text shows: read (a path next to the file, or https://…) and decoded, before the text is laid out
|
|
26
|
+
const picturesOf = (md) => {
|
|
27
|
+
const srcs = new Set();
|
|
28
|
+
const walk = (blocks) => {
|
|
29
|
+
for (const b of blocks) {
|
|
30
|
+
if (b.type === 'p') for (const s of inline(b.text)) if (s.img) srcs.add(s.img);
|
|
31
|
+
if (b.type === 'list') for (const it of b.items) (inline(it.text).forEach((s) => s.img && srcs.add(s.img)), walk(it.children));
|
|
32
|
+
if (b.type === 'quote') walk(b.blocks);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
walk(parse(md));
|
|
36
|
+
return [...srcs];
|
|
37
|
+
};
|
|
38
|
+
export const loadPictures = async (md, file) => {
|
|
39
|
+
const map = new Map();
|
|
40
|
+
for (const src of picturesOf(md)) {
|
|
41
|
+
try {
|
|
42
|
+
let buf;
|
|
43
|
+
if (/^https?:\/\//.test(src)) {
|
|
44
|
+
const r = await fetch(src, { signal: AbortSignal.timeout(8000) });
|
|
45
|
+
if (!r.ok) continue;
|
|
46
|
+
buf = Buffer.from(await r.arrayBuffer());
|
|
47
|
+
} else if (/^data:/.test(src)) buf = Buffer.from(src.split(',')[1] ?? '', /;base64,/.test(src) ? 'base64' : 'utf8');
|
|
48
|
+
else buf = readFileSync(resolvePath(file && file !== '-' ? dirname(file) : '.', decodeURIComponent(src.replace(/[?#].*$/, ''))));
|
|
49
|
+
const img = await decodeImage(buf, src);
|
|
50
|
+
if (img) map.set(src, img);
|
|
51
|
+
} catch {} // (a missing picture keeps its alt text)
|
|
52
|
+
}
|
|
53
|
+
return map;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const run = async (argv = process.argv.slice(2)) => {
|
|
57
|
+
const opt = (n) => {
|
|
58
|
+
const i = argv.indexOf(`--${n}`);
|
|
59
|
+
return i >= 0 ? argv[i + 1] : undefined;
|
|
60
|
+
};
|
|
61
|
+
const files = argv.filter((a, i) => (!a.startsWith('-') || a === '-') && !['--width', '--image-rows'].includes(argv[i - 1]));
|
|
62
|
+
if (!files.length) {
|
|
63
|
+
console.error('spider-md file.md [more.md …] [--width N] [--page] [--plain] (- reads stdin)');
|
|
64
|
+
return 2;
|
|
65
|
+
}
|
|
66
|
+
const width = Math.max(20, Number(opt('width')) || Math.min(process.stdout.columns || 100, 120));
|
|
67
|
+
const pics = !argv.includes('--no-images') && !argv.includes('--plain');
|
|
68
|
+
const rows = Math.max(6, Math.min(Number(opt('image-rows')) || 20, (process.stdout.rows || 40) - 4));
|
|
69
|
+
const parts = [];
|
|
70
|
+
for (const f of files) {
|
|
71
|
+
const text = f === '-' ? readFileSync(0, 'utf8') : readFileSync(f, 'utf8');
|
|
72
|
+
const images = pics && !LANG[extname(f).toLowerCase()] ? await loadPictures(text, f) : null;
|
|
73
|
+
parts.push((files.length > 1 ? `\x1b[2m── ${f === '-' ? 'stdin' : basename(f)} ──\x1b[0m\n` : '') + mdToTerminal(text, { file: f, width, images, rows }));
|
|
74
|
+
}
|
|
75
|
+
await closeImages();
|
|
76
|
+
let out = parts.join('\n\n');
|
|
77
|
+
if (argv.includes('--plain')) out = out.replace(/\x1b\[[0-9;]*m/g, '');
|
|
78
|
+
if (argv.includes('--page') && process.stdout.isTTY && out.split('\n').length > (process.stdout.rows || 0)) {
|
|
79
|
+
const r = spawnSync('less', ['-R'], { input: `${out}\n`, stdio: ['pipe', 'inherit', 'inherit'] });
|
|
80
|
+
if (!r.error) return 0;
|
|
81
|
+
}
|
|
82
|
+
process.stdout.write(`${out}\n`);
|
|
83
|
+
return 0;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// run as a command (also through npm's link in node_modules/.bin), not when imported
|
|
87
|
+
const self = (() => { try { return realpathSync(process.argv[1] ?? '') === realpathSync(fileURLToPath(import.meta.url)); } catch { return false; } })();
|
|
88
|
+
if (self) run().then((code) => (process.exitCode = code));
|
package/bin/spider-paint.mjs
CHANGED
|
@@ -5,6 +5,9 @@ import { resolve, join, sep, extname, dirname } from 'node:path';
|
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { buildInfo } from '../mcp/build-info.js';
|
|
7
7
|
const root=resolve(dirname(fileURLToPath(import.meta.url)),'..');
|
|
8
|
+
// spider-paint -md file.md: markdown in colour in the terminal (bin/spider-md.mjs), no server
|
|
9
|
+
const mdAt=process.argv.findIndex((a)=>a==='-md'||a==='--md');
|
|
10
|
+
if(mdAt>=0){const {run}=await import('./spider-md.mjs');process.exit(await run(process.argv.slice(2).filter((a,i)=>i!==mdAt-2)));}
|
|
8
11
|
const port=Number(process.env.PORT || process.argv[2] || 5173);
|
|
9
12
|
const versionInfo=JSON.stringify(buildInfo);
|
|
10
13
|
const types={'.html':'text/html; charset=utf-8','.js':'text/javascript; charset=utf-8','.mjs':'text/javascript; charset=utf-8','.json':'application/json; charset=utf-8','.svg':'image/svg+xml','.png':'image/png','.webmanifest':'application/manifest+json','.md':'text/plain; charset=utf-8','.css':'text/css; charset=utf-8','.wasm':'application/wasm'};
|
package/bin/spider-term.mjs
CHANGED
|
@@ -14,6 +14,8 @@ import { merge, bounds } from '../engine/45789c908f86/mesh.js';
|
|
|
14
14
|
import { instantiate } from '../engine/45789c908f86/instances.js';
|
|
15
15
|
import { BUILTIN_MATERIALS } from '../mcp/materials.js';
|
|
16
16
|
import { rasterize, rasterSky, lookAtAngles, ansiLines, fitZoom } from '../src/term-render.js';
|
|
17
|
+
import { createHelpView } from './term-help.mjs';
|
|
18
|
+
import { helpBlocks, helpSections } from '../src/md/help.js';
|
|
17
19
|
|
|
18
20
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
19
21
|
const argv = process.argv.slice(2);
|
|
@@ -22,9 +24,23 @@ const opt = (name, d) => {
|
|
|
22
24
|
const i = argv.indexOf(`--${name}`);
|
|
23
25
|
return i >= 0 && argv[i + 1] !== undefined ? Number(argv[i + 1]) : d;
|
|
24
26
|
};
|
|
25
|
-
const VALUED = ['--cols', '--rows', '--yaw', '--pitch'];
|
|
27
|
+
const VALUED = ['--cols', '--rows', '--yaw', '--pitch', '--url'];
|
|
26
28
|
const named = argv.find((a, i) => !a.startsWith('--') && !VALUED.includes(argv[i - 1])) ?? 'bridge';
|
|
27
29
|
|
|
30
|
+
// The app way (the default when a Chrome is found): the real spider-paint in a headless Chrome, every key works
|
|
31
|
+
// (bin/term-app.mjs). --native: this file's own renderer (a viewer: the mouse turns and picks, Enter a few commands).
|
|
32
|
+
if (!flag('native') && !flag('once') && process.stdout.isTTY && process.stdin.isTTY) {
|
|
33
|
+
const { findChrome, runApp } = await import('./term-app.mjs');
|
|
34
|
+
const chrome = findChrome();
|
|
35
|
+
if (chrome && typeof WebSocket === 'function') {
|
|
36
|
+
await runApp({ root, scene: argv.find((a, i) => !a.startsWith('--') && !VALUED.includes(argv[i - 1])) ?? '', chrome, url: argv.includes('--url') ? argv[argv.indexOf('--url') + 1] : undefined });
|
|
37
|
+
await new Promise(() => {}); // (runApp runs until Ctrl+C)
|
|
38
|
+
}
|
|
39
|
+
globalThis.whyNative = chrome ? `the app view needs node 22 or newer (WebSocket); this is node ${process.versions.node}` : 'no Chrome / Chromium / Edge found (set CHROME_PATH to one)';
|
|
40
|
+
if (flag('app')) (console.error(`spider-term --app: ${globalThis.whyNative}`), process.exit(1));
|
|
41
|
+
console.error(`spider-term: ${globalThis.whyNative}; the native viewer starts`);
|
|
42
|
+
await new Promise((r) => setTimeout(r, 1500));
|
|
43
|
+
}
|
|
28
44
|
const MODELS = join(root, 'models');
|
|
29
45
|
const modelNames = () => readdirSync(MODELS).filter((f) => f.endsWith('.scene.json')).map((f) => f.replace(/\.scene\.json$/, '')).sort();
|
|
30
46
|
const fileOf = (n) => {
|
|
@@ -130,6 +146,7 @@ let shown = []; // the lines on the screen now (only the changed ones are writte
|
|
|
130
146
|
let line = { mode: 'none', text: '', until: 0 }; // none | prompt | note
|
|
131
147
|
const quit = (code = 0) => {
|
|
132
148
|
out.write(RESTORE);
|
|
149
|
+
if (globalThis.whyNative) console.error(`spider-term ran the native viewer: ${globalThis.whyNative}`); // (said again: the start message was under the picture)
|
|
133
150
|
process.exit(code);
|
|
134
151
|
};
|
|
135
152
|
for (const sig of ['SIGTERM', 'SIGHUP']) process.on(sig, () => quit(0)); // (killed from outside: the terminal is given back too)
|
|
@@ -150,8 +167,9 @@ const draw = () => {
|
|
|
150
167
|
paint();
|
|
151
168
|
}, Math.max(0, 33 - (performance.now() - lastPaint)));
|
|
152
169
|
};
|
|
170
|
+
let helpView = null, helpOn = false; // the help (/help): text from help/*.md in place of the picture
|
|
153
171
|
const paint = () => {
|
|
154
|
-
const lines = picture();
|
|
172
|
+
const lines = helpOn ? (helpView ??= createHelpView(root)).rows(size().cols, size().rows) : picture();
|
|
155
173
|
const { rows, cols } = size();
|
|
156
174
|
let buf = '\x1b[?2026h'; // synchronised output: the terminal shows the frame whole (where it is understood)
|
|
157
175
|
lines.forEach((l, i) => {
|
|
@@ -238,8 +256,27 @@ const run = (text) => {
|
|
|
238
256
|
case 'quit':
|
|
239
257
|
return quit();
|
|
240
258
|
case 'help':
|
|
241
|
-
case 'h':
|
|
242
|
-
|
|
259
|
+
case 'h': {
|
|
260
|
+
// the help as text; with a word: where it is first said
|
|
261
|
+
helpView ??= createHelpView(root);
|
|
262
|
+
let place = null, file = 'index.md';
|
|
263
|
+
if (arg) {
|
|
264
|
+
const dir = join(root, 'help');
|
|
265
|
+
const read = (f) => (existsSync(join(dir, f)) ? readFileSync(join(dir, f), 'utf8') : '');
|
|
266
|
+
const q = arg.toLowerCase();
|
|
267
|
+
for (const s of [{ file: 'index.md' }, ...helpSections(read('index.md'))]) {
|
|
268
|
+
const b = helpBlocks(read(s.file)).find((x) => x.text.toLowerCase().includes(q));
|
|
269
|
+
if (b) ((file = s.file), (place = { text: b.text.slice(Math.max(0, b.text.toLowerCase().indexOf(q) - 10)) }));
|
|
270
|
+
if (b) break;
|
|
271
|
+
}
|
|
272
|
+
if (!place) note(`"${arg}" is not in the help`);
|
|
273
|
+
}
|
|
274
|
+
helpView.open(file, place);
|
|
275
|
+
helpOn = true;
|
|
276
|
+
return draw();
|
|
277
|
+
}
|
|
278
|
+
case 'keys':
|
|
279
|
+
return note('/l scene · /view front|top|iso… · /spin · /outline · /fit · /zoom n · /ls · /help [word] · /q · a name: turn round that object');
|
|
243
280
|
default:
|
|
244
281
|
return note(`no command ${cmd} (/help)`);
|
|
245
282
|
}
|
|
@@ -266,6 +303,11 @@ const cellFace = (x, y) => {
|
|
|
266
303
|
return top >= 0 ? top : py + 1 < img.height ? img.ids[(py + 1) * img.width + px] : -1;
|
|
267
304
|
};
|
|
268
305
|
const mouse = (b, x, y, release) => {
|
|
306
|
+
if (helpOn) {
|
|
307
|
+
if (b & 64) return helpView.scroll((b & 3) === 0 ? -3 : 3, size().rows), draw();
|
|
308
|
+
if (!(b & 32) && !release && (b & 3) === 0 && y === 1) return helpView.click(x - 1), draw();
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
269
311
|
const motion = b & 32, button = b & 3, wheel = b & 64;
|
|
270
312
|
if (wheel) {
|
|
271
313
|
if (scene.sky) view.fov = Math.max(0.5 * D, Math.min(150 * D, view.fov * (button === 0 ? 1 / 1.12 : 1.12)));
|
|
@@ -311,6 +353,15 @@ process.stdin.on('data', (b) => {
|
|
|
311
353
|
s = s.replace(/\x1b\[<(\d+);(\d+);(\d+)([Mm])/g, (_, b2, x, y, m) => (mouse(Number(b2), Number(x), Number(y), m === 'm'), ''));
|
|
312
354
|
if (!s) return;
|
|
313
355
|
if (s.includes('\x03')) return quit();
|
|
356
|
+
if (helpOn && line.mode !== 'prompt') {
|
|
357
|
+
// the help's keys (Enter still opens the command line)
|
|
358
|
+
if (!/[\r\n]/.test(s)) {
|
|
359
|
+
const k = s === '\x1b' ? 'Escape' : { '\x1b[A': 'ArrowUp', '\x1b[B': 'ArrowDown', '\x1b[C': 'ArrowRight', '\x1b[D': 'ArrowLeft', '\x1b[5~': 'PageUp', '\x1b[6~': 'PageDown', '\x1b[H': 'Home', '\x1b[F': 'End', '\t': 'Tab', '\x1b[Z': 'Tab' }[s] ?? s;
|
|
360
|
+
const r = helpView.key({ key: k, shift: s === '\x1b[Z' }, size().rows);
|
|
361
|
+
if (r === 'close') helpOn = false;
|
|
362
|
+
return draw();
|
|
363
|
+
}
|
|
364
|
+
}
|
|
314
365
|
if (line.mode !== 'prompt') {
|
|
315
366
|
const at = s.search(/[\r\n]/);
|
|
316
367
|
if (at < 0) return; // (zen: no key but Enter)
|