dsh-live-trace 0.1.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 +21 -0
- package/README.md +920 -0
- package/README.zh.md +790 -0
- package/assets/rain.ogg +0 -0
- package/bin/dsh-glyph-probe.js +51 -0
- package/bin/dsh-live-trace.js +29 -0
- package/bin/dsh-live-working.js +14 -0
- package/cordis.patch.yml +31 -0
- package/icon.svg +12 -0
- package/index.js +328 -0
- package/lib/client.js +178 -0
- package/lib/instance.js +68 -0
- package/lib/normalize.js +850 -0
- package/lib/paths.js +66 -0
- package/lib/protocol.js +115 -0
- package/lib/registry.js +232 -0
- package/lib/tools.js +257 -0
- package/lib/tracker.js +648 -0
- package/lib/transport.js +231 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +94 -0
- package/picture/call1.png +0 -0
- package/picture/call2.png +0 -0
- package/picture/sleep1.png +0 -0
- package/picture/sleep2.png +0 -0
- package/picture/tui1.png +0 -0
- package/picture/tui2.png +0 -0
- package/picture/type1.png +0 -0
- package/picture/type2.png +0 -0
- package/scripts/bench-render.mjs +69 -0
- package/scripts/demo-working.mjs +130 -0
- package/scripts/demo.mjs +284 -0
- package/scripts/install-profile.mjs +174 -0
- package/scripts/mock-provider.mjs +211 -0
- package/src/cli/cellsize.js +120 -0
- package/src/cli/format.js +73 -0
- package/src/cli/highlight.js +932 -0
- package/src/cli/i18n.js +457 -0
- package/src/cli/main.js +630 -0
- package/src/cli/markdown.js +753 -0
- package/src/cli/renderer.js +1044 -0
- package/src/cli/screen.js +270 -0
- package/src/cli/theme.js +221 -0
- package/src/cli/view-state.js +396 -0
- package/src/cli/views.js +406 -0
- package/src/cli/width.js +337 -0
- package/src/cli/working/art.js +413 -0
- package/src/cli/working/main.js +569 -0
- package/src/cli/working/packing.js +159 -0
- package/src/cli/working/picker.js +75 -0
- package/src/cli/working/props.js +385 -0
- package/src/cli/working/scene.js +837 -0
- package/src/cli/working/sky.js +641 -0
- package/src/cli/working/sound.js +400 -0
- package/src/cli/working/state.js +528 -0
package/lib/instance.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-process instance bookkeeping for the observer plugin.
|
|
3
|
+
*
|
|
4
|
+
* Cordis hot reload can load a fresh generation of a plugin before the previous
|
|
5
|
+
* generation's disposer has finished. Both generations would then want the same
|
|
6
|
+
* socket path (same pid). This module lets the new generation release the old
|
|
7
|
+
* server first, and lets a stale disposer avoid deleting the live generation's
|
|
8
|
+
* discovery record.
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-live-trace/instance
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** @type {Map<number, { close: () => Promise<void> }>} */
|
|
14
|
+
const active = new Map()
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Close a previously registered instance for this process, if any.
|
|
18
|
+
* @param {number} pid
|
|
19
|
+
* @returns {Promise<void>}
|
|
20
|
+
*/
|
|
21
|
+
export async function disconnectExistingInstance(pid) {
|
|
22
|
+
const existing = active.get(pid)
|
|
23
|
+
if (existing === undefined) return
|
|
24
|
+
active.delete(pid)
|
|
25
|
+
try {
|
|
26
|
+
await existing.close()
|
|
27
|
+
} catch {
|
|
28
|
+
/* a half-torn-down server is exactly why we are here */
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Record the server a fresh instance now owns.
|
|
34
|
+
* @param {number} pid
|
|
35
|
+
* @param {{ close: () => Promise<void> }} server
|
|
36
|
+
*/
|
|
37
|
+
export function registerInstance(pid, server) {
|
|
38
|
+
active.set(pid, server)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Drop a disposed instance's registration.
|
|
43
|
+
*
|
|
44
|
+
* Guarded on identity: a slow disposer from a previous generation must not
|
|
45
|
+
* evict the server a newer generation has already registered.
|
|
46
|
+
*
|
|
47
|
+
* @param {number} pid
|
|
48
|
+
* @param {{ close: () => Promise<void> }} server the caller's own server
|
|
49
|
+
* @returns {boolean} whether this call removed the registration
|
|
50
|
+
*/
|
|
51
|
+
export function releaseInstance(pid, server) {
|
|
52
|
+
if (active.get(pid) !== server) return false
|
|
53
|
+
active.delete(pid)
|
|
54
|
+
return true
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {number} pid
|
|
59
|
+
* @returns {boolean} whether this process currently has a registered observer
|
|
60
|
+
*/
|
|
61
|
+
export function hasInstance(pid) {
|
|
62
|
+
return active.has(pid)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** @returns {number} how many observer instances this process holds (0 or 1) */
|
|
66
|
+
export function instanceCount() {
|
|
67
|
+
return active.size
|
|
68
|
+
}
|