Skip to content

Commit

Permalink
Merge pull request #25 from srl-labs/tui
Browse files Browse the repository at this point in the history
Tui
  • Loading branch information
FloSch62 authored Jan 8, 2025
2 parents 8cedbb2 + c844ab2 commit ac909b1
Show file tree
Hide file tree
Showing 6 changed files with 1,110 additions and 123 deletions.
33 changes: 26 additions & 7 deletions clab2drawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def main(
# Use ThemeManager to load styles
logger.debug("Loading theme...")
theme_manager = ThemeManager(theme_path)

try:
styles = theme_manager.load_theme()
except ThemeManagerError as e:
Expand Down Expand Up @@ -102,19 +103,37 @@ def main(
else:
diagram.nodes = nodes

available_themes = theme_manager.list_available_themes()
available_themes.sort()


if interactive:
logger.debug("Entering interactive mode...")
processor = YAMLProcessor()
interactor = InteractiveManager()
interactor.run_interactive_mode(
diagram.nodes,
styles["icon_to_group_mapping"],
containerlab_data,
input_file,
processor,
prefix,
lab_name,
diagram=diagram,
available_themes=available_themes,
icon_to_group_mapping=styles["icon_to_group_mapping"],
containerlab_data=containerlab_data,
output_file=input_file,
processor=processor,
prefix=prefix,
lab_name=lab_name,
)
# After wizard finishes:
layout = interactor.final_summary.get("Layout", layout)
chosen_theme = interactor.final_summary.get("Theme")

if chosen_theme:
# Load that theme or switch to it
new_theme_path = os.path.join(os.path.dirname(theme_path), f"{chosen_theme}.yaml")
if os.path.exists(new_theme_path):
logger.debug(f"Loading user-chosen theme: {chosen_theme}")
theme_manager.config_path = new_theme_path
styles = theme_manager.load_theme()
else:
logger.warning(f"User chose theme '{chosen_theme}' but no file found. Keeping old theme.")

logger.debug("Assigning graph levels...")
graph_manager = GraphLevelManager()
Expand Down
30 changes: 29 additions & 1 deletion core/config/theme_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import base64
import re
import logging
from typing import Dict, Any
import os
import glob
from typing import Dict, Any, List

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -32,6 +34,32 @@ def __init__(self, config_path: str):
"""
self.config_path = config_path

def list_available_themes(self) -> List[str]:
"""
Return a list of all available theme names in the same directory as the current config_path.
Themes are identified by files ending with .yaml or .yml.
:return: List of theme names (file names without the .yaml/.yml extension).
"""
# Identify the directory containing the theme files
base_dir = os.path.dirname(self.config_path)
if not base_dir:
base_dir = "."

# Gather all .yaml / .yml files
yaml_files = glob.glob(os.path.join(base_dir, "*.yaml")) + glob.glob(os.path.join(base_dir, "*.yml"))

# Extract base filenames without extensions
available_themes = []
for yf in yaml_files:
filename = os.path.basename(yf)
# Remove extension and store just the "name"
theme_name, _ = os.path.splitext(filename)
available_themes.append(theme_name)

return available_themes


def load_theme(self) -> dict:
"""
Load and process the theme configuration.
Expand Down
Loading

0 comments on commit ac909b1

Please sign in to comment.