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.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +920 -0
  3. package/README.zh.md +790 -0
  4. package/assets/rain.ogg +0 -0
  5. package/bin/dsh-glyph-probe.js +51 -0
  6. package/bin/dsh-live-trace.js +29 -0
  7. package/bin/dsh-live-working.js +14 -0
  8. package/cordis.patch.yml +31 -0
  9. package/icon.svg +12 -0
  10. package/index.js +328 -0
  11. package/lib/client.js +178 -0
  12. package/lib/instance.js +68 -0
  13. package/lib/normalize.js +850 -0
  14. package/lib/paths.js +66 -0
  15. package/lib/protocol.js +115 -0
  16. package/lib/registry.js +232 -0
  17. package/lib/tools.js +257 -0
  18. package/lib/tracker.js +648 -0
  19. package/lib/transport.js +231 -0
  20. package/locale/en.json +6 -0
  21. package/locale/zh.json +6 -0
  22. package/package.json +94 -0
  23. package/picture/call1.png +0 -0
  24. package/picture/call2.png +0 -0
  25. package/picture/sleep1.png +0 -0
  26. package/picture/sleep2.png +0 -0
  27. package/picture/tui1.png +0 -0
  28. package/picture/tui2.png +0 -0
  29. package/picture/type1.png +0 -0
  30. package/picture/type2.png +0 -0
  31. package/scripts/bench-render.mjs +69 -0
  32. package/scripts/demo-working.mjs +130 -0
  33. package/scripts/demo.mjs +284 -0
  34. package/scripts/install-profile.mjs +174 -0
  35. package/scripts/mock-provider.mjs +211 -0
  36. package/src/cli/cellsize.js +120 -0
  37. package/src/cli/format.js +73 -0
  38. package/src/cli/highlight.js +932 -0
  39. package/src/cli/i18n.js +457 -0
  40. package/src/cli/main.js +630 -0
  41. package/src/cli/markdown.js +753 -0
  42. package/src/cli/renderer.js +1044 -0
  43. package/src/cli/screen.js +270 -0
  44. package/src/cli/theme.js +221 -0
  45. package/src/cli/view-state.js +396 -0
  46. package/src/cli/views.js +406 -0
  47. package/src/cli/width.js +337 -0
  48. package/src/cli/working/art.js +413 -0
  49. package/src/cli/working/main.js +569 -0
  50. package/src/cli/working/packing.js +159 -0
  51. package/src/cli/working/picker.js +75 -0
  52. package/src/cli/working/props.js +385 -0
  53. package/src/cli/working/scene.js +837 -0
  54. package/src/cli/working/sky.js +641 -0
  55. package/src/cli/working/sound.js +400 -0
  56. package/src/cli/working/state.js +528 -0
@@ -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
+ }