node-progress
node-progress copied to clipboard
Removal of cursor
The cursor can sometimes be really annoying especially in long running progress bars is there a way to remove it
The cursor is rendered by your terminal, not node or this module. You'll find that even popular GNU/Linux progress bars, wget
, pv
etc., don't hide the cursor either.
Though you do have a few options.
- Disable/re-enable the cursor in a wrapper script. This varies greatly depending on your OS, terminal, etc.
- With my configuration, setting the bar width to the terminal width pushes the cursor offscreen. This can be done by setting the
width
option toprocess.stderr.columns
. - Send the cursor to the beginning of the line by adding
\r
to the end of your template.
You can hide the cursor with ANSI escape codes, if the terminal supports them. See http://en.wikipedia.org/wiki/ANSI_escape_code and search for "Hides".
@gaborcsardi I'd tried escape codes, but couldn't get them working. Don't know what I was doing wrong because now they're working fine. Good call.
@aashrairavooru
4. Use ANSI escape codes. \x1B[?25l
hides the cursor, and \x1B[?25h
shows the cursor.
Example:
var bar = new ProgressBar(' [:bar]', {
total: 10,
callback: function() {
clearInterval(interval)
process.stderr.write('\x1B[?25h') // Show terminal cursor
}
})
process.stderr.write('\x1B[?25l') // Hide terminal cursor
var interval = setInterval(function() {
bar.tick()
}, 100)
@jrouleau I guess the challenge is that you need to check if the terminal supports ANSI sequences. You can look at how the coloring packages, e.g. chalk, do this.
I am looking for a way to invoke tput commands in nodejs haven't hade any luck although there are cli apps like https://www.npmjs.com/package/npm-workshop which remove the cursor looking into that right now On 30-Apr-2015 10:22 PM, "Gábor Csárdi" [email protected] wrote:
@jrouleau https://github.com/jrouleau I guess the challenge is that you need to check if the terminal supports ANSI sequences. You can look at how the coloring packages, e.g. chalk, do this.
— Reply to this email directly or view it on GitHub https://github.com/tj/node-progress/issues/88#issuecomment-97877840.