From 3beb63e3a97cf9d10925847c801f387078503d27 Mon Sep 17 00:00:00 2001 From: Ayush Kamat Date: Mon, 27 Nov 2023 15:44:59 -0800 Subject: [PATCH] enhancements for latch workspace Signed-off-by: Ayush Kamat --- latch_cli/menus.py | 18 +++++++++++------- latch_cli/services/workspace.py | 15 +++++++++++++-- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/latch_cli/menus.py b/latch_cli/menus.py index 70cebed9..e845cfcb 100644 --- a/latch_cli/menus.py +++ b/latch_cli/menus.py @@ -226,10 +226,13 @@ def render( break name = options[i] if i == curr_selected: - color = "\x1b[38;5;40m" + color = "\x1b[38;5;39m" bold = "\x1b[1m" reset = "\x1b[0m" - _print(f"{indent}{color}{bold}{name}{reset}\x1b[1E") + + prefix = indent[:-2] + "> " + + _print(f"{color}{bold}{prefix}{name}{reset}\x1b[1E") else: _print(f"{indent}{name}\x1b[1E") num_lines_rendered += 1 @@ -252,13 +255,14 @@ def render( _, term_height = os.get_terminal_size() remove_cursor() - if not clear_terminal: - _, curs_height = current_cursor_position() - max_per_page = term_height - curs_height - 4 - else: + max_per_page = min(len(options), term_height - 4) + + if clear_terminal: clear_screen() move_cursor((0, 0)) - max_per_page = term_height - 4 + else: + print("\n" * (max_per_page + 3)) + move_cursor_up(max_per_page + 4) num_lines_rendered = render( curr_selected, diff --git a/latch_cli/services/workspace.py b/latch_cli/services/workspace.py index 0bb9e11c..8746d07e 100644 --- a/latch_cli/services/workspace.py +++ b/latch_cli/services/workspace.py @@ -30,25 +30,36 @@ def workspace(): data = _get_workspaces() ids = {} + old_id = current_workspace() + + selected_marker = "\x1b[3m\x1b[2m (currently selected) \x1b[22m\x1b[23m" + for id, name in sorted( - data.items(), key=lambda x: "" if x[1] == "Personal Workspace" else x[1] + data.items(), key=lambda x: "" if x[1] == "Personal Workspace" else x[0] ): + if id == old_id: + name = f"{name}{selected_marker}" + ids[name] = id options.append(name) selected_option = select_tui( title="Select Workspace", options=options, + clear_terminal=False, ) if selected_option is None: return new_id = ids[selected_option] + user_config.update_workspace(new_id, selected_option) - old_id = current_workspace() if old_id != new_id: click.secho(f"Successfully switched to context {selected_option}", fg="green") else: + if selected_option.endswith(selected_marker): + selected_option = selected_option.replace(selected_marker, "") + click.secho(f"Already in context {selected_option}.", fg="green")