3

我正在尝试使用此咖啡代码读取用户输入:

_readEmail = (program, opts, c, u, cb) ->
    program.prompt 'email: ', /^.+@.+\..+$/, (email) =>
        u.email = email
        cb()

但是,退格没有正确处理。它只是作为另一个字符读取,而不是删除字符。有没有简单的方法来处理这个?

4

1 回答 1

1

您应该使用 readline 模块:

var readline = require('readline');

var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.question("What do you think of node.js? ", function(answer) {
  // TODO: Log the answer in a database
  console.log("Thank you for your valuable feedback:", answer);

  rl.close();
});

有关文档和示例,请参阅http://nodejs.org/api/readline.htmlhttps://sourcegraph.com/github.com/joyent/node/symbols/javascript/lib/readline.js

于 2013-09-09T17:31:43.410 回答