typenative 0.4.0 → 0.5.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/.github/workflows/ci.yml +2 -0
- package/CHANGELOG.md +372 -0
- package/CONTRIBUTION.md +1 -1
- package/README.md +62 -22
- package/ROUND2-HANDOFF.md +200 -0
- package/bin/cli.js +2 -0
- package/bin/go/bridge.js +74 -14
- package/bin/go/convert.js +48 -0
- package/bin/go/metadata.js +13 -4
- package/bin/go/overrides.js +4 -6
- package/bin/go/stdlib.generated.js +2 -0
- package/bin/index.js +130 -2
- package/bin/main.js +2 -0
- package/bin/node/assert.js +2 -2
- package/bin/node/async_hooks.js +1 -1
- package/bin/node/buffer.js +16 -5
- package/bin/node/child_process.js +57 -9
- package/bin/node/cluster.js +44 -6
- package/bin/node/core.js +1 -1
- package/bin/node/crypto.js +205 -4
- package/bin/node/crypto_keys.js +21 -21
- package/bin/node/dgram.js +231 -7
- package/bin/node/diagnostics_channel.js +3 -3
- package/bin/node/dns.js +472 -9
- package/bin/node/errno_tables.js +445 -0
- package/bin/node/events.js +3 -3
- package/bin/node/fetch.js +2 -2
- package/bin/node/fs.js +24 -17
- package/bin/node/fs_watch.js +5 -5
- package/bin/node/http.js +131 -33
- package/bin/node/http2.js +7 -4
- package/bin/node/module_v8.js +142 -0
- package/bin/node/net.js +17 -14
- package/bin/node/path.js +17 -3
- package/bin/node/process.js +274 -9
- package/bin/node/readline.js +272 -1
- package/bin/node/registry.js +5 -1
- package/bin/node/sqlite.js +65 -17
- package/bin/node/stream.js +220 -22
- package/bin/node/stream_web.js +10 -10
- package/bin/node/system_extra.js +3 -3
- package/bin/node/test.js +834 -234
- package/bin/node/test_coverage.js +187 -0
- package/bin/node/test_report.js +1392 -0
- package/bin/node/test_run.js +575 -0
- package/bin/node/timers.js +4 -4
- package/bin/node/tls.js +5 -5
- package/bin/node/url.js +23 -5
- package/bin/node/util.js +49 -8
- package/bin/node/util_extra.js +13 -37
- package/bin/node/webview.js +654 -0
- package/bin/node/worker_threads.js +80 -20
- package/bin/node/zlib.js +3 -3
- package/bin/parse-node.js +4 -0
- package/bin/transpiler.js +14457 -1723
- package/bin/typecheck-node.js +1 -0
- package/bin/version.js +1 -1
- package/conformance.md +1153 -884
- package/examples/README.md +47 -10
- package/examples/desktop-notes/README.md +108 -0
- package/examples/desktop-notes/bench.mjs +125 -0
- package/examples/desktop-notes/main.ts +131 -0
- package/examples/desktop-notes/package-lock.json +726 -0
- package/examples/desktop-notes/package.json +9 -0
- package/examples/desktop-notes/ui.ts +176 -0
- package/examples/dupe-finder/README.md +76 -0
- package/examples/dupe-finder/bench.mjs +120 -0
- package/examples/dupe-finder/main.ts +87 -0
- package/examples/json-server/README.md +31 -29
- package/examples/json-server/bench.mjs +130 -38
- package/examples/mandelbrot-png/README.md +65 -0
- package/examples/mandelbrot-png/bench.mjs +95 -0
- package/examples/mandelbrot-png/main.ts +98 -0
- package/examples/mandelbrot-png/preview.png +0 -0
- package/examples/marked-cli/README.md +159 -0
- package/examples/marked-cli/bench.mjs +178 -0
- package/examples/marked-cli/main.ts +292 -0
- package/examples/marked-cli/parity.mjs +185 -0
- package/examples/marked-cli/vendor/marked/LICENSE +44 -0
- package/examples/marked-cli/vendor/marked/VENDOR.md +26 -0
- package/examples/todo-cli/README.md +69 -0
- package/examples/todo-cli/bench.mjs +89 -0
- package/examples/todo-cli/main.ts +92 -0
- package/examples/yaml-cli/README.md +136 -0
- package/examples/yaml-cli/bench.mjs +265 -0
- package/examples/yaml-cli/main.ts +29 -0
- package/examples/yaml-cli/parity.mjs +156 -0
- package/examples/yaml-cli/vendor/yaml/LICENSE +13 -0
- package/examples/yaml-cli/vendor/yaml/VENDOR.md +25 -0
- package/govendor/github.com/jchv/go-webview2/LICENSE +22 -0
- package/govendor/github.com/jchv/go-webview2/README.md +21 -0
- package/govendor/github.com/jchv/go-webview2/common.go +84 -0
- package/govendor/github.com/jchv/go-webview2/go.mod +3 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32.go +194 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32_386.go +14 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32_64bit.go +15 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_COLOR.go +8 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND.go +9 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_KEY_EVENT_KIND.go +10 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_MOVE_FOCUS_REASON.go +9 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_PHYSICAL_KEY_STATUS.go +10 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_WEB_RESOURCE_CONTEXT.go +23 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventArgs.go +78 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventHandler.go +52 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller.go +132 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller2.go +74 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2CreateCoreWebView2ControllerCompletedHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventArgs.go +17 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Settings.go +270 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequest.go +43 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventArgs.go +51 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceResponse.go +21 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_2.go +21 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_3.go +60 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebViewSettings.go +396 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium.go +361 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_386.go +24 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_amd64.go +22 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_arm64.go +26 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc.go +13 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go17.go +51 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go18.go +16 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/corewebview2.go +411 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/guid.go +223 -0
- package/govendor/github.com/jchv/go-webview2/webview.go +482 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/README.md +3 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module.go +153 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_386.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_amd64.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_arm64.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/arm64/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x64/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x86/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-winloader/LICENSE.md +7 -0
- package/govendor/github.com/jchv/go-winloader/README.md +124 -0
- package/govendor/github.com/jchv/go-winloader/common.go +11 -0
- package/govendor/github.com/jchv/go-winloader/go.mod +3 -0
- package/govendor/github.com/jchv/go-winloader/internal/loader/loader.go +25 -0
- package/govendor/github.com/jchv/go-winloader/internal/loader/machine.go +53 -0
- package/govendor/github.com/jchv/go-winloader/internal/memloader/cache.go +42 -0
- package/govendor/github.com/jchv/go-winloader/internal/memloader/loader.go +253 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/export.go +76 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/format.go +522 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/import.go +106 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/module.go +91 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/reloc.go +177 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/util.go +40 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/common.go +55 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_other.go +71 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_windows.go +179 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_other.go +17 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_windows.go +73 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/loader_windows.go +64 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/machine_windows.go +32 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_386.go +9 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_amd64.go +9 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_arm64.go +9 -0
- package/govendor/github.com/jchv/go-winloader/loader_other.go +24 -0
- package/govendor/github.com/jchv/go-winloader/loader_windows.go +33 -0
- package/govendor/manifest.txt +3 -1
- package/package.json +1 -1
- package/tsparser/main.go +4 -0
- package/types/typenative-go.d.ts +23 -0
- package/types/typenative-npm.d.ts +359 -7
- package/types/typenative.d.ts +283 -42
package/bin/node/process.js
CHANGED
|
@@ -32,9 +32,15 @@ func tnRunBeforeExit(code float64) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
// Set by process.stdin.setRawMode: puts the terminal back as it was, as Node does at exit
|
|
36
|
+
var tnResetStdio func()
|
|
37
|
+
|
|
35
38
|
// The end of main: exit with process.exitCode
|
|
36
39
|
func TnProcessExit() {
|
|
37
40
|
tnRunBeforeExit(tnExitCode)
|
|
41
|
+
if tnResetStdio != nil {
|
|
42
|
+
tnResetStdio()
|
|
43
|
+
}
|
|
38
44
|
if tnExitCode != 0 {
|
|
39
45
|
os.Exit(int(tnExitCode))
|
|
40
46
|
}
|
|
@@ -46,6 +52,9 @@ func TnProcessExitWith(code ...float64) {
|
|
|
46
52
|
tnExitCode = code[0]
|
|
47
53
|
}
|
|
48
54
|
tnRunBeforeExit(tnExitCode)
|
|
55
|
+
if tnResetStdio != nil {
|
|
56
|
+
tnResetStdio()
|
|
57
|
+
}
|
|
49
58
|
os.Exit(int(tnExitCode))
|
|
50
59
|
}
|
|
51
60
|
|
|
@@ -141,14 +150,31 @@ func TnProcessKill(pid float64, signal ...interface{}) bool {
|
|
|
141
150
|
return true
|
|
142
151
|
}
|
|
143
152
|
|
|
144
|
-
|
|
153
|
+
// process.emitWarning(warning, type = 'Warning'); an Error warning's own
|
|
154
|
+
// name is its type
|
|
155
|
+
func TnProcessEmitWarning(warning interface{}, typ string) {
|
|
145
156
|
msg := fmt.Sprint(warning)
|
|
146
157
|
if e, ok := warning.(*TnError); ok {
|
|
147
158
|
msg = e.message
|
|
159
|
+
if typ == "" {
|
|
160
|
+
if name, isString := e.prop("name").(string); isString && name != "" {
|
|
161
|
+
typ = name
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if typ == "" {
|
|
166
|
+
typ = "Warning"
|
|
167
|
+
}
|
|
168
|
+
fmt.Fprintf(os.Stderr, "(node:%d) %s: %s\\n", os.Getpid(), typ, msg)
|
|
169
|
+
// (Node's hint, after the first warning)
|
|
170
|
+
if !tnWarningHinted {
|
|
171
|
+
tnWarningHinted = true
|
|
172
|
+
fmt.Fprintln(os.Stderr, "(Use \`node --trace-warnings ...\` to show where the warning was created)")
|
|
148
173
|
}
|
|
149
|
-
fmt.Fprintf(os.Stderr, "(node:%d) Warning: %s\\n", os.Getpid(), msg)
|
|
150
174
|
}
|
|
151
175
|
|
|
176
|
+
var tnWarningHinted bool
|
|
177
|
+
|
|
152
178
|
func TnProcessVersions() *TnMap[string, string] {
|
|
153
179
|
m := TnNewMap[string, string]()
|
|
154
180
|
m.Set("node", "24.0.0")
|
|
@@ -171,6 +197,197 @@ func TnHasEnv(name string) bool {
|
|
|
171
197
|
_, ok := os.LookupEnv(name)
|
|
172
198
|
return ok
|
|
173
199
|
}`;
|
|
200
|
+
// Terminal size, raw mode and umask: one variant per target OS (nodeTtyOS@os)
|
|
201
|
+
const ttyHelper = `var tnStdinRaw bool
|
|
202
|
+
|
|
203
|
+
// process.stdout.columns / rows: 0 when the stream is not a terminal
|
|
204
|
+
func TnTtyColumns(f *os.File) float64 {
|
|
205
|
+
cols, _, _ := tnTerminalSize(f)
|
|
206
|
+
return float64(cols)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
func TnTtyRows(f *os.File) float64 {
|
|
210
|
+
_, rows, _ := tnTerminalSize(f)
|
|
211
|
+
return float64(rows)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
func TnTtyWindowSize(f *os.File) []float64 {
|
|
215
|
+
cols, rows, _ := tnTerminalSize(f)
|
|
216
|
+
return []float64{float64(cols), float64(rows)}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// process.stdin.setRawMode(mode): libuv's raw mode; throws when stdin is not a terminal
|
|
220
|
+
func TnTtySetRawMode(mode bool) {
|
|
221
|
+
if !tnSetRawMode(os.Stdin, mode) {
|
|
222
|
+
panic(TnNodeError("Error", "EINVAL", "setRawMode EINVAL"))
|
|
223
|
+
}
|
|
224
|
+
tnStdinRaw = mode
|
|
225
|
+
tnResetStdio = func() { tnSetRawMode(os.Stdin, false) }
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// process.umask(mask?): the previous mask (a number or an octal string)
|
|
229
|
+
func TnProcessUmask(mask ...interface{}) float64 {
|
|
230
|
+
if len(mask) == 0 || mask[0] == nil {
|
|
231
|
+
old := tnUmask(0)
|
|
232
|
+
tnUmask(old)
|
|
233
|
+
return float64(old)
|
|
234
|
+
}
|
|
235
|
+
var m int
|
|
236
|
+
switch x := mask[0].(type) {
|
|
237
|
+
case string:
|
|
238
|
+
n, err := strconv.ParseInt(x, 8, 32)
|
|
239
|
+
if err != nil {
|
|
240
|
+
panic(TnNodeError("TypeError", "ERR_INVALID_ARG_VALUE", "The argument 'mask' must be a 32-bit unsigned integer or an octal string. Received '" + x + "'"))
|
|
241
|
+
}
|
|
242
|
+
m = int(n)
|
|
243
|
+
default:
|
|
244
|
+
m = int(TnNumber(x))
|
|
245
|
+
}
|
|
246
|
+
return float64(tnUmask(m & 0o777))
|
|
247
|
+
}`;
|
|
248
|
+
// Linux: the asm-generic termios ioctls and flags (std syscall only has them
|
|
249
|
+
// for some architectures); PowerPC and MIPS number them differently
|
|
250
|
+
const linuxTtyHelper = `type tnWinsize struct {
|
|
251
|
+
Row, Col, X, Y uint16
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
func tnTerminalSize(f *os.File) (int, int, bool) {
|
|
255
|
+
var ws tnWinsize
|
|
256
|
+
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&ws)))
|
|
257
|
+
if errno != 0 || ws.Col == 0 {
|
|
258
|
+
return 0, 0, false
|
|
259
|
+
}
|
|
260
|
+
return int(ws.Col), int(ws.Row), true
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
var tnSavedTermios *syscall.Termios
|
|
264
|
+
|
|
265
|
+
func tnSetRawMode(f *os.File, raw bool) bool {
|
|
266
|
+
if strings.HasPrefix(runtime.GOARCH, "ppc") || strings.HasPrefix(runtime.GOARCH, "mips") {
|
|
267
|
+
return false
|
|
268
|
+
}
|
|
269
|
+
var t syscall.Termios
|
|
270
|
+
if _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), 0x5401, uintptr(unsafe.Pointer(&t))); errno != 0 {
|
|
271
|
+
return false
|
|
272
|
+
}
|
|
273
|
+
if raw {
|
|
274
|
+
if tnSavedTermios == nil {
|
|
275
|
+
saved := t
|
|
276
|
+
tnSavedTermios = &saved
|
|
277
|
+
}
|
|
278
|
+
t.Iflag &^= 0x2 | 0x100 | 0x10 | 0x20 | 0x400
|
|
279
|
+
t.Oflag |= 0x4
|
|
280
|
+
t.Cflag |= 0x30
|
|
281
|
+
t.Lflag &^= 0x8 | 0x2 | 0x8000 | 0x1
|
|
282
|
+
t.Cc[6], t.Cc[5] = 1, 0
|
|
283
|
+
} else if tnSavedTermios != nil {
|
|
284
|
+
t = *tnSavedTermios
|
|
285
|
+
}
|
|
286
|
+
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), 0x5402, uintptr(unsafe.Pointer(&t)))
|
|
287
|
+
return errno == 0
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
func tnUmask(mask int) int {
|
|
291
|
+
return syscall.Umask(mask)
|
|
292
|
+
}`;
|
|
293
|
+
// macOS and FreeBSD: TIOCGETA / TIOCSETA
|
|
294
|
+
const bsdTtyHelper = `type tnWinsize struct {
|
|
295
|
+
Row, Col, X, Y uint16
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
func tnTerminalSize(f *os.File) (int, int, bool) {
|
|
299
|
+
var ws tnWinsize
|
|
300
|
+
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&ws)))
|
|
301
|
+
if errno != 0 || ws.Col == 0 {
|
|
302
|
+
return 0, 0, false
|
|
303
|
+
}
|
|
304
|
+
return int(ws.Col), int(ws.Row), true
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
var tnSavedTermios *syscall.Termios
|
|
308
|
+
|
|
309
|
+
func tnSetRawMode(f *os.File, raw bool) bool {
|
|
310
|
+
var t syscall.Termios
|
|
311
|
+
if _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), uintptr(syscall.TIOCGETA), uintptr(unsafe.Pointer(&t))); errno != 0 {
|
|
312
|
+
return false
|
|
313
|
+
}
|
|
314
|
+
if raw {
|
|
315
|
+
if tnSavedTermios == nil {
|
|
316
|
+
saved := t
|
|
317
|
+
tnSavedTermios = &saved
|
|
318
|
+
}
|
|
319
|
+
t.Iflag &^= syscall.BRKINT | syscall.ICRNL | syscall.INPCK | syscall.ISTRIP | syscall.IXON
|
|
320
|
+
t.Oflag |= syscall.ONLCR
|
|
321
|
+
t.Cflag |= syscall.CS8
|
|
322
|
+
t.Lflag &^= syscall.ECHO | syscall.ICANON | syscall.IEXTEN | syscall.ISIG
|
|
323
|
+
t.Cc[syscall.VMIN], t.Cc[syscall.VTIME] = 1, 0
|
|
324
|
+
} else if tnSavedTermios != nil {
|
|
325
|
+
t = *tnSavedTermios
|
|
326
|
+
}
|
|
327
|
+
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), uintptr(syscall.TIOCSETA), uintptr(unsafe.Pointer(&t)))
|
|
328
|
+
return errno == 0
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
func tnUmask(mask int) int {
|
|
332
|
+
return syscall.Umask(mask)
|
|
333
|
+
}`;
|
|
334
|
+
// Windows: the console API (there is no umask; Node returns 0)
|
|
335
|
+
const windowsTtyHelper = `var (
|
|
336
|
+
tnTtyKernel32 = syscall.NewLazyDLL("kernel32.dll")
|
|
337
|
+
tnGetConsoleScreenBufferInfo = tnTtyKernel32.NewProc("GetConsoleScreenBufferInfo")
|
|
338
|
+
tnSetConsoleMode = tnTtyKernel32.NewProc("SetConsoleMode")
|
|
339
|
+
tnSavedConsoleMode uint32
|
|
340
|
+
tnConsoleModeSaved bool
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
type tnConsoleScreenBufferInfo struct {
|
|
344
|
+
Size, CursorPosition [2]int16
|
|
345
|
+
Attributes uint16
|
|
346
|
+
Left, Top, Right, Bottom int16
|
|
347
|
+
MaximumWindowSize [2]int16
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
func tnTerminalSize(f *os.File) (int, int, bool) {
|
|
351
|
+
var info tnConsoleScreenBufferInfo
|
|
352
|
+
ok, _, _ := tnGetConsoleScreenBufferInfo.Call(f.Fd(), uintptr(unsafe.Pointer(&info)))
|
|
353
|
+
if ok == 0 {
|
|
354
|
+
return 0, 0, false
|
|
355
|
+
}
|
|
356
|
+
return int(info.Right-info.Left) + 1, int(info.Bottom-info.Top) + 1, true
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
func tnSetRawMode(f *os.File, raw bool) bool {
|
|
360
|
+
var mode uint32
|
|
361
|
+
if syscall.GetConsoleMode(syscall.Handle(f.Fd()), &mode) != nil {
|
|
362
|
+
return false
|
|
363
|
+
}
|
|
364
|
+
if raw {
|
|
365
|
+
if !tnConsoleModeSaved {
|
|
366
|
+
tnSavedConsoleMode, tnConsoleModeSaved = mode, true
|
|
367
|
+
}
|
|
368
|
+
// no ENABLE_ECHO_INPUT / LINE_INPUT / PROCESSED_INPUT; ENABLE_VIRTUAL_TERMINAL_INPUT
|
|
369
|
+
mode = mode&^(0x4|0x2|0x1) | 0x200
|
|
370
|
+
} else if tnConsoleModeSaved {
|
|
371
|
+
mode = tnSavedConsoleMode
|
|
372
|
+
}
|
|
373
|
+
ok, _, _ := tnSetConsoleMode.Call(f.Fd(), uintptr(mode))
|
|
374
|
+
return ok != 0
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
func tnUmask(mask int) int {
|
|
378
|
+
return 0
|
|
379
|
+
}`;
|
|
380
|
+
const otherTtyHelper = `func tnTerminalSize(f *os.File) (int, int, bool) {
|
|
381
|
+
return 0, 0, false
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
func tnSetRawMode(f *os.File, raw bool) bool {
|
|
385
|
+
return false
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
func tnUmask(mask int) int {
|
|
389
|
+
return 0
|
|
390
|
+
}`;
|
|
174
391
|
export function registerProcess(r) {
|
|
175
392
|
defineModule(r, 'process');
|
|
176
393
|
r.globals['process'] = 'process';
|
|
@@ -182,6 +399,13 @@ export function registerProcess(r) {
|
|
|
182
399
|
defineHelper(r, 'nodeProcess', ['fmt', 'math/big', 'os', 'runtime', 'strings', 'syscall', 'time'], ['error', 'orderedMap'], processHelper);
|
|
183
400
|
defineClass(r, 'process.MemoryUsage', '*TnMemoryUsage', 'class', '', 'rss=float64; heapTotal=float64; heapUsed=float64; external=float64; arrayBuffers=float64', '', '');
|
|
184
401
|
const use = () => r.helper('nodeProcess');
|
|
402
|
+
defineHelper(r, 'nodeTtyOS@linux', ['os', 'runtime', 'strings', 'syscall', 'unsafe'], [], linuxTtyHelper);
|
|
403
|
+
for (const goos of ['darwin', 'freebsd'])
|
|
404
|
+
defineHelper(r, `nodeTtyOS@${goos}`, ['os', 'syscall', 'unsafe'], [], bsdTtyHelper);
|
|
405
|
+
defineHelper(r, 'nodeTtyOS@windows', ['os', 'syscall', 'unsafe'], [], windowsTtyHelper);
|
|
406
|
+
defineHelper(r, 'nodeTtyOS@other', ['os'], [], otherTtyHelper);
|
|
407
|
+
defineHelper(r, 'nodeTty', ['os', 'strconv'], ['nodeTtyOS@os', 'nodeProcess', 'error', 'dynamic'], ttyHelper);
|
|
408
|
+
const tty = () => r.helper('nodeTty');
|
|
185
409
|
const value = (name, type, emit) => {
|
|
186
410
|
r.values[`process.${name}`] = (_c) => emit();
|
|
187
411
|
r.valueTypes[`process.${name}`] = type;
|
|
@@ -241,6 +465,26 @@ export function registerProcess(r) {
|
|
|
241
465
|
use();
|
|
242
466
|
return 'TnIsTTY(os.Stdin)';
|
|
243
467
|
});
|
|
468
|
+
value('stdout.columns', 'float64', () => {
|
|
469
|
+
tty();
|
|
470
|
+
return 'TnTtyColumns(os.Stdout)';
|
|
471
|
+
});
|
|
472
|
+
value('stdout.rows', 'float64', () => {
|
|
473
|
+
tty();
|
|
474
|
+
return 'TnTtyRows(os.Stdout)';
|
|
475
|
+
});
|
|
476
|
+
value('stderr.columns', 'float64', () => {
|
|
477
|
+
tty();
|
|
478
|
+
return 'TnTtyColumns(os.Stderr)';
|
|
479
|
+
});
|
|
480
|
+
value('stderr.rows', 'float64', () => {
|
|
481
|
+
tty();
|
|
482
|
+
return 'TnTtyRows(os.Stderr)';
|
|
483
|
+
});
|
|
484
|
+
value('stdin.isRaw', 'bool', () => {
|
|
485
|
+
tty();
|
|
486
|
+
return 'tnStdinRaw';
|
|
487
|
+
});
|
|
244
488
|
value('stdout.fd', 'float64', () => 'float64(1)');
|
|
245
489
|
value('stderr.fd', 'float64', () => 'float64(2)');
|
|
246
490
|
value('stdin.fd', 'float64', () => 'float64(0)');
|
|
@@ -284,13 +528,34 @@ export function registerProcess(r) {
|
|
|
284
528
|
use();
|
|
285
529
|
return 'TnProcessMemoryUsage().rss';
|
|
286
530
|
});
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
531
|
+
// write(data[, encoding][, callback]): the data is written at once; the
|
|
532
|
+
// callback runs as a later task, as Node calls it once the data is flushed
|
|
533
|
+
for (const [stream, file] of [['stdout', 'os.Stdout'], ['stderr', 'os.Stderr']]) {
|
|
534
|
+
fn(`${stream}.write`, 'bool', (call) => {
|
|
535
|
+
use();
|
|
536
|
+
const callback = call.nodes.length > 1 ? call.args[call.args.length - 1] : '';
|
|
537
|
+
const isCallback = call.nodes.length > 1 && (call.types[call.types.length - 1] ?? '').startsWith('func(');
|
|
538
|
+
if (!isCallback)
|
|
539
|
+
return `TnProcessWrite(${file}, ${call.args[0]})`;
|
|
540
|
+
r.helper('timerWait');
|
|
541
|
+
const takesError = (call.types[call.types.length - 1] ?? '').startsWith('func()') ? '' : 'nil';
|
|
542
|
+
return `func() bool { __ok := TnProcessWrite(${file}, ${call.args[0]}); __cb := ${callback}; TnSetImmediate(func() { __cb(${takesError}) }); return __ok }()`;
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
for (const stream of ['stdout', 'stderr']) {
|
|
546
|
+
const f = stream === 'stdout' ? 'os.Stdout' : 'os.Stderr';
|
|
547
|
+
fn(`${stream}.getWindowSize`, '[]float64', (_c) => {
|
|
548
|
+
tty();
|
|
549
|
+
return `TnTtyWindowSize(${f})`;
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
fn('stdin.setRawMode', '', (call) => {
|
|
553
|
+
tty();
|
|
554
|
+
return `TnTtySetRawMode(${call.args[0]})`;
|
|
290
555
|
});
|
|
291
|
-
fn('
|
|
292
|
-
|
|
293
|
-
return `
|
|
556
|
+
fn('umask', 'float64', (call) => {
|
|
557
|
+
tty();
|
|
558
|
+
return `TnProcessUmask(${call.args.slice(0, 1).join(', ')})`;
|
|
294
559
|
});
|
|
295
560
|
fn('nextTick', '', (call) => {
|
|
296
561
|
r.helper('timerWait');
|
|
@@ -303,7 +568,7 @@ export function registerProcess(r) {
|
|
|
303
568
|
});
|
|
304
569
|
fn('emitWarning', '', (call) => {
|
|
305
570
|
use();
|
|
306
|
-
return `TnProcessEmitWarning(${call.args[0]})`;
|
|
571
|
+
return `TnProcessEmitWarning(${call.args[0]}, ${call.args[1] ?? '""'})`;
|
|
307
572
|
});
|
|
308
573
|
for (const id of ['getuid', 'getgid', 'geteuid', 'getegid']) {
|
|
309
574
|
const goName = id === 'getuid' ? 'Getuid' : id === 'getgid' ? 'Getgid' : id === 'geteuid' ? 'Geteuid' : 'Getegid';
|
package/bin/node/readline.js
CHANGED
|
@@ -26,7 +26,7 @@ func TnCreateInterface(options interface{}, rest ...interface{}) *TnReadline {
|
|
|
26
26
|
} else if options != nil {
|
|
27
27
|
input = TnGet(options, "input")
|
|
28
28
|
output = TnGet(options, "output")
|
|
29
|
-
if p, ok :=
|
|
29
|
+
if p, ok := TnGetValue(options, "prompt").(string); ok {
|
|
30
30
|
rl.promptText = p
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -228,6 +228,270 @@ func TnClearLine(stream interface{}, dir float64, rest ...interface{}) bool {
|
|
|
228
228
|
func TnClearScreenDown(stream interface{}, rest ...interface{}) bool {
|
|
229
229
|
return tnCursorWrite(stream, "\\x1b[0J", tnCursorCallback(rest))
|
|
230
230
|
}`;
|
|
231
|
+
// readline.emitKeypressEvents(stream): 'keypress' (str, key) events decoded
|
|
232
|
+
// from the stream's data, a port of Node's emitKeys
|
|
233
|
+
const keypressHelper = `// A decoded key; "" stands for undefined
|
|
234
|
+
type TnKey struct {
|
|
235
|
+
sequence string
|
|
236
|
+
name string
|
|
237
|
+
ctrl bool
|
|
238
|
+
meta bool
|
|
239
|
+
shift bool
|
|
240
|
+
code string
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
type tnKeyDecoder struct {
|
|
244
|
+
buf []rune // -1 is the escape timeout ('' in Node)
|
|
245
|
+
timer *TnTimeout
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
var tnKeyDecoders = map[*TnStream]*tnKeyDecoder{}
|
|
249
|
+
|
|
250
|
+
func TnEmitKeypressEvents(stream interface{}, rest ...interface{}) {
|
|
251
|
+
sl, ok := stream.(tnStreamLike)
|
|
252
|
+
if !ok || TnIsNil(stream) {
|
|
253
|
+
return
|
|
254
|
+
}
|
|
255
|
+
s := sl.tnStream()
|
|
256
|
+
if tnKeyDecoders[s] != nil {
|
|
257
|
+
return
|
|
258
|
+
}
|
|
259
|
+
d := &tnKeyDecoder{}
|
|
260
|
+
tnKeyDecoders[s] = d
|
|
261
|
+
var pending []byte
|
|
262
|
+
s.TnEventEmitter.on("data", func(chunk interface{}) {
|
|
263
|
+
if s.listenerCount("keypress") == 0 {
|
|
264
|
+
return
|
|
265
|
+
}
|
|
266
|
+
switch c := chunk.(type) {
|
|
267
|
+
case string:
|
|
268
|
+
pending = append(pending, c...)
|
|
269
|
+
case []byte:
|
|
270
|
+
pending = append(pending, c...)
|
|
271
|
+
default:
|
|
272
|
+
pending = append(pending, TnJSString(chunk)...)
|
|
273
|
+
}
|
|
274
|
+
// whole UTF-8 characters only, as a StringDecoder would
|
|
275
|
+
text := []rune{}
|
|
276
|
+
for len(pending) > 0 && utf8.FullRune(pending) {
|
|
277
|
+
r, size := utf8.DecodeRune(pending)
|
|
278
|
+
text = append(text, r)
|
|
279
|
+
pending = pending[size:]
|
|
280
|
+
}
|
|
281
|
+
if len(text) == 0 {
|
|
282
|
+
return
|
|
283
|
+
}
|
|
284
|
+
if d.timer != nil {
|
|
285
|
+
TnClearTimeout(d.timer)
|
|
286
|
+
d.timer = nil
|
|
287
|
+
}
|
|
288
|
+
for _, r := range text {
|
|
289
|
+
d.feed(s, r)
|
|
290
|
+
}
|
|
291
|
+
// a lone ESC at the end is the Escape key unless more follows soon
|
|
292
|
+
if text[len(text)-1] == 0x1b {
|
|
293
|
+
d.timer = TnSetTimeout(500, func() {
|
|
294
|
+
d.timer = nil
|
|
295
|
+
if len(d.buf) > 0 {
|
|
296
|
+
d.feed(s, -1)
|
|
297
|
+
}
|
|
298
|
+
})
|
|
299
|
+
}
|
|
300
|
+
})
|
|
301
|
+
s.listening("data")
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
func (d *tnKeyDecoder) feed(s *TnStream, r rune) {
|
|
305
|
+
d.buf = append(d.buf, r)
|
|
306
|
+
for len(d.buf) > 0 {
|
|
307
|
+
key, str, emit, n := tnDecodeKey(d.buf)
|
|
308
|
+
if n == 0 {
|
|
309
|
+
return
|
|
310
|
+
}
|
|
311
|
+
d.buf = d.buf[n:]
|
|
312
|
+
if emit {
|
|
313
|
+
s.emit("keypress", str, key)
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
type tnKeyNeedMore struct{}
|
|
319
|
+
|
|
320
|
+
var tnKeyTilde = regexp.MustCompile("^(?:(\\\\d\\\\d?)(?:;(\\\\d))?([~^$])|(\\\\d{3}~))$")
|
|
321
|
+
var tnKeyLetter = regexp.MustCompile("^((\\\\d;)?(\\\\d))?([A-Za-z])$")
|
|
322
|
+
|
|
323
|
+
var tnKeyCodes = map[string]string{
|
|
324
|
+
"[P": "f1", "[Q": "f2", "[R": "f3", "[S": "f4",
|
|
325
|
+
"OP": "f1", "OQ": "f2", "OR": "f3", "OS": "f4",
|
|
326
|
+
"[11~": "f1", "[12~": "f2", "[13~": "f3", "[14~": "f4",
|
|
327
|
+
"[200~": "paste-start", "[201~": "paste-end",
|
|
328
|
+
"[[A": "f1", "[[B": "f2", "[[C": "f3", "[[D": "f4", "[[E": "f5",
|
|
329
|
+
"[15~": "f5", "[17~": "f6", "[18~": "f7", "[19~": "f8", "[20~": "f9", "[21~": "f10", "[23~": "f11", "[24~": "f12",
|
|
330
|
+
"[A": "up", "[B": "down", "[C": "right", "[D": "left", "[E": "clear", "[F": "end", "[H": "home",
|
|
331
|
+
"OA": "up", "OB": "down", "OC": "right", "OD": "left", "OE": "clear", "OF": "end", "OH": "home",
|
|
332
|
+
"[1~": "home", "[2~": "insert", "[3~": "delete", "[4~": "end", "[5~": "pageup", "[6~": "pagedown",
|
|
333
|
+
"[[5~": "pageup", "[[6~": "pagedown", "[7~": "home", "[8~": "end",
|
|
334
|
+
"[a": "up shift", "[b": "down shift", "[c": "right shift", "[d": "left shift", "[e": "clear shift",
|
|
335
|
+
"[2$": "insert shift", "[3$": "delete shift", "[5$": "pageup shift", "[6$": "pagedown shift", "[7$": "home shift", "[8$": "end shift",
|
|
336
|
+
"Oa": "up ctrl", "Ob": "down ctrl", "Oc": "right ctrl", "Od": "left ctrl", "Oe": "clear ctrl",
|
|
337
|
+
"[2^": "insert ctrl", "[3^": "delete ctrl", "[5^": "pageup ctrl", "[6^": "pagedown ctrl", "[7^": "home ctrl", "[8^": "end ctrl",
|
|
338
|
+
"[Z": "tab shift",
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// One key from the start of in: n is how many characters it used (0 when
|
|
342
|
+
// it needs more input)
|
|
343
|
+
func tnDecodeKey(in []rune) (key *TnKey, str string, emit bool, n int) {
|
|
344
|
+
defer func() {
|
|
345
|
+
if x := recover(); x != nil {
|
|
346
|
+
if _, ok := x.(tnKeyNeedMore); !ok {
|
|
347
|
+
panic(x)
|
|
348
|
+
}
|
|
349
|
+
key, str, emit, n = nil, "", false, 0
|
|
350
|
+
}
|
|
351
|
+
}()
|
|
352
|
+
i := 0
|
|
353
|
+
s := ""
|
|
354
|
+
next := func() rune {
|
|
355
|
+
if i >= len(in) {
|
|
356
|
+
panic(tnKeyNeedMore{})
|
|
357
|
+
}
|
|
358
|
+
r := in[i]
|
|
359
|
+
i++
|
|
360
|
+
if r >= 0 {
|
|
361
|
+
s += string(r)
|
|
362
|
+
}
|
|
363
|
+
return r
|
|
364
|
+
}
|
|
365
|
+
isDigit := func(r rune) bool { return r >= '0' && r <= '9' }
|
|
366
|
+
k := &TnKey{}
|
|
367
|
+
ch := next()
|
|
368
|
+
escaped := false
|
|
369
|
+
if ch == 0x1b {
|
|
370
|
+
escaped = true
|
|
371
|
+
ch = next()
|
|
372
|
+
if ch == 0x1b {
|
|
373
|
+
ch = next()
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if escaped && (ch == 'O' || ch == '[') {
|
|
377
|
+
code := string(ch)
|
|
378
|
+
modifier := 0
|
|
379
|
+
if ch == 'O' {
|
|
380
|
+
ch = next()
|
|
381
|
+
if isDigit(ch) {
|
|
382
|
+
modifier = int(ch-'0') - 1
|
|
383
|
+
ch = next()
|
|
384
|
+
}
|
|
385
|
+
if ch >= 0 {
|
|
386
|
+
code += string(ch)
|
|
387
|
+
}
|
|
388
|
+
} else {
|
|
389
|
+
ch = next()
|
|
390
|
+
if ch == '[' {
|
|
391
|
+
code += "["
|
|
392
|
+
ch = next()
|
|
393
|
+
}
|
|
394
|
+
// the command starts at ch (Node: s.length - 1)
|
|
395
|
+
cmdStart := len(s) - 1
|
|
396
|
+
if ch >= 0 {
|
|
397
|
+
cmdStart = len(s) - utf8.RuneLen(ch)
|
|
398
|
+
}
|
|
399
|
+
if isDigit(ch) {
|
|
400
|
+
ch = next()
|
|
401
|
+
if isDigit(ch) {
|
|
402
|
+
ch = next()
|
|
403
|
+
if isDigit(ch) {
|
|
404
|
+
ch = next()
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if ch == ';' {
|
|
409
|
+
ch = next()
|
|
410
|
+
if isDigit(ch) {
|
|
411
|
+
next()
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
cmd := s[cmdStart:]
|
|
415
|
+
if m := tnKeyTilde.FindStringSubmatch(cmd); m != nil {
|
|
416
|
+
if m[4] != "" {
|
|
417
|
+
code += m[4]
|
|
418
|
+
} else {
|
|
419
|
+
code += m[1] + m[3]
|
|
420
|
+
modifier = 0
|
|
421
|
+
if m[2] != "" {
|
|
422
|
+
modifier, _ = strconv.Atoi(m[2])
|
|
423
|
+
modifier--
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
} else if m := tnKeyLetter.FindStringSubmatch(cmd); m != nil {
|
|
427
|
+
code += m[4]
|
|
428
|
+
modifier = 0
|
|
429
|
+
if m[3] != "" {
|
|
430
|
+
modifier, _ = strconv.Atoi(m[3])
|
|
431
|
+
modifier--
|
|
432
|
+
}
|
|
433
|
+
} else {
|
|
434
|
+
code += cmd
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
k.ctrl = modifier&4 != 0
|
|
438
|
+
k.meta = modifier&10 != 0
|
|
439
|
+
k.shift = modifier&1 != 0
|
|
440
|
+
k.code = code
|
|
441
|
+
if named, ok := tnKeyCodes[code]; ok {
|
|
442
|
+
parts := strings.SplitN(named, " ", 2)
|
|
443
|
+
k.name = parts[0]
|
|
444
|
+
if len(parts) == 2 && parts[1] == "shift" {
|
|
445
|
+
k.shift = true
|
|
446
|
+
} else if len(parts) == 2 {
|
|
447
|
+
k.ctrl = true
|
|
448
|
+
}
|
|
449
|
+
} else {
|
|
450
|
+
k.name = "undefined"
|
|
451
|
+
}
|
|
452
|
+
} else {
|
|
453
|
+
named := true
|
|
454
|
+
switch {
|
|
455
|
+
case ch == '\\r':
|
|
456
|
+
k.name, k.meta = "return", escaped
|
|
457
|
+
case ch == '\\n':
|
|
458
|
+
k.name, k.meta = "enter", escaped
|
|
459
|
+
case ch == '\\t':
|
|
460
|
+
k.name, k.meta = "tab", escaped
|
|
461
|
+
case ch == '\\b' || ch == 0x7f:
|
|
462
|
+
k.name, k.meta = "backspace", escaped
|
|
463
|
+
case ch == 0x1b:
|
|
464
|
+
k.name, k.meta = "escape", escaped
|
|
465
|
+
case ch == ' ':
|
|
466
|
+
k.name, k.meta = "space", escaped
|
|
467
|
+
case !escaped && ch >= 0 && ch <= 0x1a:
|
|
468
|
+
k.name, k.ctrl = string(rune(ch+'a'-1)), true
|
|
469
|
+
case isDigit(ch) || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'):
|
|
470
|
+
k.name = strings.ToLower(string(ch))
|
|
471
|
+
k.shift = ch >= 'A' && ch <= 'Z'
|
|
472
|
+
k.meta = escaped
|
|
473
|
+
case escaped:
|
|
474
|
+
if ch < 0 {
|
|
475
|
+
k.name = "escape"
|
|
476
|
+
} else {
|
|
477
|
+
named = false
|
|
478
|
+
}
|
|
479
|
+
k.meta = true
|
|
480
|
+
default:
|
|
481
|
+
named = false
|
|
482
|
+
}
|
|
483
|
+
if !named && !escaped {
|
|
484
|
+
k.sequence = s
|
|
485
|
+
// a single unnamed character, e.g. "."
|
|
486
|
+
return k, s, utf8.RuneCountInString(s) == 1, i
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
k.sequence = s
|
|
490
|
+
if escaped {
|
|
491
|
+
return k, "", s != "", i
|
|
492
|
+
}
|
|
493
|
+
return k, s, s != "", i
|
|
494
|
+
}`;
|
|
231
495
|
export function registerReadline(r) {
|
|
232
496
|
defineModule(r, 'readline');
|
|
233
497
|
defineModule(r, 'readline/promises');
|
|
@@ -280,6 +544,13 @@ export function registerReadline(r) {
|
|
|
280
544
|
return event && event.kind === 'StringLiteral' && event.text === 'line' ? ['string'] : [];
|
|
281
545
|
};
|
|
282
546
|
r.paramTypers['readline.Interface#once'] = r.paramTypers['readline.Interface#on'];
|
|
547
|
+
defineHelper(r, 'nodeKeypress', ['regexp', 'strconv', 'strings', 'unicode/utf8'], ['nodeStream', 'nodeEvents', 'timerWait'], keypressHelper);
|
|
548
|
+
defineClass(r, 'readline.Key', '*TnKey', 'class', '', 'sequence=string; name=string; ctrl=bool; meta=bool; shift=bool; code=string', '', '');
|
|
549
|
+
r.functions['readline.emitKeypressEvents'] = (call) => {
|
|
550
|
+
r.helper('nodeKeypress');
|
|
551
|
+
return `TnEmitKeypressEvents(${call.args.join(', ')})`;
|
|
552
|
+
};
|
|
553
|
+
r.results['readline.emitKeypressEvents'] = '';
|
|
283
554
|
defineHelper(r, 'nodeReadlineCursor', [], ['nodeStream', 'nodeInvoke', 'eventLoop'], cursorHelper);
|
|
284
555
|
const cursorFns = {
|
|
285
556
|
cursorTo: 'TnCursorTo',
|
package/bin/node/registry.js
CHANGED
|
@@ -40,7 +40,11 @@ export function createNodeRegistry() {
|
|
|
40
40
|
typeOf: (_node) => '',
|
|
41
41
|
visit: (_node) => '',
|
|
42
42
|
categoryOf: (_node) => '',
|
|
43
|
-
isArrayBuffer: (_node) => false
|
|
43
|
+
isArrayBuffer: (_node) => false,
|
|
44
|
+
entryPoint: (_node) => '',
|
|
45
|
+
callSite: (_node) => ({ file: '', line: 0, column: 0 }),
|
|
46
|
+
mockMember: (_call, _tracker, _kind) => '',
|
|
47
|
+
mockMemberType: (_call, _kind) => ''
|
|
44
48
|
};
|
|
45
49
|
return registry;
|
|
46
50
|
}
|