-
Notifications
You must be signed in to change notification settings - Fork 0
Mra/feat launcher #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b6751c1
feat(launcher): add quick launch tui base
Mael-RABOT a87f532
evol(launcher): config
Mael-RABOT 83bb148
evol(launcher): tmux support
Mael-RABOT 57160c5
evol(launcher): QoL
Mael-RABOT 3e632e3
fix(launcher): remove exit to force launcher flow
Mael-RABOT 0c260b2
evol(docs): dev doc, readme & rqt tool
Mael-RABOT 6251427
feat(tui): encapsulate install.sh in tui
Mael-RABOT b8b1b84
evol(Lucy.py): add windows support
Mael-RABOT 96cda4e
evol(Lucy.py): update windows support & build in CI
Mael-RABOT 057c158
devops(CICD): load .exe in releases
Mael-RABOT 34e0e90
fix(windows): add x server support
Mael-RABOT 1eb7670
fix(QA): updt UX/UI
Mael-RABOT 620fc3a
evol(QA): UI/UX
Mael-RABOT 5935f40
fix(QA): dynamic term size assert
Mael-RABOT ca3b9d7
fix(QA): avoid useless core reload
Mael-RABOT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ __pycache__/ | |
| # IDE / OS | ||
| .idea/ | ||
| .vscode/ | ||
| .vs/ | ||
| .DS_Store | ||
| *~ | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import curses | ||
| import os | ||
| import subprocess | ||
| import sys | ||
|
|
||
| MIN_TERM_HEIGHT = 15 | ||
| MIN_TERM_WIDTH = 65 | ||
|
|
||
| def get_dev_mode(): | ||
| if not os.path.exists(".env"): | ||
| return False | ||
| with open(".env", "r") as f: | ||
| for line in f: | ||
| if line.strip().startswith("DEV="): | ||
| return line.strip().split("=")[1].lower() == "true" | ||
| return False | ||
|
|
||
| def set_dev_mode(is_enabled): | ||
| lines = [] | ||
| dev_found = False | ||
| if os.path.exists(".env"): | ||
| with open(".env", "r") as f: | ||
| lines = f.readlines() | ||
|
|
||
| with open(".env", "w") as f: | ||
| for line in lines: | ||
| if line.strip().startswith("DEV="): | ||
| f.write(f"DEV={str(is_enabled).lower()}\n") | ||
| dev_found = True | ||
| else: | ||
| f.write(line) | ||
| if not dev_found: | ||
| f.write(f"DEV={str(is_enabled).lower()}\n") | ||
|
|
||
| def run_command(command, interactive=False): | ||
| """Runs a command. | ||
|
|
||
| If interactive is True, runs natively in the terminal. | ||
| """ | ||
| print(f"--- Running: {' '.join(command)} ---") | ||
| try: | ||
| if interactive: | ||
| # Inherit standard IO to maintain terminal size and TTY functionality | ||
| return subprocess.run(command).returncode | ||
| else: | ||
| # Popen is fine for non-interactive scripts like install/build | ||
| process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) | ||
| while True: | ||
| output = process.stdout.readline() | ||
| if output == '' and process.poll() is not None: | ||
| break | ||
| if output: | ||
| print(output.strip()) | ||
| return process.poll() | ||
|
|
||
| except FileNotFoundError: | ||
| print(f"Error: Command '{command[0]}' not found. Make sure it's in your PATH and executable.") | ||
| return -1 | ||
| except Exception as e: | ||
| print(f"An error occurred: {e}") | ||
| return -1 | ||
|
|
||
| def main_tui(stdscr): | ||
| """The main curses TUI function. Returns the command to run.""" | ||
| h, w = stdscr.getmaxyx() | ||
| if h < MIN_TERM_HEIGHT or w < MIN_TERM_WIDTH: | ||
| return "TerminalTooSmall" | ||
|
|
||
| curses.curs_set(0) | ||
| stdscr.nodelay(0) | ||
| stdscr.timeout(-1) | ||
| curses.start_color() | ||
| curses.use_default_colors() | ||
| curses.init_pair(1, curses.COLOR_CYAN, -1) | ||
|
|
||
| is_dev_mode = get_dev_mode() | ||
| current_idx = 0 | ||
| options = ["Launch", "---", "Install/Update", "Rebuild", "Exit", "---", "Developer Mode"] | ||
|
|
||
| while True: | ||
| stdscr.clear() | ||
| h, w = stdscr.getmaxyx() | ||
| title = "Lucy Workspace Manager" | ||
| stdscr.addstr(0, max(0, (w - len(title)) // 2), title, curses.A_BOLD) | ||
|
|
||
| for i, option in enumerate(options): | ||
| if option == "---": | ||
| stdscr.addstr(2 + i, 4, "----------------------") | ||
| continue | ||
|
|
||
| prefix = "> " if current_idx == i else " " | ||
|
|
||
| if option == "Developer Mode": | ||
| checkbox = "[x]" if is_dev_mode else "[ ]" | ||
| stdscr.addstr(2 + i, 4, f"{prefix}{checkbox} {option}") | ||
| else: | ||
| stdscr.addstr(2 + i, 4, f"{prefix}{option}") | ||
|
|
||
| stdscr.addstr(h - 2, 2, "Enter/Space: Select/Toggle | Up/Down: Navigate", curses.A_DIM) | ||
| stdscr.refresh() | ||
|
|
||
| key = stdscr.getch() | ||
|
|
||
| if key == curses.KEY_UP: | ||
| current_idx = (current_idx - 1 + len(options)) % len(options) | ||
| if options[current_idx] == "---": | ||
| current_idx = (current_idx - 1 + len(options)) % len(options) | ||
| elif key == curses.KEY_DOWN: | ||
| current_idx = (current_idx + 1) % len(options) | ||
| if options[current_idx] == "---": | ||
| current_idx = (current_idx + 1) % len(options) | ||
| elif key in [ord(' '), ord('\n')]: | ||
| selected_option = options[current_idx] | ||
|
|
||
| if selected_option == "Developer Mode": | ||
| is_dev_mode = not is_dev_mode | ||
| set_dev_mode(is_dev_mode) | ||
| elif selected_option == "Install/Update": | ||
| return {"cmd": ["./install.sh"], "interactive": False, "name": "Install"} | ||
| elif selected_option == "Rebuild": | ||
| return {"cmd": ["./install.sh", "--build-only"], "interactive": False, "name": "Rebuild"} | ||
| elif selected_option == "Launch": | ||
| return {"cmd": ["./launch_lucy.sh"], "interactive": True, "name": "Launch"} | ||
| elif selected_option == "Exit": | ||
| return None | ||
|
|
||
| if __name__ == "__main__": | ||
| # This initial check is done before curses.wrapper to provide a clean error message | ||
| # without the screen flicker of initializing and de-initializing curses. | ||
| def check_initial_size(): | ||
| stdscr = curses.initscr() | ||
| h, w = stdscr.getmaxyx() | ||
| curses.endwin() | ||
| return h >= MIN_TERM_HEIGHT and w >= MIN_TERM_WIDTH | ||
|
|
||
| if not check_initial_size(): | ||
| print("Error: Terminal window is too small.", file=sys.stderr) | ||
| print(f"Please increase the terminal size to at least {MIN_TERM_WIDTH}x{MIN_TERM_HEIGHT} characters.", file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
| while True: | ||
| task = None | ||
| try: | ||
| task = curses.wrapper(main_tui) | ||
| except KeyboardInterrupt: | ||
| print("\nExiting.") | ||
| sys.exit(0) | ||
| except curses.error as e: | ||
| print(f"A terminal error occurred: {e}", file=sys.stderr) | ||
| print("This might be due to resizing the window. Please restart.", file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
| if isinstance(task, str) and task == "TerminalTooSmall": | ||
| # This case is handled by the pre-check, but as a fallback. | ||
| print("Error: Terminal window is too small.", file=sys.stderr) | ||
| print(f"Please increase the terminal size to at least {MIN_TERM_WIDTH}x{MIN_TERM_HEIGHT} characters.", file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
| if not task: | ||
| # User selected Exit | ||
| break | ||
|
|
||
| rc = run_command(task["cmd"], interactive=task.get("interactive", False)) | ||
|
|
||
| if task.get("interactive", False): | ||
| print(f"--- Session finished with exit code {rc} ---") | ||
| break | ||
|
|
||
| task_name = task.get("name") | ||
| if task_name in ["Install", "Rebuild"] and rc == 0: | ||
| print(f"\n--- Task '{task_name}' finished successfully. ---") | ||
| print("Press Enter to return to the menu.") | ||
| input() | ||
| else: | ||
| print(f"\n--- Task '{task_name}' finished with exit code {rc} ---") | ||
| print("Press Enter to exit.") | ||
| input() | ||
| break | ||
|
|
||
| sys.exit(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.