* moves the cursor relative to its current location
(stream, dx, dy, callback)
| 59 | */ |
| 60 | |
| 61 | function moveCursor(stream, dx, dy, callback) { |
| 62 | if (callback !== undefined) { |
| 63 | validateFunction(callback, 'callback'); |
| 64 | } |
| 65 | |
| 66 | if (stream == null || !(dx || dy)) { |
| 67 | if (typeof callback === 'function') process.nextTick(callback, null); |
| 68 | return true; |
| 69 | } |
| 70 | |
| 71 | let data = ''; |
| 72 | |
| 73 | if (dx < 0) { |
| 74 | data += CSI`${-dx}D`; |
| 75 | } else if (dx > 0) { |
| 76 | data += CSI`${dx}C`; |
| 77 | } |
| 78 | |
| 79 | if (dy < 0) { |
| 80 | data += CSI`${-dy}A`; |
| 81 | } else if (dy > 0) { |
| 82 | data += CSI`${dy}B`; |
| 83 | } |
| 84 | |
| 85 | return stream.write(data, callback); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * clears the current line the cursor is on: |
no test coverage detected
searching dependent graphs…