-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconsoleUpdate.js
More file actions
43 lines (38 loc) · 1.1 KB
/
consoleUpdate.js
File metadata and controls
43 lines (38 loc) · 1.1 KB
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
const debug = require('debug')('cdn-cache-check-consoleUpdate');
debug('Entry: [%s]', __filename);
// Writes text to the start of the current console row
function writeLn(text = '') {
try {
// Convert input to text if required
if (typeof (text) !== 'string') {
text = text.toString();
}
// Move cursor to start of row
process.stdout.cursorTo(0);
// Write text with added end-of-line
process.stdout.write(`${text}\r`);
} catch (error) {
debug('An error occurred in write(): %O', error);
}
}
/* Clears the current console line of text
-1: to the left from cursor
0: the entire line.
1: to the right from cursor
*/
function clearLn(option = 0) {
try {
process.stdout.clearLine(option);
} catch (error) {
debug('An error occurred in clearLine(): %O', error);
}
}
// Moves the cursor position within the current row
function cursorTo(column = 0) {
try {
process.stdout.cursorTo(column);
} catch (error) {
debug('An error occurred in cursorTo(): %O', error);
}
}
module.exports = { writeLn, clearLn, cursorTo };