| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- #pragma once
- #include <string>
- #include <map>
- #include <memory>
- #include <vector>
- #include <optional>
- #include "lumacs/color.hpp"
- #include "lumacs/face.hpp"
- namespace lumacs {
- /// Theme element types (Legacy / Semantic Names)
- enum class ThemeElement {
- // Text elements
- Normal,
- Keyword,
- String,
- Comment,
- Function,
- Type,
- Number,
- Constant,
- Error,
- // UI elements
- StatusLine,
- StatusLineInactive,
- MessageLine,
- LineNumber,
- Cursor,
- Selection,
- SearchMatch,
- SearchFail,
- // Window elements
- WindowBorder,
- WindowBorderActive,
- // Special
- Background
- };
- /// A theme defines colors and attributes for various UI elements and named faces
- class Theme {
- public:
- Theme(const std::string& name) : name_(name) {}
- /// Set color for a theme element (Legacy)
- void set_color(ThemeElement element, const Color& fg, const Color& bg = Color(-1, -1, -1));
- /// Set full face attributes
- void set_face(const std::string& name, const FaceAttributes& attrs);
-
- /// Get face attributes
- std::optional<FaceAttributes> get_face(const std::string& name) const;
- /// Get foreground color for an element (Legacy)
- Color get_fg_color(ThemeElement element) const;
- /// Get background color for an element (Legacy)
- Color get_bg_color(ThemeElement element) const;
- /// Get ncurses color pair for an element (Legacy - resolves via faces now)
- int get_color_pair(ThemeElement element) const;
-
- /// Get ncurses color pair for a face
- int get_face_color_pair(const std::string& name) const;
-
- /// Get ncurses attributes (color pair + flags) for a face
- int get_face_attributes_ncurses(const std::string& name) const;
- /// Theme name
- const std::string& name() const { return name_; }
- /// Initialize all color pairs for ncurses
- void initialize_ncurses_colors();
- /// Helper to convert ThemeElement to face name
- static std::string element_to_face_name(ThemeElement element);
- private:
- std::string name_;
- // std::map<ThemeElement, std::pair<Color, Color>> colors_; // Legacy storage - removed
-
- std::map<std::string, FaceAttributes> faces_;
-
- mutable std::map<std::string, int> face_pairs_; // Cache for ncurses pairs
- mutable int next_pair_id_ = 1;
- // Helper for inheritance resolution
- std::optional<FaceAttributes> get_face_recursive(const std::string& name, int depth) const;
- };
- /// Theme manager - handles multiple themes and switching between them
- class ThemeManager {
- public:
- /// Register a new theme
- void register_theme(std::shared_ptr<Theme> theme);
- /// Set the active theme
- void set_active_theme(const std::string& name);
- /// Get the active theme
- std::shared_ptr<Theme> active_theme() const { return active_theme_; }
- /// Get available theme names
- std::vector<std::string> theme_names() const;
- /// Create default themes
- void create_default_themes();
- /// Create Everforest dark theme
- std::shared_ptr<Theme> create_everforest_theme();
- /// Create default light theme
- std::shared_ptr<Theme> create_default_theme();
- /// Create Dracula theme
- std::shared_ptr<Theme> create_dracula_theme();
- private:
- std::map<std::string, std::shared_ptr<Theme>> themes_;
- std::shared_ptr<Theme> active_theme_;
- };
- } // namespace lumacs
|