@timmy_i_chen/

Terminal Apps Library v2

Nodejs

A simple library for manipulating the terminal

fork
loading
Files
  • index.js
  • util
  • app.js
  • package-lock.json
  • package.json

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.8278212918602972","path":"index.js","file":{"path":"index.js","content":{"asEncoding":{"base64":"LyoKRWRpdCB0aGUgYXBwLmpzIGZpbGUgZm9yIHlvdXIgYXBwIDopCiovCgpjb25zdCBrZXlwcmVzcyA9IHJlcXVpcmUoJ2tleXByZXNzJyk7CmNvbnN0IHsgc2xlZXAgfSA9IHJlcXVpcmUoJy4vdXRpbC9taXNjJyk7CmNvbnN0IGNvbG9ycyA9IHJlcXVpcmUoJy4vdXRpbC9jb2xvcnMnKTsKY29uc3Qgc2NyZWVuID0gcmVxdWlyZSgnLi91dGlsL3NjcmVlbicpOwpjb25zdCB7IHNldHVwLCBsb29wLCBvbktleVByZXNzLCBvbk1vdXNlQ2xpY2sgfSA9IHJlcXVpcmUoJy4vYXBwJyk7CgprZXlwcmVzcyhwcm9jZXNzLnN0ZGluKTsKCnByb2Nlc3Muc3RkaW4ub24oJ2tleXByZXNzJywgZnVuY3Rpb24gKGNoLCBrZXkpIHsKICBjb25zdCBjaGFyID0ga2V5ID8ga2V5Lm5hbWUgOiBjaDsKCiAgaWYgKGNoYXIgPT09ICdlc2NhcGUnKSB7CiAgICBwcm9jZXNzLmV4aXQoKQogIH0KCiAgb25LZXlQcmVzcyhjaGFyKQp9KTsKCmtleXByZXNzLmVuYWJsZU1vdXNlKHByb2Nlc3Muc3Rkb3V0KTsKCgpwcm9jZXNzLnN0ZGluLm9uKCdtb3VzZXByZXNzJywgZnVuY3Rpb24gKHsKICB4LAogIHksCiAgc2Nyb2xsLAp9KSB7CiAgb25Nb3VzZUNsaWNrKHsKICAgIHJvdzogeSwKICAgIGNvbDogeCwKICAgIHNjcm9sbCwKICB9KTsKfSk7Cgpwcm9jZXNzLm9uKCdleGl0JywgZnVuY3Rpb24gKCkgewogIGtleXByZXNzLmRpc2FibGVNb3VzZShwcm9jZXNzLnN0ZG91dCk7Cn0pOwoKcHJvY2Vzcy5zdGRpbi5zZXRSYXdNb2RlKHRydWUpOwpwcm9jZXNzLnN0ZGluLnJlc3VtZSgpOwoKKGFzeW5jICgpID0+IHsKICB0cnkgewogICAgcHJvY2Vzcy5zdGRvdXQud3JpdGUoY29sb3JzLnJlc2V0KQogICAgc2NyZWVuLnJlc2V0KCk7CiAgICBhd2FpdCBzZXR1cCgpOwoKICAgIHdoaWxlICh0cnVlKSB7CiAgICAgIGF3YWl0IGxvb3AoKTsKICAgICAgYXdhaXQgc2xlZXAoMSk7CiAgICB9CiAgfSBjYXRjaChlKSB7CiAgICBwcm9jZXNzLnN0ZG91dC53cml0ZShjb2xvcnMucmVzZXQpCiAgICBjb25zb2xlLmxvZyhlKQogIH0KfSkoKTsK"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
Edit the app.js file for your app :)
*/

const keypress = require('keypress');
const { sleep } = require('./util/misc');
const colors = require('./util/colors');
const screen = require('./util/screen');
const { setup, loop, onKeyPress, onMouseClick } = require('./app');

keypress(process.stdin);

process.stdin.on('keypress', function (ch, key) {
  const char = key ? key.name : ch;

  if (char === 'escape') {
    process.exit()
  }

  onKeyPress(char)
});

keypress.enableMouse(process.stdout);


process.stdin.on('mousepress', function ({
  x,
  y,
  scroll,
}) {
  onMouseClick({
    row: y,
    col: x,
    scroll,
  });
});

process.on('exit', function () {
  keypress.disableMouse(process.stdout);
});

process.stdin.setRawMode(true);
process.stdin.resume();

(async () => {
  try {
    process.stdout.write(colors.reset)
    screen.reset();
    await setup();

    while (true) {
      await loop();
      await sleep(1);
    }
  } catch(e) {
    process.stdout.write(colors.reset)
    console.log(e)
  }
})();
node v10.16.0