@linxiraos/pi-tui 1.0.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/CHANGELOG.md +2219 -0
- package/README.md +705 -0
- package/dist/types/autocomplete.d.ts +116 -0
- package/dist/types/bracketed-paste.d.ts +51 -0
- package/dist/types/components/box.d.ts +31 -0
- package/dist/types/components/cancellable-loader.d.ts +21 -0
- package/dist/types/components/editor.d.ts +162 -0
- package/dist/types/components/image.d.ts +112 -0
- package/dist/types/components/input.d.ts +25 -0
- package/dist/types/components/loader.d.ts +25 -0
- package/dist/types/components/markdown.d.ts +88 -0
- package/dist/types/components/scroll-view.d.ts +62 -0
- package/dist/types/components/select-list.d.ts +69 -0
- package/dist/types/components/settings-list.d.ts +123 -0
- package/dist/types/components/spacer.d.ts +11 -0
- package/dist/types/components/tab-bar.d.ts +89 -0
- package/dist/types/components/text.d.ts +27 -0
- package/dist/types/components/truncated-text.d.ts +10 -0
- package/dist/types/deccara.d.ts +49 -0
- package/dist/types/desktop-notify.d.ts +52 -0
- package/dist/types/editor-component.d.ts +38 -0
- package/dist/types/fuzzy.d.ts +48 -0
- package/dist/types/index.d.ts +32 -0
- package/dist/types/keybindings.d.ts +197 -0
- package/dist/types/keys.d.ts +210 -0
- package/dist/types/kill-ring.d.ts +20 -0
- package/dist/types/kitty-graphics.d.ts +76 -0
- package/dist/types/latex-block.d.ts +8 -0
- package/dist/types/latex-to-unicode.d.ts +50 -0
- package/dist/types/loop-watchdog.d.ts +44 -0
- package/dist/types/mouse.d.ts +67 -0
- package/dist/types/stdin-buffer.d.ts +60 -0
- package/dist/types/symbols.d.ts +25 -0
- package/dist/types/terminal-capabilities.d.ts +285 -0
- package/dist/types/terminal.d.ts +175 -0
- package/dist/types/tmux.d.ts +6 -0
- package/dist/types/ttyid.d.ts +9 -0
- package/dist/types/tui.d.ts +457 -0
- package/dist/types/utils.d.ts +100 -0
- package/package.json +70 -0
- package/src/autocomplete.ts +1079 -0
- package/src/bracketed-paste.ts +123 -0
- package/src/components/box.ts +236 -0
- package/src/components/cancellable-loader.ts +40 -0
- package/src/components/editor.ts +3301 -0
- package/src/components/image.ts +460 -0
- package/src/components/input.ts +482 -0
- package/src/components/loader.ts +174 -0
- package/src/components/markdown.ts +3119 -0
- package/src/components/scroll-view.ts +227 -0
- package/src/components/select-list.ts +539 -0
- package/src/components/settings-list.ts +793 -0
- package/src/components/spacer.ts +32 -0
- package/src/components/tab-bar.ts +300 -0
- package/src/components/text.ts +173 -0
- package/src/components/truncated-text.ts +69 -0
- package/src/deccara.ts +314 -0
- package/src/desktop-notify.ts +192 -0
- package/src/editor-component.ts +74 -0
- package/src/fuzzy.ts +384 -0
- package/src/index.ts +51 -0
- package/src/keybindings.ts +346 -0
- package/src/keys.ts +566 -0
- package/src/kill-ring.ts +51 -0
- package/src/kitty-graphics.ts +171 -0
- package/src/latex-block.ts +1338 -0
- package/src/latex-to-unicode.ts +2017 -0
- package/src/loop-watchdog.ts +115 -0
- package/src/mouse.ts +105 -0
- package/src/stdin-buffer.ts +781 -0
- package/src/symbols.ts +26 -0
- package/src/terminal-capabilities.ts +1211 -0
- package/src/terminal.ts +1854 -0
- package/src/tmux.ts +14 -0
- package/src/ttyid.ts +84 -0
- package/src/tui.ts +4275 -0
- package/src/utils.ts +619 -0
package/src/tmux.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Whether the process is running inside a tmux session. */
|
|
2
|
+
export function isInsideTmux(env: NodeJS.ProcessEnv = Bun.env): boolean {
|
|
3
|
+
return Boolean(env.TMUX);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/** Wrap a control sequence in tmux's DCS passthrough envelope. */
|
|
7
|
+
export function wrapTmuxPassthrough(payload: string): string {
|
|
8
|
+
return `\x1bPtmux;${payload.replaceAll("\x1b", "\x1b\x1b")}\x1b\\`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Pass a control sequence through tmux, leaving direct-terminal output unchanged. */
|
|
12
|
+
export function wrapTmuxPassthroughIfNeeded(payload: string, env: NodeJS.ProcessEnv = Bun.env): string {
|
|
13
|
+
return isInsideTmux(env) ? wrapTmuxPassthrough(payload) : payload;
|
|
14
|
+
}
|
package/src/ttyid.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
// TTY device path — most reliable, unique per terminal tab
|
|
43
|
+
if (process.stdin.isTTY) {
|
|
44
|
+
try {
|
|
45
|
+
const ttyPath = getTtyPath();
|
|
46
|
+
if (ttyPath?.startsWith("/dev/")) {
|
|
47
|
+
return ttyPath.slice(5).replace(/\//g, "-"); // /dev/pts/3 -> pts-3
|
|
48
|
+
}
|
|
49
|
+
} catch {}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Fallback to terminal-specific env vars
|
|
53
|
+
// Prefer inner multiplexers over host terminal emulators when stdin has no TTY path.
|
|
54
|
+
const zellijPane = process.env.ZELLIJ_PANE_ID;
|
|
55
|
+
if (zellijPane) {
|
|
56
|
+
// Session names are user-chosen (`zellij -s …`) and the id is used as a
|
|
57
|
+
// breadcrumb filename — normalize path separators like the TTY branch does.
|
|
58
|
+
const zellijSession = process.env.ZELLIJ_SESSION_NAME?.replace(/[\\/]/g, "-");
|
|
59
|
+
return zellijSession ? `zellij-${zellijSession}-${zellijPane}` : `zellij-${zellijPane}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const tmuxPane = process.env.TMUX_PANE;
|
|
63
|
+
if (tmuxPane) return `tmux-${tmuxPane}`;
|
|
64
|
+
|
|
65
|
+
const cmuxSurface = process.env.CMUX_SURFACE_ID;
|
|
66
|
+
if (cmuxSurface) return `cmux-${cmuxSurface}`;
|
|
67
|
+
|
|
68
|
+
// Kitty before WezTerm/others, matching terminal-capabilities.ts detection
|
|
69
|
+
// order. Inherited env makes either order wrong for some nesting; staying
|
|
70
|
+
// consistent with the capability detector keeps the two answers aligned.
|
|
71
|
+
const kittyId = process.env.KITTY_WINDOW_ID;
|
|
72
|
+
if (kittyId) return `kitty-${kittyId}`;
|
|
73
|
+
|
|
74
|
+
const weztermPane = process.env.WEZTERM_PANE;
|
|
75
|
+
if (weztermPane) return `wezterm-${weztermPane}`;
|
|
76
|
+
|
|
77
|
+
const terminalSessionId = process.env.TERM_SESSION_ID; // macOS Terminal.app
|
|
78
|
+
if (terminalSessionId) return `apple-${terminalSessionId}`;
|
|
79
|
+
|
|
80
|
+
const wtSession = process.env.WT_SESSION; // Windows Terminal
|
|
81
|
+
if (wtSession) return `wt-${wtSession}`;
|
|
82
|
+
|
|
83
|
+
return null;
|
|
84
|
+
}
|