theme.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #pragma once
  2. #include <string>
  3. #include <map>
  4. #include <memory>
  5. #include <vector>
  6. #include <optional>
  7. #include "lumacs/color.hpp"
  8. #include "lumacs/face.hpp"
  9. namespace lumacs {
  10. /// Theme element types (Legacy / Semantic Names)
  11. enum class ThemeElement {
  12. // Text elements
  13. Normal,
  14. Keyword,
  15. String,
  16. Comment,
  17. Function,
  18. Type,
  19. Number,
  20. Constant,
  21. Error,
  22. // UI elements
  23. StatusLine,
  24. StatusLineInactive,
  25. MessageLine,
  26. LineNumber,
  27. Cursor,
  28. Selection,
  29. SearchMatch,
  30. SearchFail,
  31. // Window elements
  32. WindowBorder,
  33. WindowBorderActive,
  34. // Special
  35. Background
  36. };
  37. /// A theme defines colors and attributes for various UI elements and named faces
  38. class Theme {
  39. public:
  40. Theme(const std::string& name) : name_(name) {}
  41. /// Set color for a theme element (Legacy)
  42. void set_color(ThemeElement element, const Color& fg, const Color& bg = Color(-1, -1, -1));
  43. /// Set full face attributes
  44. void set_face(const std::string& name, const FaceAttributes& attrs);
  45. /// Get face attributes
  46. std::optional<FaceAttributes> get_face(const std::string& name) const;
  47. /// Get foreground color for an element (Legacy)
  48. Color get_fg_color(ThemeElement element) const;
  49. /// Get background color for an element (Legacy)
  50. Color get_bg_color(ThemeElement element) const;
  51. /// Get ncurses color pair for an element (Legacy - resolves via faces now)
  52. int get_color_pair(ThemeElement element) const;
  53. /// Get ncurses color pair for a face
  54. int get_face_color_pair(const std::string& name) const;
  55. /// Get ncurses attributes (color pair + flags) for a face
  56. int get_face_attributes_ncurses(const std::string& name) const;
  57. /// Theme name
  58. const std::string& name() const { return name_; }
  59. /// Initialize all color pairs for ncurses
  60. void initialize_ncurses_colors();
  61. /// Helper to convert ThemeElement to face name
  62. static std::string element_to_face_name(ThemeElement element);
  63. private:
  64. std::string name_;
  65. // std::map<ThemeElement, std::pair<Color, Color>> colors_; // Legacy storage - removed
  66. std::map<std::string, FaceAttributes> faces_;
  67. mutable std::map<std::string, int> face_pairs_; // Cache for ncurses pairs
  68. mutable int next_pair_id_ = 1;
  69. // Helper for inheritance resolution
  70. std::optional<FaceAttributes> get_face_recursive(const std::string& name, int depth) const;
  71. };
  72. /// Theme manager - handles multiple themes and switching between them
  73. class ThemeManager {
  74. public:
  75. /// Register a new theme
  76. void register_theme(std::shared_ptr<Theme> theme);
  77. /// Set the active theme
  78. void set_active_theme(const std::string& name);
  79. /// Get the active theme
  80. std::shared_ptr<Theme> active_theme() const { return active_theme_; }
  81. /// Get available theme names
  82. std::vector<std::string> theme_names() const;
  83. /// Create default themes
  84. void create_default_themes();
  85. /// Create Everforest dark theme
  86. std::shared_ptr<Theme> create_everforest_theme();
  87. /// Create default light theme
  88. std::shared_ptr<Theme> create_default_theme();
  89. /// Create Dracula theme
  90. std::shared_ptr<Theme> create_dracula_theme();
  91. private:
  92. std::map<std::string, std::shared_ptr<Theme>> themes_;
  93. std::shared_ptr<Theme> active_theme_;
  94. };
  95. } // namespace lumacs