Skip to content

Commit

Permalink
do not create readline interface unless interactive() is called. ensu…
Browse files Browse the repository at this point in the history
…re prompt input goes to end of line after prompting (ux hack, in case user types more before prompt() is returned, will allow additional input to continue at end of inputted text instead if in middle.) (#13)
  • Loading branch information
gleuch authored and patapizza committed Apr 18, 2016
1 parent 4e569ea commit 82ec48f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/wit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

const request = require('request');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const uuid = require('node-uuid');
const Logger = require('./logger').Logger;
const logLevels = require('./logger').logLevels;
Expand Down Expand Up @@ -265,9 +261,14 @@ const Wit = function(token, actions, logger) {
const sessionId = uuid.v1();
const context = typeof initContext === 'object' ? initContext : {};
const steps = maxSteps ? maxSteps : DEFAULT_MAX_STEPS;
rl.setPrompt('> ');
rl.prompt();
rl.on('line', ((line) => {
this.rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
this.rl.setPrompt('> ');
this.rl.prompt();
this.rl.write(null, {ctrl: true, name: 'e'});
this.rl.on('line', ((line) => {
const msg = line.trim();
this.runActions(
sessionId,
Expand All @@ -277,7 +278,8 @@ const Wit = function(token, actions, logger) {
if (error) {
l.error(error);
}
rl.prompt();
this.rl.prompt();
this.rl.write(null, {ctrl: true, name: 'e'});
},
steps
);
Expand Down

0 comments on commit 82ec48f

Please sign in to comment.