Skip to content

Commit

Permalink
Monkey-patch readline's setPrompt to allow for colored prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvisser committed Apr 21, 2014
1 parent a57d1b3 commit edaf763
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ function _resetReadLine(state) {
}
});

/*!
* Monkey-patch the setPrompt method to properly calculate the string length when colors are used. :(
* http://stackoverflow.com/questions/12075396/adding-colors-to-terminal-prompt-results-in-large-white-space
*/
var rl = state.rl;
rl._setPrompt = rl.setPrompt;
rl.setPrompt = function(prompt, length) {
rl._setPrompt(prompt, (length) ? length : prompt.split(/[\r\n]/).pop().stripColors.length);
};

_bindSigint(state);
}

Expand Down

0 comments on commit edaf763

Please sign in to comment.