Skip to content

Instantly share code, notes, and snippets.

@linhuiw
Created August 20, 2012 13:47
Show Gist options
  • Select an option

  • Save linhuiw/3404203 to your computer and use it in GitHub Desktop.

Select an option

Save linhuiw/3404203 to your computer and use it in GitHub Desktop.

Revisions

  1. linhuiw created this gist Aug 20, 2012.
    27 changes: 27 additions & 0 deletions redline-complete.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    //
    // 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'});