Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vorpal.ui.clear command to API #134

Open
mamboer opened this issue Mar 13, 2016 · 17 comments
Open

Add vorpal.ui.clear command to API #134

mamboer opened this issue Mar 13, 2016 · 17 comments

Comments

@mamboer
Copy link

mamboer commented Mar 13, 2016

hi,
I implemented a clear command in one of my vorpal application following your answers in this post http://stackoverflow.com/questions/8813142/clear-terminal-window-in-node-js-readline-shell/32871585#32871585?newreg=0fd7e6b366544c72b82496cd4c077973

The problem is that the cursor lost in the console after executing the clear command, as the screenshots below:

Before clear,

image

After clear,

image

Notice that the grey cursor had gone.

@dthree
Copy link
Owner

dthree commented Mar 13, 2016

Thanks.

The API on this changed a bit since that post. Could you possibly paste your code?

@mamboer
Copy link
Author

mamboer commented Mar 14, 2016

hi, here's my code in my clear command,

'use strict';
module.exports = (vorpal, config) => {
    return vorpal
        .command('clear', 'Clear the outputs.')
        .action(function(args, cbk) {
            let blank = '';
            for (var i = 0; i < process.stdout.rows; ++i) {
              blank += '\n';
            }
            vorpal.ui.redraw(blank);
            vorpal.ui.redraw('');
            cbk();
        });
};
@mamboer
Copy link
Author

mamboer commented Mar 14, 2016

It will be very nice that vorpal could add a built-in clear command along with the help and exit.
Viewing the help, doing some works, clear the screen and doing some other works, daily CLI working routine.

@dthree
Copy link
Owner

dthree commented Mar 14, 2016

For sure!

In the immediate, check out this for a much better way to solve your problem!

https://github.com/dthree/cash/blob/master/src/commands/clear.js

@mamboer
Copy link
Author

mamboer commented Mar 14, 2016

Cool! Thanks so much!

I'm confused on the \u001b[2J\u001b[0;0H in the source code, can you explain a little bit about it?

@eistaa
Copy link

eistaa commented Mar 14, 2016

@mamboer: It's ANSI escape codes. A breakdown of \u001b[2J\u001b[0;0H is:

  • \u001b is the escape character, together with [ it becomes a Control Sequence Introducer (CSI)
  • CSI 2J is the sequence for clearing the entire screen
  • CSI 0;0H is the sequence for moving the cursor to row 0, column 0
@dthree
Copy link
Owner

dthree commented Mar 14, 2016

No problem.

I'm renaming this issue to turn it into a feature request.

@dthree dthree changed the title cursor lost after clear the vorpal outputs Mar 14, 2016
@mamboer
Copy link
Author

mamboer commented Mar 14, 2016

@eistaa @dthree thanks guys

@subk
Copy link

subk commented Apr 22, 2016

Just to point out the ansi-escapes package which implements a clearScreen method and many other useful sequences.

@Maxtoros
Copy link

Maxtoros commented May 6, 2016

Hey guys am using this command to 'clean' the screen , especially after a messy execution :
vorpal
.command('clean')
.action(function (args,cb) {
process.stdout.write ("\u001B[2J\u001B[0;0f");
cb();
});

@dthree
Copy link
Owner

dthree commented May 8, 2016

@Maxtoros nice idea!

@jimbuck
Copy link

jimbuck commented Aug 1, 2016

Should we use @Maxtoros's process.stdout.write(...) or @dthree's this.log(...) for that?

@jimbuck
Copy link

jimbuck commented Aug 1, 2016

I just tried this on Windows 10 and it exits my app completely. Any ideas?

@Maxtoros
Copy link

Maxtoros commented Aug 1, 2016

@JimmyBoh I used Windows 10 while working with my solution ( ConEmu with 2 tabs : Cygwin Bash + CMD)

@dthree
Copy link
Owner

dthree commented Aug 1, 2016

@JimmyBoh probably this.log.


What exactly exits your app? Is there an exception?

@jimbuck
Copy link

jimbuck commented Aug 2, 2016

@Maxtoros exact recommendation:

vorpal
  .command('clean')
  .action(function (args,cb) {
    process.stdout.write ("\u001B[2J\u001B[0;0f");
    cb();
  });

There was no exception, it just instantly cleared everything and exiting the vorpal context (returned back to regular cmd.exe).

@jimbuck
Copy link

jimbuck commented Aug 8, 2016

I actually just tried the same thing with vorpal.ui.redraw.clear and even that made my app immediately exit without any error or other indication of failure. This is in cmd.exe with Windows 10, and also happens in Cmder on Windows 10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
6 participants