Coverage for openhcs/textual_tui/services/pattern_file_service.py: 0.0%
18 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-04 02:09 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-04 02:09 +0000
1"""
2Pattern File Service - TUI-specific version with external editor support.
4This service extends the framework-agnostic PatternFileService with
5Textual TUI-specific external editor integration.
6"""
8import logging
9from typing import Union, List, Dict, Optional, Any
11from openhcs.ui.shared.pattern_file_service import PatternFileService as PatternFileServiceCore
12from openhcs.textual_tui.services.external_editor_service import ExternalEditorService
14logger = logging.getLogger(__name__)
17class PatternFileService(PatternFileServiceCore):
18 """
19 TUI-specific pattern file service with external editor integration.
21 Extends the framework-agnostic core with prompt_toolkit-based external editor.
22 """
24 def __init__(self, state: Any):
25 """
26 Initialize the TUI pattern file service.
28 Args:
29 state: TUIState instance for external editor integration
30 """
31 super().__init__()
32 self.state = state
33 self.external_editor_service = ExternalEditorService(state)
35 # Core file I/O methods inherited from PatternFileServiceCore:
36 # - load_pattern_from_file()
37 # - save_pattern_to_file()
38 # - validate_pattern_file()
39 # - get_default_save_path()
40 # - ensure_func_extension()
41 # - backup_pattern_file()
43 async def edit_pattern_externally(self, pattern: Union[List, Dict]) -> tuple[bool, Union[List, Dict], Optional[str]]:
44 """
45 Edit pattern in external editor (Vim) via ExternalEditorService.
47 TUI-specific method using prompt_toolkit-based external editor.
49 Args:
50 pattern: Pattern to edit
52 Returns:
53 Tuple of (success, new_pattern, error_message)
54 """
55 try:
56 # Format pattern for external editing
57 initial_content = f"pattern = {repr(pattern)}"
59 # Use existing ExternalEditorService (TUI-specific)
60 success, new_pattern, error_message = await self.external_editor_service.edit_pattern_in_external_editor(initial_content)
62 return success, new_pattern, error_message
64 except Exception as e:
65 logger.error(f"External editor integration failed: {e}")
66 return False, pattern, f"External editor failed: {e}"