1.0.3 • Published 8 years ago

raw_input v1.0.3

Weekly downloads
1
License
MIT
Repository
-
Last release
8 years ago
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.raw_input("What's your name?", completionFunction)

A Coffeescript variation:

raw_input = require("raw_input") completionFunction = -> console.log("Great name!") message = raw_input.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. Receiving complete inputs is still a matter of difficulty, but can be achieved by making the asynchronous part of this source code synchronous. Any edits to the source code and redistribution with proper citation will be allowed.
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;
  };
1.0.3

8 years ago

1.1.0

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago