Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 1.02 KB

.verb.md

File metadata and controls

47 lines (35 loc) · 1.02 KB

Usage

var UI = require('{%= name %}');
var ui = new UI();

Example

example

The following example shows how to create a basic input prompt. This example is a greatly simplified version of [prompt-base][].

(This code is also in example.js if you want to run it yourself.)

var cyan = require('ansi-cyan');
var UI = require('{%= name %}');
var ui = new UI();

// first, we need to render the "question" 
// to display in the terminal
var prompt = '? foo ';
ui.render(prompt);

// on keypress events, re-render the prompt 
// along with user input
ui.on('keypress', function() {
  ui.render(prompt + ui.rl.line);
});

// when the "line" event is emitted (from the "enter" keypress)
// we `.end()` to unmute the output stream then pause the readline. 
ui.on('line', function(answer) {
  ui.render(prompt + cyan(answer));
  ui.end();
  ui.rl.pause();
  console.log({color: answer});
});

API

{%= apidocs("index.js") %}

Attribution

Inspired by the "screen manager" code in Inquirer.