const util = require('util');
const esc = '\u001B';
/**
* A small underlying module which manages cursor movement
* @module cursor
*/
function write(d) {
process.stdout.write(d);
}
module.exports = {
/**
* Move the cursor to a specific coordinate
* @param {number} x
* @param {number} y
*/
move: function (x, y) {
write(esc + "[" + (y+1) + ";" + (x+1) + "H");
},
/**
* move the cursor up an specific amount of lines
* @param {number} lines
*/
goUp: function (lines) {
write(esc + "[$" + lines + "A");
},
/**
* Move the cursor up one line
*/
goUpOne: function () {
write(esc + "[1A");
},
/**
* move the cursor down a specific amount of lines
* @param {number} lines
*/
goDown: function (lines) {
write(esc + "[" + lines + "B");
},
/**
* Move the cursor down one line
*/
goDownOne: function () {
write(esc + "[1B");
},
/**
* Move the cursor right a specific amount of columns
* @param {number} lines
*/
goRight: function (lines) {
write(esc + "[" + lines + "C");
},
/**
* Move the cursor right one column
*/
goRightOne: function () {
write(esc + "[1C");
},
/**
* Move the cursor left a specific amount of columns
* @param {number} lines
*/
goLeft: function (lines) {
write(esc + "[" + lines + "D");
},
/**
* Move the cursor left one column
*/
goLeftOne: function () {
write(esc + "[1D");
},
/**
* Clears the whole console
*/
clear: function () {
write( esc + "c" + esc);
},
/**
* Erases a line
*/
eraseLine: function () {
write(esc + "[K");
},
/**
* Write text at the cursor
* @param {string} data
*/
write: function (data) {
process.stdout.write(data);
},
/**
* Write text at the cursor until it hits xLength
* sort of a limit on for how long it should write a string
* @param {string} data
* @param {number} xLength
*/
wrap: function (data, xLength) {
data += "";
process.stdout.write(data.slice(0, xLength));
},
/**
* Reset all color effect on the cursor currently
*/
resetColor: function () {
write("\x1b[0m");
}
};