Readline implementation for browserify.
JavaScript
Switch branches/tags
Latest commit 8127f46 Aug 23, 2012 @joeferner new version
Permalink
Failed to load latest commit information.
test enter selects autocomplete Jun 22, 2012
.gitignore initial Jun 19, 2012
README.md moved styles to css Jun 20, 2012
default.css enter selects autocomplete Jun 22, 2012
index.js Fixed bugs in the more... functionality Aug 13, 2012
package.json new version Aug 23, 2012

README.md

readline-browserify

Readline implementation for browserify.

Install

npm install browserify
npm install readline-browserify

Usage

Copy the css from default.css into your css file.

<div id="commandLineOutput"></div>
<div id="commandLine"></div>

<script>
  var readline = require("readline");

  var rl = readline.createInterface({
    elementId: 'commandLine',

    write: function(data) {
      var output = document.getElementById('commandLineOutput');
      if (output.innerHTML.length > 0) {
        output.innerHTML += "<br>";
      }
      output.innerHTML += line;
    },

    completer: function(linePartial, callback) {
      var cmds = ['command1', 'command2', 'test'];
      var matches = [];
      cmds.forEach(function (cmd) {
        if (cmd.indexOf(linePartial) === 0) {
          matches.push(cmd);
        }
      });
      callback(null, [matches, linePartial]);
    }
  });

  rl.setPrompt('browserify> ');
  rl.prompt();
  rl.on('line', function (line) {
      switch (line.trim()) {
      case 'command1':
        rl.write('ok command1');
        break;
      case 'command2':
        rl.write('ok command2');
        break;
      case 'test':
        rl.write('ok test');
        break;
      default:
        rl.write('Say what? I might have heard `' + line.trim() + '`');
        break;
      }
      rl.prompt();
    });
</script>