Skip to content

Commit 528c43c

Browse files
committed
Added scroll, case insensitivity
1 parent c02cecf commit 528c43c

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

icl.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def __init__(self):
9999
self.input_string=""
100100
self.all_entries = get_entries_from_file()
101101
self.matches = []
102+
self.start = 0
102103
self.selected_option_index = 0
103104

104105
self.screen = curses.initscr()
@@ -143,7 +144,10 @@ def _get_vertical_real_estate(self):
143144

144145

145146
def _match(self, entry, query):
146-
query_words = query.split()
147+
148+
# TODO later: smartcase
149+
entry=list(map(str.lower, entry))
150+
query_words = query.lower().split()
147151

148152
for word in query_words:
149153
if word not in entry[0] and word not in entry[1]:
@@ -161,7 +165,7 @@ def _search_suggestions(self, query_string):
161165

162166
screen_vertical_real_estate = self._get_vertical_real_estate()
163167

164-
for idx, match in enumerate(self.matches[:screen_vertical_real_estate]):
168+
for idx, match in enumerate(self.matches[self.start:self.start+screen_vertical_real_estate]):
165169
try:
166170
line_number = idx * 2 + 1
167171
if self.selected_option_index != idx:
@@ -204,12 +208,21 @@ def _handle_keypress(self, pressed_key):
204208

205209
elif pressed_key == curses.KEY_DOWN:
206210
screen_vertical_real_estate = self._get_vertical_real_estate()
207-
if self.selected_option_index < screen_vertical_real_estate - 1:
211+
212+
if self.start+ self.selected_option_index + 1 >= len(self.matches): # already at the bottom
213+
return
214+
if self.selected_option_index < screen_vertical_real_estate - 1: # visible page remains same but highlight the next
208215
self.selected_option_index += 1
216+
217+
else: # move the visible page down by 1 to highlight the next
218+
self.start+=1
209219

210220
elif pressed_key == curses.KEY_UP:
211221
if self.selected_option_index > 0:
212222
self.selected_option_index -= 1
223+
else:
224+
self.start-=min(self.start, 1)
225+
# todo later: scroll wrap
213226

214227
elif pressed_key == 27: # Exit on escape
215228
raise

0 commit comments

Comments
 (0)