node-progress icon indicating copy to clipboard operation
node-progress copied to clipboard

Removal of cursor

Open ghost opened this issue 9 years ago • 5 comments

The cursor can sometimes be really annoying especially in long running progress bars is there a way to remove it

ghost avatar Apr 28 '15 13:04 ghost

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.

  1. Disable/re-enable the cursor in a wrapper script. This varies greatly depending on your OS, terminal, etc.
  2. With my configuration, setting the bar width to the terminal width pushes the cursor offscreen. This can be done by setting the width option to process.stderr.columns.
  3. Send the cursor to the beginning of the line by adding \r to the end of your template.

jrouleau avatar Apr 29 '15 23:04 jrouleau

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 avatar Apr 30 '15 11:04 gaborcsardi

@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 avatar Apr 30 '15 16:04 jrouleau

@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.

gaborcsardi avatar Apr 30 '15 16:04 gaborcsardi

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.

ghost avatar Apr 30 '15 17:04 ghost