Debian Codegraph @

cli-color/move.js

raw
1 "use strict";
2
3 var d = require("d")
4 , trunc = require("es5-ext/math/trunc");
5
6 var up, down, right, left, abs = Math.abs, floor = Math.floor, max = Math.max;
7
8 var getMove = function (control) {
9 return function (num) {
10 num = isNaN(num) ? 0 : max(floor(num), 0);
11 return num ? "\x1b[" + num + control : "";
12 };
13 };
14
15 module.exports = Object.defineProperties(
16 function (x, y) {
17 x = isNaN(x) ? 0 : floor(x);
18 y = isNaN(y) ? 0 : floor(y);
19 return (x > 0 ? right(x) : left(-x)) + (y > 0 ? down(y) : up(-y));
20 },
21 {
22 up: d((up = getMove("A"))),
23 down: d((down = getMove("B"))),
24 right: d((right = getMove("C"))),
25 left: d((left = getMove("D"))),
26 to: d(function (x, y) {
27 x = isNaN(x) ? 1 : max(floor(x), 0) + 1;
28 y = isNaN(y) ? 1 : max(floor(y), 0) + 1;
29 return "\x1b[" + y + ";" + x + "H";
30 }),
31 lines: d(function (n) {
32 var dir;
33 n = trunc(n) || 0;
34 dir = n >= 0 ? "B" : "A";
35 n = floor(abs(n));
36 return "\x1b[" + n + dir + "\x1b[1G";
37 }),
38 top: d("\x1b[5000F"),
39 bottom: d("\x1b[5000B"),
40 lineBegin: d("\x1b[5000D"),
41 lineEnd: d("\x1b[5000C")
42 }
43 );