summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/__init__.py3
-rw-r--r--kvmd/apps/kvmd/ugpio.py40
-rw-r--r--kvmd/validators/ugpio.py4
3 files changed, 34 insertions, 13 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py
index 6bac90e2..168b1b85 100644
--- a/kvmd/apps/__init__.py
+++ b/kvmd/apps/__init__.py
@@ -93,6 +93,7 @@ from ..validators.kvm import valid_stream_h264_gop
from ..validators.ugpio import valid_ugpio_driver
from ..validators.ugpio import valid_ugpio_channel
from ..validators.ugpio import valid_ugpio_mode
+from ..validators.ugpio import valid_ugpio_view_title
from ..validators.ugpio import valid_ugpio_view_table
from ..validators.hw import valid_tty_speed
@@ -482,7 +483,7 @@ def _get_config_scheme() -> dict:
"scheme": {}, # Dymanic content
"view": {
"header": {
- "title": Option("GPIO"),
+ "title": Option("GPIO", type=valid_ugpio_view_title),
},
"table": Option([], type=valid_ugpio_view_table),
},
diff --git a/kvmd/apps/kvmd/ugpio.py b/kvmd/apps/kvmd/ugpio.py
index 8b7b31f8..0774ff91 100644
--- a/kvmd/apps/kvmd/ugpio.py
+++ b/kvmd/apps/kvmd/ugpio.py
@@ -311,6 +311,27 @@ class UserGpio:
# =====
def __make_view(self) -> dict:
+ return {
+ "header": {"title": self.__make_view_title()},
+ "table": self.__make_view_table(),
+ }
+
+ def __make_view_title(self) -> list[dict]:
+ raw_title = self.__view["header"]["title"]
+ title: list[dict] = []
+ if isinstance(raw_title, list):
+ for item in raw_title:
+ if item.startswith("#") or len(item) == 0:
+ title.append(self.__make_item_label(item))
+ else:
+ parts = list(map(str.strip, item.split("|", 2)))
+ if parts and parts[0] in self.__inputs:
+ title.append(self.__make_item_input(parts))
+ else:
+ title.append(self.__make_item_label(f"#{raw_title}"))
+ return title
+
+ def __make_view_table(self) -> list[list[dict] | None]:
table: list[list[dict] | None] = []
for row in self.__view["table"]:
if len(row) == 0:
@@ -320,29 +341,24 @@ class UserGpio:
items: list[dict] = []
for item in map(str.strip, row):
if item.startswith("#") or len(item) == 0:
- items.append(self.__make_view_label(item))
+ items.append(self.__make_item_label(item))
else:
parts = list(map(str.strip, item.split("|", 2)))
if parts:
if parts[0] in self.__inputs:
- items.append(self.__make_view_input(parts))
+ items.append(self.__make_item_input(parts))
elif parts[0] in self.__outputs:
- items.append(self.__make_view_output(parts))
+ items.append(self.__make_item_output(parts))
table.append(items)
+ return table
- return {
- "header": self.__view["header"],
- "table": table,
- }
-
- def __make_view_label(self, item: str) -> dict:
- assert item.startswith("#")
+ def __make_item_label(self, item: str) -> dict:
return {
"type": "label",
"text": item[1:].strip(),
}
- def __make_view_input(self, parts: list[str]) -> dict:
+ def __make_item_input(self, parts: list[str]) -> dict:
assert len(parts) >= 1
color = (parts[1] if len(parts) > 1 else None)
if color not in ["green", "yellow", "red"]:
@@ -353,7 +369,7 @@ class UserGpio:
"color": color,
}
- def __make_view_output(self, parts: list[str]) -> dict:
+ def __make_item_output(self, parts: list[str]) -> dict:
assert len(parts) >= 1
confirm = False
text = "Click"
diff --git a/kvmd/validators/ugpio.py b/kvmd/validators/ugpio.py
index c05aa75d..ba4a5c5b 100644
--- a/kvmd/validators/ugpio.py
+++ b/kvmd/validators/ugpio.py
@@ -46,6 +46,10 @@ def valid_ugpio_mode(arg: Any, variants: set[str]) -> str:
return check_string_in_list(arg, "GPIO driver's pin mode", variants)
+def valid_ugpio_view_title(arg: Any) -> (str | list[str]):
+ return (list(map(str, arg)) if isinstance(arg, list) else str(arg))
+
+
def valid_ugpio_view_table(arg: Any) -> list[list[str]]: # pylint: disable=inconsistent-return-statements
try:
return [list(map(str, row)) for row in list(arg)]