From de4acf1891861e9097966103107ac940cf5cce0e Mon Sep 17 00:00:00 2001 From: John Ladan Date: Fri, 25 Oct 2013 16:07:34 -0400 Subject: [PATCH] Case insensitive searching; fixed column sorting --- browser.py | 15 +++++++++++---- help_bar.py | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/browser.py b/browser.py index 8251157..b554bf3 100644 --- a/browser.py +++ b/browser.py @@ -8,7 +8,8 @@ class browserWindow: topline = 0 entries = [] selected = list() - commands = [(' /', 'search'), (' n', 'find next'), (' N', 'find previous'), (' q', 'quit')] + commands = [(' /', 'search'), (' n', 'find next'), (' N', 'find previous'), + ('F6', 'Sort Column'), (' q', 'quit')] cs = [] # column definitions are in (label, weight, specified width) triples columnDefs = [('something',1,None)] @@ -25,9 +26,10 @@ class browserWindow: self.commands = self.cs+self.commands def sortByColumn(self, col): - self.entries.sort(key=lambda k: k.get(col)) # key=dict.get(col)) + self.entries.sort(key=lambda k: k.get(col,"")) # key=dict.get(col)) self.selected = list(map(lambda x: False, self.selected)) + def updateGeometry(self): (self.my,self.mx)=self.w.getmaxyx() (y,x) = self.w.getbegyx() @@ -121,12 +123,17 @@ class browserWindow: self.refresh() def search(self, string): + case_sensitive = not(string.islower()) + #sys.stderr.write(str(case_sensitive)+'\n') i = 0 found = False for e in self.entries: for k,v in e.items(): - if str(v).find(string) != -1: - found = True + # we or with found to make sure it is never "unfound" + if case_sensitive: + found = str(v).find(string) != -1 or found + else: + found = str(v).lower().find(string) != -1 or found if found: break i += 1; diff --git a/help_bar.py b/help_bar.py index af18358..fabe313 100644 --- a/help_bar.py +++ b/help_bar.py @@ -57,7 +57,7 @@ class helpBar: string = string[0:len(string)-1] self.w.addstr(0,1,string) elif ch>=32 and ch<=126: - char = curses.keyname(ch) + char = curses.keyname(ch).decode('utf-8') string = string + char self.w.addstr(0,1,string) self.w.refresh()