mirror of
https://github.com/overcuriousity/trace.git
synced 2025-12-21 05:22:21 +00:00
Major refactoring to organize code into focused, single-responsibility modules that are easier for AI coding agents and developers to navigate and modify. **Module Reorganization:** Models Package (trace/models/): - Moved models.py content into models/__init__.py - Extracted IOC extraction into models/extractors/ioc_extractor.py (236 lines) - Extracted tag extraction into models/extractors/tag_extractor.py (34 lines) - Reduced duplication and improved maintainability Storage Package (trace/storage_impl/): - Split storage.py (402 lines) into focused modules: - storage.py: Main Storage class (112 lines) - state_manager.py: StateManager for context/settings (92 lines) - lock_manager.py: Cross-platform file locking (87 lines) - demo_data.py: Demo case creation (143 lines) - Added backward-compatible wrapper at trace/storage.py TUI Utilities (trace/tui/): - Created rendering package: - colors.py: Color pair constants and initialization (43 lines) - text_renderer.py: Text rendering with highlighting (137 lines) - Created handlers package: - export_handler.py: Export functionality (238 lines) - Main tui.py (3307 lines) remains for future refactoring **Benefits:** - Smaller, focused files (most < 250 lines) - Clear single responsibilities - Easier to locate and modify specific functionality - Better separation of concerns - Reduced cognitive load for AI agents - All tests pass, no features removed **Testing:** - All existing tests pass - Imports verified - CLI and storage functionality tested - Backward compatibility maintained Updated CLAUDE.md to document new architecture and AI optimization strategy.
44 lines
1.8 KiB
Python
44 lines
1.8 KiB
Python
"""Color pair initialization and constants for TUI"""
|
|
|
|
import curses
|
|
|
|
|
|
class ColorPairs:
|
|
"""Color pair constants"""
|
|
SELECTION = 1 # Black on cyan
|
|
SUCCESS = 2 # Green on black
|
|
WARNING = 3 # Yellow on black
|
|
ERROR = 4 # Red on black
|
|
HEADER = 5 # Cyan on black
|
|
METADATA = 6 # White on black
|
|
BORDER = 7 # Blue on black
|
|
TAG = 8 # Magenta on black
|
|
IOC_SELECTED = 9 # Red on cyan
|
|
TAG_SELECTED = 10 # Yellow on cyan
|
|
|
|
|
|
def init_colors():
|
|
"""Initialize color pairs for the TUI"""
|
|
curses.start_color()
|
|
if curses.has_colors():
|
|
# Selection / Highlight
|
|
curses.init_pair(ColorPairs.SELECTION, curses.COLOR_BLACK, curses.COLOR_CYAN)
|
|
# Success / Active indicators
|
|
curses.init_pair(ColorPairs.SUCCESS, curses.COLOR_GREEN, curses.COLOR_BLACK)
|
|
# Info / Warnings
|
|
curses.init_pair(ColorPairs.WARNING, curses.COLOR_YELLOW, curses.COLOR_BLACK)
|
|
# Errors / Critical / IOCs
|
|
curses.init_pair(ColorPairs.ERROR, curses.COLOR_RED, curses.COLOR_BLACK)
|
|
# Headers / Titles (bright cyan)
|
|
curses.init_pair(ColorPairs.HEADER, curses.COLOR_CYAN, curses.COLOR_BLACK)
|
|
# Metadata / Secondary text (dim)
|
|
curses.init_pair(ColorPairs.METADATA, curses.COLOR_WHITE, curses.COLOR_BLACK)
|
|
# Borders / Separators (blue)
|
|
curses.init_pair(ColorPairs.BORDER, curses.COLOR_BLUE, curses.COLOR_BLACK)
|
|
# Tags (magenta)
|
|
curses.init_pair(ColorPairs.TAG, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
|
|
# IOCs on selected background (red on cyan)
|
|
curses.init_pair(ColorPairs.IOC_SELECTED, curses.COLOR_RED, curses.COLOR_CYAN)
|
|
# Tags on selected background (yellow on cyan)
|
|
curses.init_pair(ColorPairs.TAG_SELECTED, curses.COLOR_YELLOW, curses.COLOR_CYAN)
|