MCPcopy Create free account
hub / github.com/hashintel/hash / onData

Function onData

apps/hash-api/src/setup-admin.ts:50–78  ·  view source on GitHub ↗
(char: string)

Source from the content-addressed store, hash-verified

48
49 let buffer = "";
50 const onData = (char: string) => {
51 const code = char.charCodeAt(0);
52 // CR / LF / Ctrl+D — finish
53 if (code === 13 || code === 10 || code === 4) {
54 stdin.setRawMode(false);
55 stdin.pause();
56 stdin.off("data", onData);
57 stdout.write("\n");
58 resolve(buffer);
59 return;
60 }
61 // Ctrl+C — abort
62 if (code === 3) {
63 stdin.setRawMode(false);
64 stdin.pause();
65 stdout.write("\n");
66 process.exit(130);
67 }
68 // DEL / BS — erase last char
69 if (code === 127 || code === 8) {
70 if (buffer.length > 0) {
71 buffer = buffer.slice(0, -1);
72 stdout.write("\b \b");
73 }
74 return;
75 }
76 buffer += char;
77 stdout.write("*");
78 };
79
80 stdin.on("data", onData);
81 });

Callers

nothing calls this directly

Calls 4

pauseMethod · 0.65
resolveFunction · 0.50
writeMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected