source: frontend/node_modules/sisteransi/src/index.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.3 KB
Line 
1'use strict';
2
3const ESC = '\x1B';
4const CSI = `${ESC}[`;
5const beep = '\u0007';
6
7const cursor = {
8 to(x, y) {
9 if (!y) return `${CSI}${x + 1}G`;
10 return `${CSI}${y + 1};${x + 1}H`;
11 },
12 move(x, y) {
13 let ret = '';
14
15 if (x < 0) ret += `${CSI}${-x}D`;
16 else if (x > 0) ret += `${CSI}${x}C`;
17
18 if (y < 0) ret += `${CSI}${-y}A`;
19 else if (y > 0) ret += `${CSI}${y}B`;
20
21 return ret;
22 },
23 up: (count = 1) => `${CSI}${count}A`,
24 down: (count = 1) => `${CSI}${count}B`,
25 forward: (count = 1) => `${CSI}${count}C`,
26 backward: (count = 1) => `${CSI}${count}D`,
27 nextLine: (count = 1) => `${CSI}E`.repeat(count),
28 prevLine: (count = 1) => `${CSI}F`.repeat(count),
29 left: `${CSI}G`,
30 hide: `${CSI}?25l`,
31 show: `${CSI}?25h`,
32 save: `${ESC}7`,
33 restore: `${ESC}8`
34}
35
36const scroll = {
37 up: (count = 1) => `${CSI}S`.repeat(count),
38 down: (count = 1) => `${CSI}T`.repeat(count)
39}
40
41const erase = {
42 screen: `${CSI}2J`,
43 up: (count = 1) => `${CSI}1J`.repeat(count),
44 down: (count = 1) => `${CSI}J`.repeat(count),
45 line: `${CSI}2K`,
46 lineEnd: `${CSI}K`,
47 lineStart: `${CSI}1K`,
48 lines(count) {
49 let clear = '';
50 for (let i = 0; i < count; i++)
51 clear += this.line + (i < count - 1 ? cursor.up() : '');
52 if (count)
53 clear += cursor.left;
54 return clear;
55 }
56}
57
58module.exports = { cursor, scroll, erase, beep };
Note: See TracBrowser for help on using the repository browser.