Ejemplo n.º 1
0
def history_cmd(ses, args, input):
    """
  #history prints the current history buffer.

  ! will call an item in the history indexed by the number after
  the !.  You can also do replacements via the sub=repl syntax.

  examples:
    #history [count=30]
        prints the last count entries in the history buffer
    !
        executes the last thing you did
    !4
        executes the fourth to last thing you did
    !4 3k=gk
        executes the fourth to last thing you did after replacing
        3k with gk in it

  category: commands
  """
    count = args["count"]

    historylist = exported.get_history(count)
    for i in range(0, len(historylist)):
        historylist[i] = "%d %s" % ((i + 1), historylist[i])
    historylist.reverse()
    exported.write_message("History:\n" + "\n".join(historylist))
Ejemplo n.º 2
0
def history_cmd(ses, args, input):
  """
  #history prints the current history buffer.

  ! will call an item in the history indexed by the number after
  the !.  You can also do replacements via the sub=repl syntax.

  examples:
    #history [count=30]
        prints the last count entries in the history buffer
    !
        executes the last thing you did
    !4
        executes the fourth to last thing you did
    !4 3k=gk
        executes the fourth to last thing you did after replacing
        3k with gk in it

  category: commands
  """
  count = args["count"]
  
  historylist = exported.get_history(count)
  for i in range(0, len(historylist)):
    historylist[i] = "%d %s" % ((i+1), historylist[i])
  historylist.reverse()
  exported.write_message("History:\n" + "\n".join(historylist))
Ejemplo n.º 3
0
 def insertPrevCommand(self, tkevent):
     """ Handles the <KeyPress-Up> event."""
     hist = exported.get_history()
     if self.hist_index == -1:
         self.current_input = self.get()
     if self.hist_index < len(hist) - 1:
         self.hist_index = self.hist_index + 1
         self.delete(0, "end")
         self.insert(0, hist[self.hist_index].decode(UNICODE_ENCODING))
Ejemplo n.º 4
0
 def insertPrevCommand(self, tkevent):
     """ Handles the <KeyPress-Up> event."""
     hist = exported.get_history()
     if self.hist_index == -1:
         self.current_input = self.get()
     if self.hist_index < len(hist) - 1:
         self.hist_index = self.hist_index + 1
         self.delete(0, 'end')
         self.insert(0, _decode(hist[self.hist_index]))
Ejemplo n.º 5
0
    def insertNextCommand(self, tkevent):
        """ Handles the <KeyPress-Down> event."""
        hist = exported.get_history()
        if self.hist_index == -1:
            return
        self.hist_index = self.hist_index - 1
        if self.hist_index == -1:
            self.delete(0, "end")
            self.insert(0, self.current_input.decode(UNICODE_ENCODING))

        else:
            self.delete(0, "end")
            self.insert(0, hist[self.hist_index].decode(UNICODE_ENCODING))
Ejemplo n.º 6
0
    def insertNextCommand(self, tkevent):
        """ Handles the <KeyPress-Down> event."""
        hist = exported.get_history()
        if self.hist_index == -1:
            return
        self.hist_index = self.hist_index - 1
        if self.hist_index == -1:
            self.delete(0, 'end')
            self.insert(0, _decode(self.current_input))

        else:
            self.delete(0, 'end')
            self.insert(0, _decode(hist[self.hist_index]))
Ejemplo n.º 7
0
  def do_command(self, ch):
    if ch == -1:
      pass
    if (ch & ~0xFF)==0 and (ascii.isprint(ch) or chr(ch) in string.letters):
      self.string_ = self.string_[:self.curx_]+chr(ch)+self.string_[self.curx_:]
      self.curx_ += 1
      self._align(1)
      self._reset()
    elif ch in (ascii.BS, ascii.DEL, curses.KEY_BACKSPACE):
      if self.curx_ > 0:
        self.curx_ -= 1
        self.string_ = self.string_[0:self.curx_] + self.string_[self.curx_+1:]
        self._align(1)
      self._reset()  
    elif ch == ascii.HT:
      newtext, newposition = self.ui_.get_completion(self.string_, self.curx_)
      self.set(newtext)
      self.curx_ = newposition
      self._align(1)
    elif ch in (ascii.SOH, curses.KEY_HOME): # ^a
      self.curx_ = 0
      self._align()
      self._reset()  
    elif ch in (ascii.STX, curses.KEY_LEFT): # ^b    
      if self.curx_ > 0:
        self.curx_ -= 1
        self._align()
      self._reset()  
    elif ch in (ascii.ACK, curses.KEY_RIGHT): # ^f
      if self.curx_ < len(self.string_):
        self.curx_ += 1
        self._align()
      self._reset()  
    elif ch in (ascii.EOT, curses.KEY_DC): # ^d
      if self.curx_ < len(self.string_):
        self.string_ = self.string_[0:self.curx_] + self.string_[self.curx_+1:]
        self._align(1)
      self._reset()  
    elif ch in (ascii.ENQ, curses.KEY_END): # ^e
      self.curx_ = len(self.string_)
      self._align()
      self._reset()  
    elif ch in (ascii.DLE, curses.KEY_UP): # ^p
      #
      # search the history back
      #
      if not self.history_:
        self.history_ = filter( lambda x: x.find(self.string_) != -1,
                                exported.get_history(1000) )
      if self.history_:
        found = self.history_[0]
        self.history_[0:1] = []
        self.history_.append(found)
        self.set( found )

    elif ch in (ascii.SO, curses.KEY_DOWN): # ^n
      #
      # search the history forward
      #
      if self.history_:
        self.history_.insert(0, self.history_.pop())
        self.set( self.history_[-1] )
    
    elif ch in (ascii.NAK,): # ^U
      #
      # Kill the line, reset the history search
      #
      self._reset()
      self.set("")

    # elif ch in (ascii.DLE,): # ^r
    #   pass

    elif ch in (ascii.CR, ascii.LF):
      #
      # reset the history search
      #
      self._reset()

    # elif ch == curses.KEY_RESIZE:
    #   pass

    return ch
Ejemplo n.º 8
0
    def do_command(self, ch):
        if ch == -1:
            pass
        if (ch & ~0xFF) == 0 and (ascii.isprint(ch)
                                  or chr(ch) in string.letters):
            self.string_ = self.string_[:self.curx_] + chr(
                ch) + self.string_[self.curx_:]
            self.curx_ += 1
            self._align(1)
            self._reset()
        elif ch in (ascii.BS, ascii.DEL, curses.KEY_BACKSPACE):
            if self.curx_ > 0:
                self.curx_ -= 1
                self.string_ = self.string_[0:self.
                                            curx_] + self.string_[self.curx_ +
                                                                  1:]
                self._align(1)
            self._reset()
        elif ch == ascii.HT:
            newtext, newposition = self.ui_.get_completion(
                self.string_, self.curx_)
            self.set(newtext)
            self.curx_ = newposition
            self._align(1)
        elif ch in (ascii.SOH, curses.KEY_HOME):  # ^a
            self.curx_ = 0
            self._align()
            self._reset()
        elif ch in (ascii.STX, curses.KEY_LEFT):  # ^b
            if self.curx_ > 0:
                self.curx_ -= 1
                self._align()
            self._reset()
        elif ch in (ascii.ACK, curses.KEY_RIGHT):  # ^f
            if self.curx_ < len(self.string_):
                self.curx_ += 1
                self._align()
            self._reset()
        elif ch in (ascii.EOT, curses.KEY_DC):  # ^d
            if self.curx_ < len(self.string_):
                self.string_ = self.string_[0:self.
                                            curx_] + self.string_[self.curx_ +
                                                                  1:]
                self._align(1)
            self._reset()
        elif ch in (ascii.ENQ, curses.KEY_END):  # ^e
            self.curx_ = len(self.string_)
            self._align()
            self._reset()
        elif ch in (ascii.DLE, curses.KEY_UP):  # ^p
            #
            # search the history back
            #
            if not self.history_:
                self.history_ = filter(lambda x: x.find(self.string_) != -1,
                                       exported.get_history(1000))
            if self.history_:
                found = self.history_[0]
                self.history_[0:1] = []
                self.history_.append(found)
                self.set(found)

        elif ch in (ascii.SO, curses.KEY_DOWN):  # ^n
            #
            # search the history forward
            #
            if self.history_:
                self.history_.insert(0, self.history_.pop())
                self.set(self.history_[-1])

        elif ch in (ascii.NAK, ):  # ^U
            #
            # Kill the line, reset the history search
            #
            self._reset()
            self.set("")

        # elif ch in (ascii.DLE,): # ^r
        #   pass

        elif ch in (ascii.CR, ascii.LF):
            #
            # reset the history search
            #
            self._reset()

        # elif ch == curses.KEY_RESIZE:
        #   pass

        return ch