-
Notifications
You must be signed in to change notification settings - Fork 281
API | vorpal.ui
Provides tools for direct and easy manipulation of your screen, including editing the prompt, user input and re-drawing the screen.
Gets or sets the user's delimiter (message) on the current vorpal prompt. If no parameter is passed, the current delimiter will be gotten. Otherwise, the delimiter will be overridden.
vorpal.ui.delimiter('NaN: ');
setInterval(function() {
vorpal.ui.delimiter(vorpal.ui.delimiter() + 'NaN: ');
}, 1000);After running for 4 seconds:
NaN: NaN: NaN: NaN: NaN: This delimiter is temporary and will reset to vorpal's last set delimiter on the next prompt, as set by vorpal.delimiter.
Gets or sets the the user's input text on the current vorpal prompt. If no parameter is passed, the current input will be gotten. Otherwise, the input will be overridden.
setInterval(function() {
vorpal.ui.input(vorpal.ui.input() + 'NaN');
vorpal.log(vorpal.ui.input());
}, 1000);NaN
NaNNaN
NaNNaNNaN
NaNNaNNaNNaN
app$ NaNNaNNaNNaNLogs current prompt delimiter and input values, and returns to the same prompt. This is good for uses such as tabbed auto-completion.
setTimeout(function() {
vorpal.ui.imprint();
vorpal.log('cheese pepperoni olives anchovies');
}, 2000);app~$ i want
cheese pepperoni olives anchovies
app~$ i wantSubmits the active vorpal prompt as if the user entered a command and pressed enter. The text is the value passed as the result of the command.
setTimeout(function() {
vorpal.ui.submit('help');
}, 2000);app~$ help
...
...
app~$Cancels the active vorpal prompt. This will break the regular vorpal prompt loop, and will, if nothing else is executed afterward, therefore exit the application. This can also be used to cancel custom Inquirer prompts called within a command's execution. When cancelled, the command's callback is not called.
setTimeout(function() {
vorpal.ui.cancel();
}, 2000);app~$
$ (app exits)Re-draws the screen. This method exposes the logUpdate library by Sindre Sorhus.
setInterval(function () {
vorpal.ui.redraw('\n\n' + Math.random() + '\n\n');
}, 1000);Note: If vorpal is currently mid a prompt, it the prompt will not be drawn after ui.redraw is called. To re-show the prompt, use ui.redraw.done() afterwards.
Clears the logged output after ui.redraw(). This method exposes the logUpdate.clear() method of logUpdate, written by Sindre Sorhus.
let ctr = 0;
function draw() {
vorpal.ui.redraw('\n\n' + Math.random() + '\n\n');
if (ctr < 10) {
ctr++;
setTimeout(function (){
draw();
}, 200)
} else {
vorpal.ui.redraw.clear();
}
}
draw();Persists the logged output after ui.redraw(). This method exposes the logUpdate.done() method of logUpdate, written by Sindre Sorhus. If the user was mid a vorpal prompt when ui.redraw was called, ui.redraw.done() will show the input again.
let ctr = 0;
function draw() {
vorpal.ui.redraw('\n\n' + Math.random() + '\n\n');
if (ctr < 10) {
ctr++;
setTimeout(function (){
draw();
}, 200)
} else {
vorpal.ui.redraw.done();
}
}
draw();