code: function(input) {
      var start, end;
      switch (this._caretChange) {
        case Caret.SELECT_ALL:
          start = 0;
          end = input.typed.length;
          break;
  
        case Caret.TO_END:
          start = input.typed.length;
          end = input.typed.length;
          break;
  
        case Caret.TO_ARG_END:
          // There could be a fancy way to do this involving assignment/arg math
          // but it doesn't seem easy, so we cheat a move the cursor to just before
          // the next space, or the end of the input
          start = input.cursor.start;
          do {
            start++;
          }
          while (start < input.typed.length && input.typed[start - 1] !== ' ');
  
          end = start;
          break;
  
        default:
          start = input.cursor.start;
          end = input.cursor.end;
          break;
      }
  
      start = (start > input.typed.length) ? input.typed.length : start;
      end = (end > input.typed.length) ? input.typed.length : end;
  
      var newInput = {
        typed: input.typed,
        cursor: { start: start, end: end }
      };
  
      if (this.terminal.inputElement.selectionStart !== start) {
        this.terminal.inputElement.selectionStart = start;
      }
      if (this.terminal.inputElement.selectionEnd !== end) {
        this.terminal.inputElement.selectionEnd = end;
      }
  
      this.caretMoved(start);
  
      this._caretChange = null;
      return newInput;
    }
docs: If this._caretChange === Caret.TO_ARG_END, we alter the input object to move
  the selection start to the end of the current argument.
  @param input An object shaped like { typed:'', cursor: { start:0, end:0 }}