Skip to content

Instantly share code, notes, and snippets.

@linhuiw
Created August 20, 2012 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linhuiw/3404203 to your computer and use it in GitHub Desktop.
Save linhuiw/3404203 to your computer and use it in GitHub Desktop.
redline-complete
//
// Based on github.com/cloudhead/http-console
// An attempt at a simplified readline example.
//
var readline = require('readline')
, util = require('util')
, rl = readline.createInterface(process.stdin, process.stdout, completer)
// This should work now, thanks to @josher19
function completer(line) {
var completions = '.help .error .exit .quit .q'.split(' ')
var hits = completions.filter(function(c) {
if (c.indexOf(line) == 0) {
// console.log('bang! ' + c);
return c;
}
});
return [hits && hits.length ? hits : completions, line];
}
rl.write('type your tab key!');
// Simulate ctrl+u to delete the line written previously
//rl.write(null, {ctrl: true, name: 'u'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment