raw_input

1.0.3 • Public • Published
Raw input is a simple to use module that allows developers to take user input in the form of a string from the command line interface when developing Node.js applications
Originating from the raw_input function found in Python 2.0, raw_input offers a variety of possibilities, and is still in development due to some minor and major bugs still present.
An example of raw_input in use is shown below:

var raw_input = require("raw_input"); completionFunction = function() { console.log("Great name!"); } message = raw_input("What's your name?", completionFunction);

A Coffeescript variation:

raw_input = require("raw_input") completionFunction = -> console.log("Great name!") message = raw_input("What's your name?", completionFunction)

This module is still in beta. Note that I'm a 13-year old hobbyist, so not many advanced features will be available in this module. Processing inputs can be achieved by editing the source code, which is provided below.
Source Code:
  var readline;
 
  readline = require('readline');
 
  readline.emitKeypressEvents(process.stdin);
 
  process.stdin.setRawMode(true);
 
  exports.raw_input = function(input, anyFunction) {
    var output;
    process.stdout.write(input);
    output = "";
    process.stdin.on('keypress', (function(_this) {
      return function(str, key) {
        if (key.name === 'space') {
          process.stdout.write(" ");
          return output = output + " ";
        } else if (key.name === 'backspace') {
          output = output.slice(0, output.length - 1);
          return process.stdout.write("\n" + output);
        } else if (key.name === 'return') {
          anyFunction();
          process.stdout.write("\n");
          return process.exit();
        } else {
          output = output + key.name;
          return process.stdout.write(key.name);
        }
      };
    })(this));
    return output;
  };
 
}).call(this);```

Package Sidebar

Install

npm i raw_input

Weekly Downloads

1

Version

1.0.3

License

MIT

Last publish

Collaborators

  • violetizhere