* moves the cursor to the x and y coordinate on the given stream
(stream, x, y, callback)
| 31 | */ |
| 32 | |
| 33 | function cursorTo(stream, x, y, callback) { |
| 34 | if (callback !== undefined) { |
| 35 | validateFunction(callback, 'callback'); |
| 36 | } |
| 37 | |
| 38 | if (typeof y === 'function') { |
| 39 | callback = y; |
| 40 | y = undefined; |
| 41 | } |
| 42 | |
| 43 | if (NumberIsNaN(x)) throw new ERR_INVALID_ARG_VALUE('x', x); |
| 44 | if (NumberIsNaN(y)) throw new ERR_INVALID_ARG_VALUE('y', y); |
| 45 | |
| 46 | if (stream == null || (typeof x !== 'number' && typeof y !== 'number')) { |
| 47 | if (typeof callback === 'function') process.nextTick(callback, null); |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | if (typeof x !== 'number') throw new ERR_INVALID_CURSOR_POS(); |
| 52 | |
| 53 | const data = typeof y !== 'number' ? CSI`${x + 1}G` : CSI`${y + 1};${x + 1}H`; |
| 54 | return stream.write(data, callback); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * moves the cursor relative to its current location |
no test coverage detected
searching dependent graphs…