node.js - how to prefix the input using inquirer.prompt -
given following...
var prompts = [{ type: 'input', name: 'message', default: 'some message' message: 'commit message?', }] require('inquirer').prompt(prompts, function(){})
the terminal output following
[?] commit message? (some message) ||
the "||" symbolizes cursor
if press enter, without typing anything, inquirer use (some message) default input value.
however, if type @ "some message gets overwritten"
i following instead
[?] commit message? || message
the "||" symbolizes cursor
basically modify default message, or prefix input value, allowing me modify prefix.
my best solution... not work following
var prompts = [{ type: 'input', name: 'message', message: 'commit message?', when: function(){ process.nexttick(function(){ process.stdout.write('some message'); }); } }] require('inquirer').prompt(prompts, function(){})
this following
[?] commit message? message ||
the "||" symbolizes cursor
this seems work, unable move cursor backward in order modify message.
is possible print modifiable string terminal?
this 1 way that:
var inquirer = require("inquirer"); var chalk = require("chalk"); inquirer.prompt([ { type: "input", message: "commit message? " + chalk.cyan( "some message" ), name: "message", filter: function(val) { return val + " message"; } } ], function( answers ) { console.log( json.stringify(answers, null, " ") ); });
you can make own prompts.
cheers.
Comments
Post a Comment