Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lydell committed Jul 5, 2020
0 parents commit cccc9a6
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"proseWrap": "never"
}
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: run
run:
./script.bash
35 changes: 35 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const pty = require("node-pty");

const options = {
cols: process.stdout.columns,
rows: process.stdout.rows,
};

// const terminal = pty.spawn("nvim", [], options);
// const terminal = pty.spawn("pwd", ["-P"], options);
const terminal = pty.spawn("./slow.bash", [], options);
console.clear();
console.log(terminal.pid, terminal.process);

process.stdout.on("resize", () => {
terminal.resize(process.stdout.columns, process.stdout.rows);
});

process.stdin.setRawMode(true);
process.stdin.setEncoding("utf8");
process.stdin.on("data", (data) => {
if (data === "\x03") {
terminal.kill();
} else {
terminal.write(data);
}
});

terminal.on("data", (data) => {
process.stdout.write(data);
});

terminal.on("exit", (exitCode, signal) => {
console.log("Exit", exitCode, signal);
process.exit(exitCode);
});
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"private": true,
"devDependencies": {
"prettier": "^2.0.5"
},
"dependencies": {
"node-pty": "^0.9.0"
}
}
3 changes: 3 additions & 0 deletions script.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

node index.js
6 changes: 6 additions & 0 deletions slow.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

while true; do
echo $RANDOM
sleep 0.1
done

0 comments on commit cccc9a6

Please sign in to comment.