Case insensitive searching; fixed column sorting

This commit is contained in:
John Ladan 2013-10-25 16:07:34 -04:00
parent 4b658477ea
commit de4acf1891
2 changed files with 12 additions and 5 deletions

View File

@ -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;

View File

@ -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()