add optional ascii art

This commit is contained in:
Agatha Lovelace 2021-10-06 01:52:54 +03:00
parent ec600fd1f6
commit a0eb162f93
No known key found for this signature in database
GPG Key ID: 2DB18BA2E0A80BC3
3 changed files with 48 additions and 12 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
__pycache__
__pycache__
.vscode

View File

@ -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

53
main.py
View File

@ -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
))