-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
33 lines (27 loc) · 1 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import json
import curses
import subprocess
def run_command(command):
try:
subprocess.run(command, shell=True, check=True)
except subprocess.CalledProcessError as e:
print(f"Command '{command}' failed with error: {e}")
def load_config(filename):
with open(filename, 'r') as file:
return json.load(file)
def apply_custom_colors(stdscr):
curses.start_color()
curses.use_default_colors()
curses.init_pair(1, 0, 15)
curses.init_pair(2, -1, -1)
def handle_keys(stdscr, key, items, current_row):
if key == curses.KEY_UP or key == ord('k'):
current_row = (current_row - 1) % len(items)
elif key == curses.KEY_DOWN or key == ord('j'):
current_row = (current_row + 1) % len(items)
elif key == ord('q') or key == ord('Q'):
return 'quit', current_row
elif key == curses.KEY_ENTER or key in [10, 13, ord(' ')]:
selected_item = items[current_row]
return selected_item['command'], current_row
return None, current_row