shellwise 0.1.9 → 0.2.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/package.json +1 -1
- package/src/cli/search.ts +2 -0
- package/src/tui/renderer.ts +25 -5
package/package.json
CHANGED
package/src/cli/search.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
showCursor,
|
|
10
10
|
getTerminalSize,
|
|
11
11
|
clearDown,
|
|
12
|
+
closeTty,
|
|
12
13
|
} from "../tui/renderer";
|
|
13
14
|
import { renderSearchBox, getSearchBoxCursorCol } from "../tui/components/search-box";
|
|
14
15
|
import { renderResultList } from "../tui/components/result-list";
|
|
@@ -51,6 +52,7 @@ export async function runSearch(initialQuery: string = ""): Promise<void> {
|
|
|
51
52
|
write(showCursor());
|
|
52
53
|
write(moveCursorToColumn(1));
|
|
53
54
|
disableRawMode();
|
|
55
|
+
closeTty();
|
|
54
56
|
};
|
|
55
57
|
|
|
56
58
|
// Handle unexpected exit
|
package/src/tui/renderer.ts
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
|
+
import { openSync, writeSync, closeSync } from "fs";
|
|
2
|
+
|
|
1
3
|
const ESC = "\x1b[";
|
|
2
4
|
|
|
5
|
+
// Open /dev/tty directly — avoids Bun bug where process.stderr is
|
|
6
|
+
// undefined when fd 2 is redirected to /dev/tty via shell integration
|
|
7
|
+
let ttyFd: number | null = null;
|
|
8
|
+
|
|
9
|
+
function getTtyFd(): number {
|
|
10
|
+
if (ttyFd === null) {
|
|
11
|
+
ttyFd = openSync("/dev/tty", "w");
|
|
12
|
+
}
|
|
13
|
+
return ttyFd;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function closeTty(): void {
|
|
17
|
+
if (ttyFd !== null) {
|
|
18
|
+
try { closeSync(ttyFd); } catch {}
|
|
19
|
+
ttyFd = null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
3
23
|
export function moveCursorUp(n: number): string {
|
|
4
24
|
return n > 0 ? `${ESC}${n}A` : "";
|
|
5
25
|
}
|
|
@@ -29,14 +49,14 @@ export function showCursor(): string {
|
|
|
29
49
|
}
|
|
30
50
|
|
|
31
51
|
export function getTerminalSize(): { rows: number; cols: number } {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
52
|
+
// process.stdout may not be a TTY when running inside $() capture
|
|
53
|
+
const rows = process.stdout?.rows || process.stderr?.rows || 24;
|
|
54
|
+
const cols = process.stdout?.columns || process.stderr?.columns || 80;
|
|
55
|
+
return { rows, cols };
|
|
36
56
|
}
|
|
37
57
|
|
|
38
58
|
export function write(text: string): void {
|
|
39
|
-
|
|
59
|
+
writeSync(getTtyFd(), text);
|
|
40
60
|
}
|
|
41
61
|
|
|
42
62
|
export function truncate(text: string, maxWidth: number): string {
|