@gjsify/terminal-native 0.4.0 → 0.4.4
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
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
"name": "@gjsify/terminal-native",
|
|
3
|
+
"version": "0.4.4",
|
|
4
|
+
"description": "Optional Vala/GObject bridge providing Posix.isatty(), ioctl(TIOCGWINSZ), termios raw-mode and SIGWINCH for GJS. Enhances @gjsify/tty and @gjsify/process with correct terminal behaviour when installed.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/esm/index.js",
|
|
7
|
+
"module": "lib/esm/index.js",
|
|
8
|
+
"types": "lib/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./lib/types/index.d.ts",
|
|
12
|
+
"default": "./lib/esm/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"lib",
|
|
17
|
+
"prebuilds",
|
|
18
|
+
"meson.build",
|
|
19
|
+
"src/vala"
|
|
20
|
+
],
|
|
21
|
+
"gjsify": {
|
|
22
|
+
"prebuilds": "prebuilds"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"gjs",
|
|
26
|
+
"terminal",
|
|
27
|
+
"tty",
|
|
28
|
+
"isatty",
|
|
29
|
+
"ioctl",
|
|
30
|
+
"termios",
|
|
31
|
+
"raw-mode",
|
|
32
|
+
"sigwinch",
|
|
33
|
+
"vala",
|
|
34
|
+
"native"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"clear": "rm -rf lib build tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo || exit 0",
|
|
38
|
+
"check": "tsc --noEmit",
|
|
39
|
+
"build": "gjsify run build:gjsify && gjsify run build:types",
|
|
40
|
+
"build:gjsify": "gjsify build --library 'src/ts/**/*.{ts,js}'",
|
|
41
|
+
"build:types": "tsc",
|
|
42
|
+
"init:meson": "meson setup build .",
|
|
43
|
+
"init:meson:wipe": "gjsify run init:meson --wipe",
|
|
44
|
+
"build:meson": "gjsify run init:meson && meson compile -C build",
|
|
45
|
+
"build:prebuilds": "gjsify run build:meson && mkdir -p prebuilds/linux-x86_64 && cp build/libgjsifyterminal.so build/GjsifyTerminal-1.0.gir build/GjsifyTerminal-1.0.typelib prebuilds/linux-x86_64/",
|
|
46
|
+
"build:gir-types": "ts-for-gir generate --externalDeps --allowMissingDeps --girDirectories=./prebuilds/linux-x86_64 --girDirectories=/usr/share/gir-1.0 --modules=GjsifyTerminal-1.0 --outdir=src/ts --npmScope=@girs --package=false --ignoreVersionConflicts=true"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@girs/glib-2.0": "2.88.0-4.0.0-rc.15",
|
|
50
|
+
"@girs/gobject-2.0": "2.88.0-4.0.0-rc.15"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@gjsify/cli": "^0.4.4",
|
|
54
|
+
"@ts-for-gir/cli": "^4.0.0-rc.15",
|
|
55
|
+
"@types/node": "^25.6.2",
|
|
56
|
+
"typescript": "^6.0.3"
|
|
13
57
|
}
|
|
14
|
-
|
|
15
|
-
"files": [
|
|
16
|
-
"lib",
|
|
17
|
-
"prebuilds",
|
|
18
|
-
"meson.build",
|
|
19
|
-
"src/vala"
|
|
20
|
-
],
|
|
21
|
-
"gjsify": {
|
|
22
|
-
"prebuilds": "prebuilds"
|
|
23
|
-
},
|
|
24
|
-
"keywords": [
|
|
25
|
-
"gjs",
|
|
26
|
-
"terminal",
|
|
27
|
-
"tty",
|
|
28
|
-
"isatty",
|
|
29
|
-
"ioctl",
|
|
30
|
-
"termios",
|
|
31
|
-
"raw-mode",
|
|
32
|
-
"sigwinch",
|
|
33
|
-
"vala",
|
|
34
|
-
"native"
|
|
35
|
-
],
|
|
36
|
-
"scripts": {
|
|
37
|
-
"clear": "rm -rf lib build tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo || exit 0",
|
|
38
|
-
"check": "tsc --noEmit",
|
|
39
|
-
"build": "yarn build:gjsify && yarn build:types",
|
|
40
|
-
"build:gjsify": "gjsify build --library 'src/ts/**/*.{ts,js}'",
|
|
41
|
-
"build:types": "tsc",
|
|
42
|
-
"init:meson": "meson setup build .",
|
|
43
|
-
"init:meson:wipe": "yarn init:meson --wipe",
|
|
44
|
-
"build:meson": "yarn init:meson && meson compile -C build",
|
|
45
|
-
"build:prebuilds": "yarn build:meson && mkdir -p prebuilds/linux-x86_64 && cp build/libgjsifyterminal.so build/GjsifyTerminal-1.0.gir build/GjsifyTerminal-1.0.typelib prebuilds/linux-x86_64/",
|
|
46
|
-
"build:gir-types": "ts-for-gir generate --externalDeps --allowMissingDeps --girDirectories=./prebuilds/linux-x86_64 --girDirectories=/usr/share/gir-1.0 --modules=GjsifyTerminal-1.0 --outdir=src/ts --npmScope=@girs --package=false --ignoreVersionConflicts=true"
|
|
47
|
-
},
|
|
48
|
-
"dependencies": {
|
|
49
|
-
"@girs/glib-2.0": "2.88.0-4.0.0-rc.15",
|
|
50
|
-
"@girs/gobject-2.0": "2.88.0-4.0.0-rc.15"
|
|
51
|
-
},
|
|
52
|
-
"devDependencies": {
|
|
53
|
-
"@gjsify/cli": "^0.4.0",
|
|
54
|
-
"@ts-for-gir/cli": "^4.0.0-rc.15",
|
|
55
|
-
"@types/node": "^25.6.2",
|
|
56
|
-
"typescript": "^6.0.3"
|
|
57
|
-
}
|
|
58
|
-
}
|
|
58
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* GjsifyTerminal — Linux terminal primitives for GJS.
|
|
3
|
+
*
|
|
4
|
+
* Exposes Posix/Linux syscalls that have no GLib equivalent:
|
|
5
|
+
* • Posix.isatty() — reliable TTY detection
|
|
6
|
+
* • ioctl(TIOCGWINSZ) — actual terminal dimensions
|
|
7
|
+
* • termios raw mode — keypress-level input for interactive prompts
|
|
8
|
+
* • SIGWINCH watcher — notify on terminal resize (GLib.Unix.signal_add)
|
|
9
|
+
*
|
|
10
|
+
* No dependencies beyond glib-2.0 / gobject-2.0.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
using GLib;
|
|
14
|
+
|
|
15
|
+
namespace GjsifyTerminal {
|
|
16
|
+
|
|
17
|
+
// Specific ioctl binding for TIOCGWINSZ — avoids variadic ambiguity.
|
|
18
|
+
[CCode (cname = "ioctl", cheader_filename = "sys/ioctl.h,termios.h")]
|
|
19
|
+
private static extern int _ioctl_winsize (int fd, ulong request, ref Linux.winsize ws);
|
|
20
|
+
|
|
21
|
+
// Explicit tcgetattr / tcsetattr with ref to match C pointer semantics.
|
|
22
|
+
[CCode (cname = "tcgetattr", cheader_filename = "termios.h")]
|
|
23
|
+
private static extern int _tcgetattr (int fd, ref Posix.termios t);
|
|
24
|
+
|
|
25
|
+
[CCode (cname = "tcsetattr", cheader_filename = "termios.h")]
|
|
26
|
+
private static extern int _tcsetattr (int fd, int action, ref Posix.termios t);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Terminal — static helpers wrapping Posix / Linux ioctl syscalls.
|
|
30
|
+
*/
|
|
31
|
+
public class Terminal : GLib.Object {
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* is_tty:
|
|
35
|
+
* @fd: file descriptor to test (0=stdin, 1=stdout, 2=stderr)
|
|
36
|
+
*
|
|
37
|
+
* Returns %TRUE if @fd refers to an interactive terminal.
|
|
38
|
+
* Uses Posix.isatty() — more accurate than GLib.log_writer_supports_color().
|
|
39
|
+
*/
|
|
40
|
+
public static bool is_tty (int fd) {
|
|
41
|
+
return Posix.isatty (fd);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* get_size:
|
|
46
|
+
* @fd: file descriptor (use 1 for stdout)
|
|
47
|
+
* @rows: (out) terminal height in character rows
|
|
48
|
+
* @cols: (out) terminal width in character columns
|
|
49
|
+
* @xpixel: (out) terminal width in pixels (0 on most terminals)
|
|
50
|
+
* @ypixel: (out) terminal height in pixels (0 on most terminals)
|
|
51
|
+
*
|
|
52
|
+
* Queries terminal dimensions via ioctl(TIOCGWINSZ).
|
|
53
|
+
* Returns %TRUE on success. All out-params are 0 on failure.
|
|
54
|
+
*/
|
|
55
|
+
public static bool get_size (int fd, out int rows, out int cols,
|
|
56
|
+
out int xpixel, out int ypixel) {
|
|
57
|
+
rows = 0; cols = 0; xpixel = 0; ypixel = 0;
|
|
58
|
+
var ws = Linux.winsize ();
|
|
59
|
+
if (_ioctl_winsize (fd, Linux.Termios.TIOCGWINSZ, ref ws) != 0) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
rows = (int) ws.ws_row;
|
|
63
|
+
cols = (int) ws.ws_col;
|
|
64
|
+
xpixel = (int) ws.ws_xpixel;
|
|
65
|
+
ypixel = (int) ws.ws_ypixel;
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* set_raw_mode:
|
|
71
|
+
* @fd: file descriptor (typically stdin = 0)
|
|
72
|
+
* @enable: %TRUE to enter raw mode, %FALSE to restore canonical mode
|
|
73
|
+
*
|
|
74
|
+
* Toggles terminal raw mode so interactive prompts can read
|
|
75
|
+
* individual keystrokes without line-buffering or echo.
|
|
76
|
+
* Returns %TRUE on success.
|
|
77
|
+
*/
|
|
78
|
+
public static bool set_raw_mode (int fd, bool enable) {
|
|
79
|
+
var t = Posix.termios ();
|
|
80
|
+
if (_tcgetattr (fd, ref t) != 0) return false;
|
|
81
|
+
if (enable) {
|
|
82
|
+
t.c_lflag &= ~(Posix.ICANON | Posix.ECHO);
|
|
83
|
+
t.c_iflag &= ~Posix.ICRNL;
|
|
84
|
+
t.c_cc[Posix.VMIN] = 1;
|
|
85
|
+
t.c_cc[Posix.VTIME] = 0;
|
|
86
|
+
} else {
|
|
87
|
+
t.c_lflag |= (Posix.ICANON | Posix.ECHO);
|
|
88
|
+
t.c_iflag |= Posix.ICRNL;
|
|
89
|
+
}
|
|
90
|
+
return _tcsetattr (fd, Posix.TCSAFLUSH, ref t) == 0;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* ResizeWatcher — fires #GjsifyTerminal.ResizeWatcher::resized whenever
|
|
96
|
+
* the terminal window is resized (SIGWINCH).
|
|
97
|
+
*
|
|
98
|
+
* Call start() once; the watcher stays active for the process lifetime.
|
|
99
|
+
* The signal is dispatched on the GLib main context via GLib.Idle so
|
|
100
|
+
* JavaScript signal handlers run on the main thread.
|
|
101
|
+
*/
|
|
102
|
+
public class ResizeWatcher : GLib.Object {
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* resized:
|
|
106
|
+
* @rows: new terminal height in character rows
|
|
107
|
+
* @cols: new terminal width in character columns
|
|
108
|
+
*/
|
|
109
|
+
public signal void resized (int rows, int cols);
|
|
110
|
+
|
|
111
|
+
private bool _active = false;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* start:
|
|
115
|
+
*
|
|
116
|
+
* Begin watching SIGWINCH. Idempotent — safe to call multiple times.
|
|
117
|
+
*/
|
|
118
|
+
public void start () {
|
|
119
|
+
if (_active) return;
|
|
120
|
+
_active = true;
|
|
121
|
+
|
|
122
|
+
GLib.Unix.signal_add (Posix.Signal.WINCH, () => {
|
|
123
|
+
int r = 0, c = 0, xp = 0, yp = 0;
|
|
124
|
+
if (Terminal.get_size (1, out r, out c, out xp, out yp)) {
|
|
125
|
+
int rows_snap = r;
|
|
126
|
+
int cols_snap = c;
|
|
127
|
+
GLib.Idle.add (() => {
|
|
128
|
+
this.resized (rows_snap, cols_snap);
|
|
129
|
+
return GLib.Source.REMOVE;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return GLib.Source.CONTINUE;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|