mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] colorize app catalog lines per level
This commit is contained in:
parent
016396a49a
commit
c1f57322e1
1 changed files with 23 additions and 0 deletions
|
@ -36,6 +36,8 @@ import urllib.parse
|
|||
import tempfile
|
||||
from collections import OrderedDict
|
||||
|
||||
from rich.style import Style
|
||||
|
||||
from moulinette import msignals, m18n, msettings, console, Table, TableForDict
|
||||
from moulinette.core import MoulinetteError
|
||||
from moulinette.utils.log import getActionLogger
|
||||
|
@ -112,11 +114,32 @@ def app_catalog(full=False, with_categories=False):
|
|||
for c in catalog["categories"]
|
||||
]
|
||||
|
||||
def colorize_row_from_levels(table, columns, row, values):
|
||||
level = row[1]["level"]
|
||||
if not isinstance(level, int) and not level.isdigit():
|
||||
table.add_row(*values)
|
||||
return
|
||||
|
||||
level = int(level)
|
||||
style = None
|
||||
|
||||
if level > 7:
|
||||
style = Style(color="blue")
|
||||
elif level > 6:
|
||||
style = Style(color="green")
|
||||
elif level > 4:
|
||||
style = Style(color="yellow")
|
||||
else:
|
||||
style = Style(color="red")
|
||||
|
||||
table.add_row(*values, style=style)
|
||||
|
||||
if not with_categories:
|
||||
return TableForDict(
|
||||
{"apps": catalog["apps"]},
|
||||
title="Available applications catalog",
|
||||
columns=[{"key": TableForDict.key, "header": "Application id"}, "description", "level"],
|
||||
row_function=colorize_row_from_levels,
|
||||
)
|
||||
else:
|
||||
return {"apps": catalog["apps"], "categories": catalog["categories"]}
|
||||
|
|
Loading…
Add table
Reference in a new issue