- commit
- 2d2fee5265b9dd4fa90701cfc722164fff9dcb01
- parent
- 7cb9b89a80fd0ee647dd41dd7e1a93d86f124ab1
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2020-09-03 16:53
add filter search
Diffstat
| M | cplay.py | 41 | +++++++++++++++++++++++++++++++++++------ |
1 files changed, 35 insertions, 6 deletions
diff --git a/cplay.py b/cplay.py
@@ -38,6 +38,7 @@ q, Q : quit 38 38 Filelist 39 39 -------- 40 40 a : add to playlist -1 41 s : recursive search 41 42 BS : go to parent dir 42 43 43 44 Playlist @@ -306,32 +307,55 @@ class HelpList(List): 306 307 class Filelist(List): 307 308 def __init__(self): 308 309 super().__init__() -1 310 self.input = Input() 309 311 self.set_path(os.getcwd()) 310 312 311 313 def get_title(self):312 -1 return 'Filelist: %s/' % self.path.rstrip('/')-1 314 title = 'Filelist: %s/' % self.path -1 315 if self.input.str: -1 316 title += 'search "%s"/' % self.input.str -1 317 return title 313 318 314 319 def set_path(self, path, prev=None): 315 320 self.path = path316 -1 self.items = []-1 321 self.all_items = [] -1 322 self.input.str = '' 317 323 318 324 for p, is_dir in listdir(path): 319 325 ext = p.rsplit('.', 1)[-1] 320 326 if is_dir or ext == 'm3u' or ext in AUDIO_EXTENSIONS:321 -1 self.items.append(p)-1 327 self.all_items.append(p) 322 328323 -1 if prev:-1 329 self.items = self.all_items -1 330 -1 331 if prev and prev in self.items: 324 332 self.set_cursor(self.items.index(prev)) 325 333 else: 326 334 self.position = 0 327 335 self.cursor = 0 328 336 -1 337 def filter(self, query): -1 338 if query: -1 339 self.items = [] -1 340 for path in self.all_items: -1 341 if query.lowwer() in self.format_item(path).lower(): -1 342 self.items.append(path) -1 343 else: -1 344 self.items = self.all_items -1 345 -1 346 self.set_cursor(self.cursor) -1 347 329 348 def process_key(self, key):330 -1 if key == 'a':-1 349 if self.input.process_key(key): -1 350 self.filter(self.input.str) -1 351 elif key == 'a': 331 352 if not self.items: 332 353 return True 333 354 if playlist.add(self.items[self.cursor]): 334 355 self.move_cursor(1) -1 356 elif key == 's': -1 357 self.input.active = True -1 358 self.filter(self.input.str) 335 359 elif key == '\n': 336 360 if not self.items: 337 361 return True @@ -343,7 +367,10 @@ class Filelist(List): 343 367 playlist.active = -1 344 368 player.play(item) 345 369 elif key == curses.KEY_BACKSPACE:346 -1 self.set_path(os.path.dirname(self.path), prev=self.path)-1 370 if self.input.str: -1 371 self.set_path(self.path) -1 372 else: -1 373 self.set_path(os.path.dirname(self.path), prev=self.path) 347 374 else: 348 375 return super().process_key(key) 349 376 return True @@ -546,6 +573,8 @@ class Application: 546 573 547 574 if self.input.active: 548 575 status = '/%s' % self.input.str -1 576 elif self.tab == filelist and filelist.input.active: -1 577 status = 'search: %s' % filelist.input.str 549 578 elif player.path and player._proc: 550 579 status = 'Playing %s' % os.path.relpath(player.path, filelist.path) 551 580 else: