lib/autocomplete.js
function (str, cb) {
    var self = this;
    var input = parseInput(str, this.parent.ui._activePrompt.screen.rl.cursor);
    var commands = getCommandNames(this.parent.commands);
    var vorpalMatch = getMatch(input.context, commands, {ignoreSlashes: true});
    var freezeTabs = false;

    function end(str) {
      var res = handleTabCounts.call(self, str, freezeTabs);
      cb(undefined, res);
    }

    function evaluateTabs(input) {
      if (input.context && input.context[input.context.length - 1] === '/') {
        freezeTabs = true;
      }
    }

    if (vorpalMatch) {
      input.context = vorpalMatch;
      evaluateTabs(input);
      end(assembleInput(input));
      return;
    }

    input = getMatchObject.call(this, input, commands);
    if (input.match) {
      input = parseMatchSection.call(this, input);
      getMatchData.call(self, input, function (data) {
        var dataMatch = getMatch(input.context, data);
        if (dataMatch) {
          input.context = dataMatch;
          evaluateTabs(input);
          end(assembleInput(input));
          return;
        }
        end(filterData(input.context, data));
      });
      return;
    }
    end(filterData(input.context, commands));
  }
function (str, cb) {
    var self = this;
    var input = parseInput(str, this.parent.ui._activePrompt.screen.rl.cursor);
    var commands = getCommandNames(this.parent.commands);
    var vorpalMatch = getMatch(input.context, commands, {ignoreSlashes: true});
    var freezeTabs = false;

    function end(str) {
      var res = handleTabCounts.call(self, str, freezeTabs);
      cb(undefined, res);
    }

    function evaluateTabs(input) {
      if (input.context && input.context[input.context.length - 1] === '/') {
        freezeTabs = true;
      }
    }

    if (vorpalMatch) {
      input.context = vorpalMatch;
      evaluateTabs(input);
      end(assembleInput(input));
      return;
    }

    input = getMatchObject.call(this, input, commands);
    if (input.match) {
      input = parseMatchSection.call(this, input);
      getMatchData.call(self, input, function (data) {
        var dataMatch = getMatch(input.context, data);
        if (dataMatch) {
          input.context = dataMatch;
          evaluateTabs(input);
          end(assembleInput(input));
          return;
        }
        end(filterData(input.context, data));
      });
      return;
    }
    end(filterData(input.context, commands));
  }
function ( str , cb ) { var self = this ; var input = parseInput ( str , this . parent . ui . _activePrompt . screen . rl . cursor ) ; var commands = getCommandNames ( this . parent . commands ) ; var vorpalMatch = getMatch ( input . context , commands , { ignoreSlashes : true } ) ; var freezeTabs = false ; function end ( str ) { var res = handleTabCounts . call ( self , str , freezeTabs ) ; cb ( undefined , res ) ; } function evaluateTabs ( input ) { if ( input . context && input . context [ input . context . length - 1 ] === '/' ) { freezeTabs = true ; } } if ( vorpalMatch ) { input . context = vorpalMatch ; evaluateTabs ( input ) ; end ( assembleInput ( input ) ) ; return ; } input = getMatchObject . call ( this , input , commands ) ; if ( input . match ) { input = parseMatchSection . call ( this , input ) ; getMatchData . call ( self , input , function ( data ) { var dataMatch = getMatch ( input . context , data ) ; if ( dataMatch ) { input . context = dataMatch ; evaluateTabs ( input ) ; end ( assembleInput ( input ) ) ; return ; } end ( filterData ( input . context , data ) ) ; } ) ; return ; } end ( filterData ( input . context , commands ) ) ; }
Handles tabbed autocompletion.

- Initial tabbing lists all registered commands.
- Completes a command halfway typed.
- Recognizes options and lists all possible options.
- Recognizes option arguments and lists them.
- Supports cursor positions anywhere in the string.
- Supports piping.

@param {String} str
@return {String} cb
@api public
Handles tabbed autocompletion .