From a0eb162f930f418162a12902366be86af9b41834 Mon Sep 17 00:00:00 2001 From: Agatha Rose Date: Wed, 6 Oct 2021 01:52:54 +0300 Subject: [PATCH] add optional ascii art --- .gitignore | 3 ++- config.py | 4 +++- main.py | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index ed8ebf5..7b62f12 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -__pycache__ \ No newline at end of file +__pycache__ +.vscode \ No newline at end of file diff --git a/config.py b/config.py index da1bc56..cc330dc 100644 --- a/config.py +++ b/config.py @@ -13,7 +13,9 @@ os.makedirs(config_dir, exist_ok=True) # create an example config file if it doesn't already exist if not os.path.exists(config_dir + '/config.toml'): with open(config_dir + '/config.toml', 'a+') as f: - f.write('''[repo] + f.write('''# Disable ascii art if you're using a screen reader or want smaller output +ascii_art = true +[repo] # Example: `~/backups/backup.borg` or `ssh://agatha@some.place:22/~/backups/backup.borg` path = "" # Leave empty if none diff --git a/main.py b/main.py index b09c8a5..b68b79a 100644 --- a/main.py +++ b/main.py @@ -1,15 +1,34 @@ from prepare import borg_info_raw, readable_csize, csize, archive_num, last_archive_time, df_avail_readable, df_avail_bytes -from rich import print, box -from rich.console import Group +from rich import box +from rich.console import Console +from rich.layout import Layout from rich.padding import Padding from rich.panel import Panel from rich.progress import Progress, BarColumn from rich.style import Style - -# actually print the thing +from config import config emphasis = Style(color='#d89961', bold=True) +flomp = f'''[{emphasis}] + .=--:: + -***##- ::. ... + +**##*: =##*. =*****: + :******+::.. :##*: :******. + =*************+====-::+*****+ + .+**=:-==+++++****************: + -***. .:--==+++++******+ + =**+. .:-+#***- + :***= ***** + -***- -#***- + .=+**=:. ***** + .:-+++=-:. =#***= + .:-=*+=-:. :#****. + .:-=+++-::*****= + .:-=+**** + .:. +''' + if borg_info_raw.returncode == 0: online = Padding('[#82bfe0 bold]◉[/#82bfe0 bold] Host online', (0, 2)) else: @@ -31,13 +50,27 @@ disk_usage = Panel(used, box=box.SQUARE, border_style=emphasis) avail_backups = Panel(f"Available: [{emphasis}]{archive_num}[/{emphasis}] backups. Last backup from: [{emphasis}]{last_archive_time}[/{emphasis}]", box=box.SQUARE, border_style=emphasis) -output_group = Group( - online, - disk_usage, - avail_backups +if config['ascii_art']: + console = Console(width=85, height=18) +else: + console = Console(width=70, height=8) + +layout = Layout() +layout.split_row( + Layout(flomp, name="left"), + Layout(name="right") ) -print(Panel.fit( - output_group, +layout['right'].split_column( + Layout(online, size=1), + Layout(disk_usage, size=3), + Layout(avail_backups, size=4) +) + +layout['left'].visible = config['ascii_art'] + +# actually print the thing +console.print(Panel.fit( + layout, box=box.DOUBLE, border_style=emphasis ))