Skip to content

Commit de8ebfd

Browse files
authored
Headers are added in a table view (#102)
1 parent c3639ab commit de8ebfd

File tree

5 files changed

+56
-20
lines changed

5 files changed

+56
-20
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ Settings are stored at `~/.config/mud/settings.ini`.
9595
| `run_async` | `True`/`False` | enables asynchronous commands. |
9696
| `run_table` | `True`/`False` | enables table view for asynchronous commands. Requires `run_async`. |
9797
| `nerd_fonts` | `True`/`False` | enables nerd fonts in the output. |
98-
| `show_borders` | `True`/`False` | enables borders in the table view. |
98+
| `display_borders` | `True`/`False` | enables borders in the table view. |
99+
| `display_headers` | `True`/`False` | enables headers in the table view. |
100+
| `display_absolute_paths` | `True`/`False` | displays absolute paths for directories. |
99101
| `round_corners` | `True`/`False` | enables round corners for the table view. Requires `show_borders` to be enabled. |
100102
| `collapse_paths` | `True`/`False` | simplifies branch names in the branch view. |
101-
| `display_absolute_paths` | `True`/`False` | displays absolute paths for directories. |
102103
| `config_path` | `~/Documents/.mudconfig` | this is set by the `mud set-global` command. |
103104

104105
### Aliases

src/mud/runner.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,15 @@ def get_git_origin_host_icon(url: str) -> str:
5858
else:
5959
return YELLOW + glyphs('git') + RESET
6060

61-
table: PrettyTable = utils.get_table(['Path', 'Commits', 'User Commits', 'Size', 'Labels'])
62-
table.align['Commits'] = 'r'
63-
table.align['User Commits'] = 'r'
64-
table.align['Size'] = 'r'
61+
table: PrettyTable = utils.get_table([
62+
f'{YELLOW}{glyphs('git-repo')}{glyphs('space')}{RESET}Directory',
63+
f'{BLUE}{glyphs('commit')}{glyphs('space')}{RESET}Commits',
64+
f'{BLUE}{glyphs('commit')}{glyphs('space')}{RESET}User Commits',
65+
f'{MAGENTA}{glyphs('weight')}{glyphs('space')}{RESET}Size',
66+
f'{MAGENTA}{glyphs('labels')}{glyphs('space')}{RESET}Labels'])
67+
table.align[f'{BLUE}{glyphs('commit')}{glyphs('space')}{RESET}Commits'] = 'r'
68+
table.align[f'{BLUE}{glyphs('commit')}{glyphs('space')}{RESET}User Commits'] = 'r'
69+
table.align[f'{MAGENTA}{glyphs('weight')}{glyphs('space')}{RESET}Size'] = 'r'
6570

6671
for path, labels in repos.items():
6772
repo = Repository(path)
@@ -91,7 +96,12 @@ def get_git_origin_host_icon(url: str) -> str:
9196

9297
# `mud status` command implementation
9398
def status(self, repos: Dict[str, List[str]]) -> None:
94-
table = utils.get_table(['Path', 'Branch', 'Origin Sync', 'Status', 'Edits'])
99+
table = utils.get_table([
100+
f'{YELLOW}{glyphs('git-repo')}{glyphs('space')}{RESET}Directory',
101+
f'{GREEN}{glyphs('branch')}{glyphs('space')}{RESET}Branch',
102+
f'{CYAN}{glyphs('origin-sync')}{glyphs('space')}{RESET}Origin Sync',
103+
f'{BRIGHT_YELLOW}{glyphs('info')}{glyphs('space')}{RESET}Status',
104+
f'{BRIGHT_GREEN}{glyphs('git-modified')}{glyphs('space')}{RESET}Modified Files'])
95105

96106
for path, labels in repos.items():
97107
repo = Repository(os.path.abspath(path))
@@ -122,7 +132,9 @@ def status(self, repos: Dict[str, List[str]]) -> None:
122132

123133
# `mud labels` command implementation
124134
def labels(self, repos: Dict[str, List[str]]) -> None:
125-
table = utils.get_table(['Path', 'Labels'])
135+
table = utils.get_table([
136+
f'{YELLOW}{glyphs('git-repo')}{glyphs('space')}{RESET}Directory',
137+
f'{MAGENTA}{glyphs('labels')}{glyphs('space')}{RESET}Labels'])
126138

127139
for path, labels in repos.items():
128140
formatted_path = self._get_formatted_path(path)
@@ -133,7 +145,13 @@ def labels(self, repos: Dict[str, List[str]]) -> None:
133145

134146
# `mud log` command implementation
135147
def log(self, repos: Dict[str, List[str]]) -> None:
136-
table = utils.get_table(['Path', 'Branch', 'Hash', 'Author', 'Time', 'Message'])
148+
table = utils.get_table([
149+
f'{YELLOW}{glyphs('git-repo')}{glyphs('space')}{RESET}Directory',
150+
f'{GREEN}{glyphs('branch')}{glyphs('space')}{RESET}Branch',
151+
f'{BRIGHT_YELLOW}{glyphs('hash')}{glyphs('space')}{RESET}Hash',
152+
f'{BRIGHT_GREEN}{glyphs('author')}{glyphs('space')}{RESET}Author',
153+
f'{BRIGHT_CYAN}{glyphs('time')}{glyphs('space')}{RESET}Time',
154+
f'{BRIGHT_BLUE}{glyphs('message')}{glyphs('space')}{RESET}Message'])
137155

138156
for path in repos.keys():
139157
repo = Repository(path)
@@ -156,7 +174,9 @@ def log(self, repos: Dict[str, List[str]]) -> None:
156174

157175
# `mud branch` command implementation
158176
def branches(self, paths: Dict[str, List[str]], remote: bool) -> None:
159-
table = utils.get_table(['Path', 'Branches'])
177+
table = utils.get_table([
178+
f'{YELLOW}{glyphs('git-repo')}{glyphs('space')}{RESET}Directory',
179+
f'{BLUE}{glyphs('branch')}{glyphs('space')}{RESET}Branches'])
160180
all_branches = {}
161181
repos = [[path, Repository(path)] for path in paths]
162182
prefix = 'refs/remotes/' if remote else 'refs/heads/'
@@ -187,7 +207,6 @@ def branches(self, paths: Dict[str, List[str]], remote: bool) -> None:
187207
# `mud tags` command implementation
188208
def tags(self, repos: Dict[str, List[str]]) -> None:
189209
COLORS = [196, 202, 208, 214, 220, 226, 118, 154, 190, 33, 39, 45, 51, 87, 93, 99, 105, 111, 27, 63, 69, 75, 81, 87, 123, 129, 135, 141, 147, 183, 189, 225]
190-
191210
tag_colors = {}
192211

193212
def assign_color(tag: str) -> str:
@@ -196,7 +215,9 @@ def assign_color(tag: str) -> str:
196215
tag_colors[tag] = f'\033[38;5;{color_code}m'
197216
return tag_colors[tag]
198217

199-
table = utils.get_table(['Path', 'Tags'])
218+
table = utils.get_table([
219+
f'{YELLOW}{glyphs('git-repo')}{glyphs('space')}{RESET}Directory',
220+
f'{BRIGHT_BLUE}{glyphs('tags')}{glyphs('space')}{RESET}Tags'])
200221

201222
for path, labels in repos.items():
202223
repo = Repository(path)
@@ -282,7 +303,8 @@ async def _run_process(self, path: str, table: Dict[str, List[str]], command: st
282303
self._print_process(table)
283304

284305
def _print_process(self, info: Dict[str, List[str]]) -> None:
285-
table: PrettyTable = utils.get_table(['Path', 'Status', 'Output'])
306+
table = utils.get_table([f'{YELLOW}{glyphs('git-repo')}{glyphs('space')}{RESET}Directory', f'{BRIGHT_YELLOW}{glyphs('info')}{glyphs('space')}{RESET}Status', 'Output'])
307+
table.header = False
286308
for path, (line, status) in info.items():
287309
formatted_path = self._get_formatted_path(path)
288310
table.add_row([formatted_path, status, line])

src/mud/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def __init__(self, file_name: str, old_file_name: str) -> None:
2121
'nerd_fonts': True,
2222
'run_async': True,
2323
'run_table': True,
24-
'show_borders': True,
24+
'display_header': True,
25+
'display_borders': True,
2526
'round_corners': False,
2627
'simplify_branches': True,
2728
'display_absolute_paths': False

src/mud/styles.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@
8282
'failed': ['\uf00d', 'Failed'],
8383
'finished': ['\uf00c', 'Finished'],
8484
'running': ['\uf46a', 'Running'],
85-
'label': ['\uf435', ''],
85+
'label': ['\uf041', ''],
86+
'labels': ['\uf041', ''],
8687
'tag': ['\uf02b', '>'],
88+
'tags': ['\uf02c', ''],
8789
'terminal': ['\ue795', ''],
8890
'directory': ['\uf4d4', ''],
8991
'(': ['\uE0B2', ''],
@@ -94,5 +96,13 @@
9496
'github': ['\uf09b', ''],
9597
'gitlab': ['\uf296', ''],
9698
'azure': ['\uebe8', ''],
97-
'bitbucket': ['\ue703', '']
99+
'bitbucket': ['\ue703', ''],
100+
'git-repo': ['\ue5fb', ''],
101+
'git-modified': ['\uf05f', ''],
102+
'hash': ['\uf4df', ''],
103+
'author': ['\uf4ff', ''],
104+
'time': ['\uf017', ''],
105+
'message': ['\uf27a', ''],
106+
'info': ['\uf05a', ''],
107+
'origin-sync': ['\uf4dd', '']
98108
}

src/mud/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ def configure() -> None:
3939
settings.config['mud']['run_table'] = str(ask('Do you want to see command execution progress in table view? This will limit output content.'))
4040
settings.config['mud']['run_async'] = str(ask('Do you want to run commands simultaneously for multiple repositories?'))
4141
settings.config['mud']['nerd_fonts'] = str(ask(f'Do you want to use {BOLD}nerd-fonts{RESET}?'))
42-
settings.config['mud']['show_borders'] = str(ask(f'Do you want to see borders in table view?'))
43-
settings.config['mud']['collapse_paths'] = str(ask(f'Do you want to collapse paths, such as directory paths and branches? (ex. {BOLD}feature/name{RESET} -> {BOLD}f/name{RESET}'))
4442
settings.config['mud']['display_absolute_paths'] = str(ask(f'Do you want to display absolute paths for directories? (ex. {BOLD}~/Documents/repo{RESET} -> {BOLD}/home/user/Documents/repo{RESET}'))
43+
settings.config['mud']['display_header'] = str(ask(f'Do you want to display headers in a table view {BOLD}nerd-fonts{RESET}?'))
44+
settings.config['mud']['display_borders'] = str(ask(f'Do you want to see borders in table view?'))
45+
settings.config['mud']['collapse_paths'] = str(ask(f'Do you want to collapse paths, such as directory paths and branches? (ex. {BOLD}feature/name{RESET} -> {BOLD}f/name{RESET}'))
4546
except KeyboardInterrupt:
4647
return
4748

@@ -105,9 +106,10 @@ def get_table(field_names: List[str]) -> PrettyTable:
105106
def set_style(item: str) -> str:
106107
return f'{GRAY}{item}{RESET}'
107108

108-
borders = settings.config['mud'].getboolean('show_borders', fallback=False)
109+
borders = settings.config['mud'].getboolean('display_borders', fallback=False)
109110
round_corners = settings.config['mud'].getboolean('round_corners', fallback=False)
110111
table = PrettyTable(border=borders, header=False, style=PLAIN_COLUMNS, align='l')
112+
111113
if borders:
112114
table.horizontal_char = set_style('─')
113115
table.vertical_char = set_style('│')
@@ -130,7 +132,7 @@ def set_style(item: str) -> str:
130132
table.bottom_right_junction_char = set_style('┘')
131133

132134
table.field_names = field_names
133-
135+
table.header = settings.config['mud'].getboolean('display_header', fallback=False)
134136
return table
135137

136138

0 commit comments

Comments
 (0)