Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/core/posix-node/demo/terminal.js
1067 views
1
/*
2
Example of using setEcho and getChar from pour posix library.
3
4
NOTE: You can accomplish basically the same thing as this demo in pure node as explained at
5
6
https://stackoverflow.com/questions/5006821/nodejs-how-to-read-keystrokes-from-stdin
7
8
*/
9
10
const posix = require("..");
11
posix.setEcho(false);
12
console.log(
13
"This is a little terminal that capitalizes whatever you type, as you type it."
14
);
15
console.log("Hit ctrl+c or ctrl+d to exit, and of course this is not burning cpu while waiting for input.");
16
console.log("You can usé utf-8: 😀");
17
18
while (true) {
19
const t = posix.getChar();
20
if (t.charCodeAt(0) == 4) break;
21
process.stdout.write(t.toUpperCase());
22
}
23
24