X-Git-Url: https://git.sthu.org/?a=blobdiff_plain;f=DbgTerminal.py;h=6b09426a0698313742ed85402b441cdf4b715c67;hb=505db8dd1b2862d460c7442e98c0c14ac776a4db;hp=e9a706fffcdb793ba81e7d3d027ef48d010d1c39;hpb=66662457f7e6cfc95de535503aa1f4b088822d2f;p=pygdb.git diff --git a/DbgTerminal.py b/DbgTerminal.py index e9a706f..6b09426 100644 --- a/DbgTerminal.py +++ b/DbgTerminal.py @@ -26,8 +26,9 @@ class DbgTerminal (vte.Terminal): #Set members self.childpid = None - self.history = [] + self.history = [""] self.isactive = True + self.lastc, self.lastr = 0,0 #Start debugger self.clientCmd = clientCmd @@ -58,25 +59,22 @@ class DbgTerminal (vte.Terminal): def contents_changed(self, term): + assert( self.getHistoryLen()>0 ) + c,r = term.get_cursor_position() - text = self.get_text_range(max(self.getHistoryLen()-1,0),0,r,-1,lambda *w:True) + text = self.get_text_range(self.lastr,self.lastc,r,c-1,lambda *w:True) + self.lastc, self.lastr = c,r #Remove annoying \n at the end assert(text[-1] == "\n") text = text[:-1] - #Remove the incomplete line - if self.getHistoryLen()>0 and self.history[-1]!='\n': - del self.history[-1] - #Get the lines and remove empty lines lines = string.split(text, "\n") - #Add lines to history. The last line contains no "\n" at the end! - self.history += [l+"\n" for l in lines[:-1]] - self.history += [lines[-1]] - - assert(r == self.getHistoryLen()-1) + #Remove the incomplete line + self.history[-1] += lines[0] + self.history += lines[1:] def waitForNewline(self): @@ -88,16 +86,16 @@ class DbgTerminal (vte.Terminal): return len(self.history) def waitForRx(self, rx, start): - curr = start - while True: - for no in range(max(curr-1,start), self.getHistoryLen()): + assert( curr>=start ) + for no in range(curr, self.getHistoryLen()): line = self.history[no] if rx.search(line): return no, line - curr = max(start,self.getHistoryLen()) + #Do not forget the last line + curr = max(start,self.getHistoryLen()-1) gtk.main_iteration() @@ -150,7 +148,6 @@ def quitHandler(*w): gtk.main_quit() except: pass - sys.exit(0)