Skip to content

Commit

Permalink
Fixed table rendering (close #94)
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Jul 13, 2020
1 parent c5f7cf2 commit 1cbd754
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CB/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import random
from rich.terminal_theme import TerminalTheme

__version__ = '3.5.0'
__version__ = '3.5.1'
__license__ = 'GPLv3'
__copyright__ = '2019-2020, Paweł Jastrzębski <[email protected]>'
__docformat__ = 'restructuredtext en'
Expand Down
32 changes: 21 additions & 11 deletions CurseBreaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pathlib import Path
from datetime import datetime
from rich import box
from rich.text import Text
from rich.rule import Rule
from rich.table import Table
from rich.console import Console
Expand Down Expand Up @@ -290,8 +291,8 @@ def setup_completer(self):
def setup_table(self):
self.table = Table(box=box.SQUARE)
self.table.add_column('Status', header_style='bold white', no_wrap=True, justify='center')
self.table.add_column('Name', header_style='bold white', no_wrap=True)
self.table.add_column('Version', header_style='bold white', no_wrap=True)
self.table.add_column('Name', header_style='bold white')
self.table.add_column('Version', header_style='bold white')

def c_install(self, args):
if args:
Expand All @@ -308,9 +309,11 @@ def c_install(self, args):
for addon in addons:
installed, name, version = self.core.add_addon(addon, optignore)
if installed:
self.table.add_row('[green]Installed[/green]', name, version)
self.table.add_row('[green]Installed[/green]', Text(name, no_wrap=True),
Text(version, no_wrap=True))
else:
self.table.add_row('[bold black]Already installed[/bold black]', name, version)
self.table.add_row('[bold black]Already installed[/bold black]',
Text(name, no_wrap=True), Text(version, no_wrap=True))
progress.update(task, advance=1, refresh=True)
self.console.print(self.table)
else:
Expand All @@ -335,9 +338,11 @@ def c_uninstall(self, args):
for addon in addons:
name, version = self.core.del_addon(addon)
if name:
self.table.add_row(f'[bold red]Uninstalled[/bold red]', name, version)
self.table.add_row(f'[bold red]Uninstalled[/bold red]',
Text(name, no_wrap=True), Text(version, no_wrap=True))
else:
self.table.add_row(f'[bold black]Not installed[/bold black]', addon, '')
self.table.add_row(f'[bold black]Not installed[/bold black]',
Text(addon, no_wrap=True), Text('', no_wrap=True))
progress.update(task, advance=1, refresh=True)
self.console.print(self.table)
else:
Expand Down Expand Up @@ -372,17 +377,22 @@ def c_update(self, args, addline=False, update=True, force=False):
if versionold:
if versionold == versionnew:
if modified:
self.table.add_row('[bold red]Modified[/bold red]', name, versionold)
self.table.add_row('[bold red]Modified[/bold red]',
Text(name, no_wrap=True), Text(versionold, no_wrap=True))
else:
self.table.add_row('[green]Up-to-date[/green]', name, versionold)
self.table.add_row('[green]Up-to-date[/green]',
Text(name, no_wrap=True), Text(versionold, no_wrap=True))
else:
if modified or blocked:
self.table.add_row('[bold red]Update suppressed[/bold red]', name, versionold)
self.table.add_row('[bold red]Update suppressed[/bold red]',
Text(name, no_wrap=True), Text(versionold, no_wrap=True))
else:
self.table.add_row(f'[yellow]{"Updated" if update else "Update available"}'
f'[/yellow]', name, f'[yellow]{versionnew}[/yellow]')
f'[/yellow]', Text(name, no_wrap=True),
Text(versionnew, style='yellow', no_wrap=True))
else:
self.table.add_row(f'[bold black]Not installed[/bold black]', addon, '')
self.table.add_row(f'[bold black]Not installed[/bold black]',
Text(addon, no_wrap=True), Text('', no_wrap=True))
except Exception as e:
exceptions.append(e)
progress.update(task, advance=1 if args else 0.5, refresh=True)
Expand Down

0 comments on commit 1cbd754

Please sign in to comment.