Files
  • index.js
  • util
  • app.js
  • package-lock.json
  • package.json
index.js
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.15.2 linux/amd64