mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-03-10 08:29:00 +00:00
Update selector.py
This commit is contained in:
@@ -8,7 +8,8 @@ from rich.text import Text
|
||||
from unshackle.core.console import console
|
||||
|
||||
IS_WINDOWS = sys.platform == "win32"
|
||||
if IS_WINDOWS: import msvcrt
|
||||
if IS_WINDOWS:
|
||||
import msvcrt
|
||||
|
||||
class Selector:
|
||||
"""
|
||||
@@ -133,7 +134,8 @@ class Selector:
|
||||
|
||||
total_visible = len(visible_indices)
|
||||
total_pages = (total_visible + self.page_size - 1) // self.page_size
|
||||
if total_pages == 0: total_pages = 1
|
||||
if total_pages == 0:
|
||||
total_pages = 1
|
||||
current_page = (self.scroll_offset // self.page_size) + 1
|
||||
|
||||
if self.dependencies:
|
||||
@@ -211,23 +213,15 @@ class Selector:
|
||||
else:
|
||||
self.selected_indices.difference_update(target_indices)
|
||||
|
||||
def toggle_expand(self, expand: bool = None):
|
||||
def toggle_expand(self):
|
||||
"""
|
||||
Expands or collapses the current header.
|
||||
Args:
|
||||
expand: True to expand, False to collapse, None to toggle.
|
||||
"""
|
||||
if self.cursor_index in self.dependencies:
|
||||
if expand is None:
|
||||
if self.cursor_index in self.expanded_headers:
|
||||
self.expanded_headers.remove(self.cursor_index)
|
||||
else:
|
||||
self.expanded_headers.add(self.cursor_index)
|
||||
elif expand:
|
||||
self.expanded_headers.add(self.cursor_index)
|
||||
if self.cursor_index in self.expanded_headers:
|
||||
self.expanded_headers.remove(self.cursor_index)
|
||||
else:
|
||||
if self.cursor_index in self.expanded_headers:
|
||||
self.expanded_headers.remove(self.cursor_index)
|
||||
self.expanded_headers.add(self.cursor_index)
|
||||
|
||||
def toggle_expand_all(self):
|
||||
"""
|
||||
@@ -265,10 +259,14 @@ class Selector:
|
||||
if key == b"\xe0" or key == b"\x00":
|
||||
try:
|
||||
key = msvcrt.getch()
|
||||
if key == b"H": return "UP" # Arrow Up
|
||||
if key == b"P": return "DOWN" # Arrow Down
|
||||
if key == b"K": return "LEFT" # Arrow Left
|
||||
if key == b"M": return "RIGHT" # Arrow Right
|
||||
if key == b"H": # Arrow Up
|
||||
return "UP"
|
||||
if key == b"P": # Arrow Down
|
||||
return "DOWN"
|
||||
if key == b"K": # Arrow Left
|
||||
return "LEFT"
|
||||
if key == b"M": # Arrow Right
|
||||
return "RIGHT"
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -277,16 +275,26 @@ class Selector:
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
if char in ("\r", "\n"): return "ENTER"
|
||||
if char == " ": return "SPACE"
|
||||
if char in ("q", "Q"): return "QUIT"
|
||||
if char in ("a", "A"): return "ALL"
|
||||
if char == "e": return "EXPAND"
|
||||
if char == "E": return "EXPAND_ALL"
|
||||
if char in ("w", "W", "k", "K"): return "UP"
|
||||
if char in ("s", "S", "j", "J"): return "DOWN"
|
||||
if char in ("h", "H"): return "LEFT"
|
||||
if char in ("d", "D", "l", "L"): return "RIGHT"
|
||||
if char in ("\r", "\n"):
|
||||
return "ENTER"
|
||||
if char == " ":
|
||||
return "SPACE"
|
||||
if char in ("q", "Q"):
|
||||
return "QUIT"
|
||||
if char in ("a", "A"):
|
||||
return "ALL"
|
||||
if char == "e":
|
||||
return "EXPAND"
|
||||
if char == "E":
|
||||
return "EXPAND_ALL"
|
||||
if char in ("w", "W", "k", "K"):
|
||||
return "UP"
|
||||
if char in ("s", "S", "j", "J"):
|
||||
return "DOWN"
|
||||
if char in ("h", "H"):
|
||||
return "LEFT"
|
||||
if char in ("d", "D", "l", "L"):
|
||||
return "RIGHT"
|
||||
return None
|
||||
|
||||
def get_input_unix(self):
|
||||
@@ -313,24 +321,38 @@ class Selector:
|
||||
next1 = click.getchar()
|
||||
if next1 in ("[", "O"): # Sequence indicators
|
||||
next2 = click.getchar()
|
||||
if next2 == "A": return "UP" # Arrow Up
|
||||
if next2 == "B": return "DOWN" # Arrow Down
|
||||
if next2 == "C": return "RIGHT" # Arrow Right
|
||||
if next2 == "D": return "LEFT" # Arrow Left
|
||||
if next2 == "A": # Arrow Up
|
||||
return "UP"
|
||||
if next2 == "B": # Arrow Down
|
||||
return "DOWN"
|
||||
if next2 == "C": # Arrow Right
|
||||
return "RIGHT"
|
||||
if next2 == "D": # Arrow Left
|
||||
return "LEFT"
|
||||
return "CANCEL"
|
||||
except Exception:
|
||||
return "CANCEL"
|
||||
|
||||
if char in ("\r", "\n"): return "ENTER"
|
||||
if char == " ": return "SPACE"
|
||||
if char in ("q", "Q"): return "QUIT"
|
||||
if char in ("a", "A"): return "ALL"
|
||||
if char == "e": return "EXPAND"
|
||||
if char == "E": return "EXPAND_ALL"
|
||||
if char in ("w", "W", "k", "K"): return "UP"
|
||||
if char in ("s", "S", "j", "J"): return "DOWN"
|
||||
if char in ("h", "H"): return "LEFT"
|
||||
if char in ("d", "D", "l", "L"): return "RIGHT"
|
||||
if char in ("\r", "\n"):
|
||||
return "ENTER"
|
||||
if char == " ":
|
||||
return "SPACE"
|
||||
if char in ("q", "Q"):
|
||||
return "QUIT"
|
||||
if char in ("a", "A"):
|
||||
return "ALL"
|
||||
if char == "e":
|
||||
return "EXPAND"
|
||||
if char == "E":
|
||||
return "EXPAND_ALL"
|
||||
if char in ("w", "W", "k", "K"):
|
||||
return "UP"
|
||||
if char in ("s", "S", "j", "J"):
|
||||
return "DOWN"
|
||||
if char in ("h", "H"):
|
||||
return "LEFT"
|
||||
if char in ("d", "D", "l", "L"):
|
||||
return "RIGHT"
|
||||
return None
|
||||
|
||||
def run(self) -> list[int]:
|
||||
@@ -359,7 +381,7 @@ class Selector:
|
||||
elif action == "RIGHT":
|
||||
self.change_page(1)
|
||||
elif action == "EXPAND":
|
||||
self.toggle_expand(expand=None)
|
||||
self.toggle_expand()
|
||||
elif action == "EXPAND_ALL":
|
||||
self.toggle_expand_all()
|
||||
elif action == "SPACE":
|
||||
@@ -374,7 +396,6 @@ class Selector:
|
||||
except KeyboardInterrupt:
|
||||
return []
|
||||
|
||||
|
||||
def select_multiple(
|
||||
options: list[str],
|
||||
minimal_count: int = 1,
|
||||
|
||||
Reference in New Issue
Block a user