Skip to content

Commit ac909b1

Browse files
authored
Merge pull request #25 from srl-labs/tui
Tui
2 parents 8cedbb2 + c844ab2 commit ac909b1

File tree

6 files changed

+1110
-123
lines changed

6 files changed

+1110
-123
lines changed

clab2drawio.py

+26-7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def main(
7272
# Use ThemeManager to load styles
7373
logger.debug("Loading theme...")
7474
theme_manager = ThemeManager(theme_path)
75+
7576
try:
7677
styles = theme_manager.load_theme()
7778
except ThemeManagerError as e:
@@ -102,19 +103,37 @@ def main(
102103
else:
103104
diagram.nodes = nodes
104105

106+
available_themes = theme_manager.list_available_themes()
107+
available_themes.sort()
108+
109+
105110
if interactive:
106111
logger.debug("Entering interactive mode...")
107112
processor = YAMLProcessor()
108113
interactor = InteractiveManager()
109114
interactor.run_interactive_mode(
110-
diagram.nodes,
111-
styles["icon_to_group_mapping"],
112-
containerlab_data,
113-
input_file,
114-
processor,
115-
prefix,
116-
lab_name,
115+
diagram=diagram,
116+
available_themes=available_themes,
117+
icon_to_group_mapping=styles["icon_to_group_mapping"],
118+
containerlab_data=containerlab_data,
119+
output_file=input_file,
120+
processor=processor,
121+
prefix=prefix,
122+
lab_name=lab_name,
117123
)
124+
# After wizard finishes:
125+
layout = interactor.final_summary.get("Layout", layout)
126+
chosen_theme = interactor.final_summary.get("Theme")
127+
128+
if chosen_theme:
129+
# Load that theme or switch to it
130+
new_theme_path = os.path.join(os.path.dirname(theme_path), f"{chosen_theme}.yaml")
131+
if os.path.exists(new_theme_path):
132+
logger.debug(f"Loading user-chosen theme: {chosen_theme}")
133+
theme_manager.config_path = new_theme_path
134+
styles = theme_manager.load_theme()
135+
else:
136+
logger.warning(f"User chose theme '{chosen_theme}' but no file found. Keeping old theme.")
118137

119138
logger.debug("Assigning graph levels...")
120139
graph_manager = GraphLevelManager()

core/config/theme_manager.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import base64
33
import re
44
import logging
5-
from typing import Dict, Any
5+
import os
6+
import glob
7+
from typing import Dict, Any, List
68

79
logger = logging.getLogger(__name__)
810

@@ -32,6 +34,32 @@ def __init__(self, config_path: str):
3234
"""
3335
self.config_path = config_path
3436

37+
def list_available_themes(self) -> List[str]:
38+
"""
39+
Return a list of all available theme names in the same directory as the current config_path.
40+
Themes are identified by files ending with .yaml or .yml.
41+
42+
:return: List of theme names (file names without the .yaml/.yml extension).
43+
"""
44+
# Identify the directory containing the theme files
45+
base_dir = os.path.dirname(self.config_path)
46+
if not base_dir:
47+
base_dir = "."
48+
49+
# Gather all .yaml / .yml files
50+
yaml_files = glob.glob(os.path.join(base_dir, "*.yaml")) + glob.glob(os.path.join(base_dir, "*.yml"))
51+
52+
# Extract base filenames without extensions
53+
available_themes = []
54+
for yf in yaml_files:
55+
filename = os.path.basename(yf)
56+
# Remove extension and store just the "name"
57+
theme_name, _ = os.path.splitext(filename)
58+
available_themes.append(theme_name)
59+
60+
return available_themes
61+
62+
3563
def load_theme(self) -> dict:
3664
"""
3765
Load and process the theme configuration.

0 commit comments

Comments
 (0)