zion 2.3.0 → 2.4.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.
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/lib/render.tsx
4
+ import { render as inkRender } from "ink";
5
+
6
+ // src/lib/Screen.tsx
7
+ import { useCallback, useEffect, useState } from "react";
8
+ import { Box, useStdout } from "ink";
9
+ import { jsx } from "react/jsx-runtime";
10
+ function Screen({ children }) {
11
+ const { stdout } = useStdout();
12
+ const getSize = useCallback(() => ({ height: stdout.rows, width: stdout.columns }), [stdout]);
13
+ const [size, setSize] = useState(getSize);
14
+ useEffect(() => {
15
+ const onResize = () => setSize(getSize());
16
+ stdout.on("resize", onResize);
17
+ return () => {
18
+ stdout.off("resize", onResize);
19
+ };
20
+ }, [stdout, getSize]);
21
+ return /* @__PURE__ */ jsx(Box, { height: size.height, width: size.width, children });
22
+ }
23
+
24
+ // src/lib/render.tsx
25
+ import { jsx as jsx2 } from "react/jsx-runtime";
26
+ var ENTER_ALT_BUFFER = "\x1B[?1049h";
27
+ var EXIT_ALT_BUFFER = "\x1B[?1049l";
28
+ var CLEAR_SCREEN = "\x1B[2J\x1B[H";
29
+ function render(node, options) {
30
+ process.stdout.write(ENTER_ALT_BUFFER + CLEAR_SCREEN);
31
+ const element = /* @__PURE__ */ jsx2(Screen, { children: node });
32
+ const instance = inkRender(element, options);
33
+ setImmediate(() => instance.rerender(element));
34
+ const cleanup = () => process.stdout.write(EXIT_ALT_BUFFER);
35
+ const originalWaitUntilExit = instance.waitUntilExit.bind(instance);
36
+ instance.waitUntilExit = async () => {
37
+ await originalWaitUntilExit();
38
+ cleanup();
39
+ };
40
+ process.on("exit", cleanup);
41
+ const handleSignal = () => {
42
+ cleanup();
43
+ instance.unmount();
44
+ process.exit(0);
45
+ };
46
+ process.on("SIGINT", handleSignal);
47
+ process.on("SIGTERM", handleSignal);
48
+ return instance;
49
+ }
50
+ export {
51
+ render
52
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zion",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",