Skip to content

Commit

Permalink
enhancements for latch workspace
Browse files Browse the repository at this point in the history
Signed-off-by: Ayush Kamat <[email protected]>
  • Loading branch information
ayushkamat committed Nov 27, 2023
1 parent 5269f99 commit 3beb63e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
18 changes: 11 additions & 7 deletions latch_cli/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
15 changes: 13 additions & 2 deletions latch_cli/services/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 3beb63e

Please sign in to comment.