From 8421581d967f5ad3639952dda35d7d13889e1612 Mon Sep 17 00:00:00 2001 From: Bob Farrell Date: Mon, 28 Apr 2008 23:41:22 +0100 Subject: [PATCH] Tab stuff is much better now. I added a thing so you can hit C-Backspace to go to the beginning of the line, and then I figured I should actually handle tabs properly, so that's what it does now. Hooray. I think it might break on other computers, oh well, too late now. --- bpython.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/bpython.py b/bpython.py index c93be35..865abc8 100644 --- a/bpython.py +++ b/bpython.py @@ -197,6 +197,7 @@ class Repl: self.f_string = '' self.matches = [] self.argspec = None + self.tablen = None self.s = '' if not OPTS.argspec: @@ -802,22 +803,30 @@ class Repl: def bs( self ): """Process a backspace""" -#TODO: All this curses code really ought to be somewhere else. :( y, x = self.scr.getyx() if x == self.ix and y == self.iy: return + n = 1 + if x == 0: y -= 1 x = gethw()[1] - if not self.cpos: + if not self.cpos: # I know the nested if blocks look nasty. :( + if self.s[-1] == '\t': + n = self.tablen + if len(self.s) > 1: + n = n * 2 + self.s = self.s[ : -1 ] else: self.s = self.s[ : -self.cpos-1 ] + self.s[ -self.cpos : ] - self.scr.delch( y, x - 1 ) + + for i in range(n): + self.scr.delch( y, x - n ) self.scr.refresh() def clrtobol( self ): @@ -838,6 +847,11 @@ class Repl: if self.c is None: return '' + if self.c == chr(8): # C-Backspace (on my computer anyway!) + self.clrtobol() + self.c = '\n' + # Don't return; let it get handled + if self.c in ( chr(127), 'KEY_BACKSPACE' ): self.bs() self.complete() @@ -904,9 +918,15 @@ class Repl: otherwise attempt to autocomplete to the best match of possible choices in the match list.""" + if self.tablen is None: + x = self.scr.getyx()[1] + if self.atbol(): self.addc( self.c ) self.print_line( self.s ) + if self.tablen is None: + self.tablen = self.scr.getyx()[1] - x + DEBUG( str(self.tablen) ) return True cw = self.cw()