@sayknow-cli/tui 0.2.2

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 (61) hide show
  1. package/CHANGELOG.md +903 -0
  2. package/README.md +704 -0
  3. package/dist/types/autocomplete.d.ts +82 -0
  4. package/dist/types/bracketed-paste.d.ts +26 -0
  5. package/dist/types/components/box.d.ts +20 -0
  6. package/dist/types/components/cancellable-loader.d.ts +21 -0
  7. package/dist/types/components/editor.d.ts +111 -0
  8. package/dist/types/components/image.d.ts +16 -0
  9. package/dist/types/components/input.d.ts +16 -0
  10. package/dist/types/components/loader.d.ts +14 -0
  11. package/dist/types/components/markdown.d.ts +64 -0
  12. package/dist/types/components/select-list.d.ts +46 -0
  13. package/dist/types/components/settings-list.d.ts +39 -0
  14. package/dist/types/components/spacer.d.ts +11 -0
  15. package/dist/types/components/tab-bar.d.ts +56 -0
  16. package/dist/types/components/text.d.ts +13 -0
  17. package/dist/types/components/truncated-text.d.ts +10 -0
  18. package/dist/types/editor-component.d.ts +36 -0
  19. package/dist/types/fuzzy.d.ts +15 -0
  20. package/dist/types/index.d.ts +26 -0
  21. package/dist/types/keybindings.d.ts +189 -0
  22. package/dist/types/keys.d.ts +208 -0
  23. package/dist/types/kill-ring.d.ts +27 -0
  24. package/dist/types/metrics.d.ts +85 -0
  25. package/dist/types/stdin-buffer.d.ts +50 -0
  26. package/dist/types/symbols.d.ts +23 -0
  27. package/dist/types/terminal-capabilities.d.ts +75 -0
  28. package/dist/types/terminal.d.ts +76 -0
  29. package/dist/types/ttyid.d.ts +9 -0
  30. package/dist/types/tui.d.ts +181 -0
  31. package/dist/types/utils.d.ts +75 -0
  32. package/package.json +74 -0
  33. package/src/autocomplete.ts +896 -0
  34. package/src/bracketed-paste.ts +47 -0
  35. package/src/components/box.ts +173 -0
  36. package/src/components/cancellable-loader.ts +40 -0
  37. package/src/components/editor.ts +2820 -0
  38. package/src/components/image.ts +90 -0
  39. package/src/components/input.ts +465 -0
  40. package/src/components/loader.ts +103 -0
  41. package/src/components/markdown.ts +1061 -0
  42. package/src/components/select-list.ts +249 -0
  43. package/src/components/settings-list.ts +211 -0
  44. package/src/components/spacer.ts +28 -0
  45. package/src/components/tab-bar.ts +175 -0
  46. package/src/components/text.ts +110 -0
  47. package/src/components/truncated-text.ts +61 -0
  48. package/src/editor-component.ts +71 -0
  49. package/src/fuzzy.ts +143 -0
  50. package/src/index.ts +41 -0
  51. package/src/keybindings.ts +279 -0
  52. package/src/keys.ts +537 -0
  53. package/src/kill-ring.ts +46 -0
  54. package/src/metrics.ts +382 -0
  55. package/src/stdin-buffer.ts +444 -0
  56. package/src/symbols.ts +24 -0
  57. package/src/terminal-capabilities.ts +537 -0
  58. package/src/terminal.ts +807 -0
  59. package/src/ttyid.ts +73 -0
  60. package/src/tui.ts +1765 -0
  61. package/src/utils.ts +389 -0
package/src/ttyid.ts ADDED
@@ -0,0 +1,73 @@
1
+ import { CString, dlopen, FFIType } from "bun:ffi";
2
+ import * as fs from "node:fs";
3
+ import * as os from "node:os";
4
+
5
+ /** Resolve the TTY device path for stdin (fd 0) via POSIX `ttyname(3)`. */
6
+ export function getTtyPath(): string | null {
7
+ if (os.platform() === "linux") {
8
+ // Linux: /proc/self/fd/0 is a symlink to /dev/pts/N
9
+ try {
10
+ const ttyPath = fs.readlinkSync("/proc/self/fd/0");
11
+ if (ttyPath.startsWith("/dev/")) {
12
+ return ttyPath;
13
+ }
14
+ } catch {
15
+ return null;
16
+ }
17
+ } else if (os.platform() !== "win32") {
18
+ try {
19
+ const libName = os.platform() === "darwin" ? "libSystem.B.dylib" : "libc.so.6";
20
+ const lib = dlopen(libName, {
21
+ ttyname: { args: [FFIType.i32], returns: FFIType.ptr },
22
+ });
23
+ try {
24
+ const result = lib.symbols.ttyname(0);
25
+ return result ? new CString(result).toString() : null;
26
+ } finally {
27
+ lib.close();
28
+ }
29
+ } catch {
30
+ return null;
31
+ }
32
+ }
33
+ return null;
34
+ }
35
+ /**
36
+ * Get a stable identifier for the current terminal.
37
+ * Uses the TTY device path (e.g., /dev/pts/3), falling back to environment
38
+ * variables for terminal multiplexers or terminal emulators.
39
+ * Returns null if no terminal can be identified (e.g., piped input).
40
+ */
41
+ export function getTerminalId(): string | null {
42
+ // Inside tmux the stdin TTY path is unstable (it tracks the attached
43
+ // client, not the pane), which spawns duplicate sessions and breaks
44
+ // /resume. Prefer the stable per-pane TMUX_PANE identifier instead.
45
+ if (process.env.TMUX && process.env.TMUX_PANE) {
46
+ return `tmux-${process.env.TMUX_PANE}`;
47
+ }
48
+
49
+ // TTY device path — most reliable, unique per terminal tab
50
+ if (process.stdin.isTTY) {
51
+ try {
52
+ const ttyPath = getTtyPath();
53
+ if (ttyPath?.startsWith("/dev/")) {
54
+ return ttyPath.slice(5).replace(/\//g, "-"); // /dev/pts/3 -> pts-3
55
+ }
56
+ } catch {}
57
+ }
58
+
59
+ // Fallback to terminal-specific env vars
60
+ const kittyId = process.env.KITTY_WINDOW_ID;
61
+ if (kittyId) return `kitty-${kittyId}`;
62
+
63
+ const tmuxPane = process.env.TMUX_PANE;
64
+ if (tmuxPane) return `tmux-${tmuxPane}`;
65
+
66
+ const terminalSessionId = process.env.TERM_SESSION_ID; // macOS Terminal.app
67
+ if (terminalSessionId) return `apple-${terminalSessionId}`;
68
+
69
+ const wtSession = process.env.WT_SESSION; // Windows Terminal
70
+ if (wtSession) return `wt-${wtSession}`;
71
+
72
+ return null;
73
+ }