Skip to content

Commit

Permalink
Pass sorted commands to command_table function
Browse files Browse the repository at this point in the history
  • Loading branch information
elkinaguas committed Oct 17, 2023
1 parent 734fbe9 commit 4a82aad
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions clir/tools/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def get_commands():
return current_commands

def choose_command(commands: dict = {}):
command_table(commands=commands)
sorted_commands = dict(sorted(commands.items(), key=lambda item: item[1]["tag"]))
command_table(commands=sorted_commands)
command_id = Prompt.ask("Enter command ID")

try:
Expand All @@ -40,20 +40,17 @@ def choose_command(commands: dict = {}):


def command_table(commands: dict = {}):
# Current commands sorted by tag
sorted_commands = dict(sorted(commands.items(), key=lambda item: item[1]["tag"]))

table = Table(show_lines=True, box=box.ROUNDED, style="#7D7C7C")

table.add_column("ID", style="cyan", no_wrap=True)
table.add_column("Command", style="cyan", no_wrap=True)
table.add_column("Description", style="magenta")
table.add_column("Tag", style="green")

for indx, command in enumerate(sorted_commands):
for indx, command in enumerate(commands):
desc_len = 50
command_len = 50
description = sorted_commands[command]["description"]
description = commands[command]["description"]
split_description = "\n".join([description[i:i+desc_len] for i in range(0, len(description), desc_len)])
split_command = []
local_command = ""
Expand All @@ -67,11 +64,11 @@ def command_table(commands: dict = {}):
split_command.append(local_command)

display_command = " \ \n".join(split_command)
table.add_row(str(indx+1), display_command, split_description, sorted_commands[command]["tag"])
table.add_row(str(indx+1), display_command, split_description, commands[command]["tag"])

console = Console()
console.print(table)
print(f"Showing {str(len(sorted_commands))} commands")
print(f"Showing {str(len(commands))} commands")

def save_commands(command: str = "", desc: str = "", tag: str = ""):
current_commands = get_commands()
Expand Down

0 comments on commit 4a82aad

Please sign in to comment.