Skip to content

Commit

Permalink
Fix save/restore cursor position on macOS Terminal.app (#4)
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
sindresorhus committed Apr 23, 2017
1 parent e1bcbc5 commit 31a29c3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const ESC = '\u001B[';
const x = module.exports;
const ESC = '\u001B[';
const isTerminalApp = process.env.TERM_PROGRAM === 'Apple_Terminal';

x.cursorTo = function (x, y) {
if (arguments.length === 0) {
Expand Down Expand Up @@ -38,8 +39,8 @@ x.cursorForward = count => ESC + (typeof count === 'number' ? count : 1) + 'C';
x.cursorBackward = count => ESC + (typeof count === 'number' ? count : 1) + 'D';

x.cursorLeft = ESC + 'G';
x.cursorSavePosition = ESC + 's';
x.cursorRestorePosition = ESC + 'u';
x.cursorSavePosition = ESC + (isTerminalApp ? '7' : 's');
x.cursorRestorePosition = ESC + (isTerminalApp ? '8' : 'u');
x.cursorGetPosition = ESC + '6n';
x.cursorNextLine = ESC + 'E';
x.cursorPrevLine = ESC + 'F';
Expand Down

0 comments on commit 31a29c3

Please sign in to comment.