theme.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. Warning,
  23. Variable,
  24. Builtin,
  25. Preprocessor,
  26. Operator,
  27. // UI elements
  28. StatusLine,
  29. StatusLineInactive,
  30. MessageLine,
  31. LineNumber,
  32. LineNumberCurrent,
  33. Cursor,
  34. Selection,
  35. SearchMatch,
  36. SearchFail,
  37. MatchParen,
  38. // Minibuffer elements
  39. MinibufferPrompt,
  40. MinibufferInput,
  41. MinibufferCompletion,
  42. MinibufferMatch,
  43. // Window elements
  44. WindowBorder,
  45. WindowBorderActive,
  46. WindowSeparator,
  47. TabLine,
  48. TabLineSel,
  49. // Special
  50. Background,
  51. Foreground
  52. };
  53. /// A theme defines colors and attributes for various UI elements and named faces
  54. class Theme {
  55. public:
  56. Theme(const std::string& name) : name_(name) {}
  57. /// Set color for a theme element (Legacy)
  58. void set_color(ThemeElement element, const Color& fg, const Color& bg = Color(-1, -1, -1));
  59. /// Set full face attributes
  60. void set_face(const std::string& name, const FaceAttributes& attrs);
  61. /// Get face attributes
  62. std::optional<FaceAttributes> get_face(const std::string& name) const;
  63. /// Get foreground color for an element (Legacy)
  64. Color get_fg_color(ThemeElement element) const;
  65. /// Get background color for an element (Legacy)
  66. Color get_bg_color(ThemeElement element) const;
  67. /// Get ncurses color pair for an element (Legacy - resolves via faces now)
  68. int get_color_pair(ThemeElement element) const;
  69. /// Get ncurses color pair for a face
  70. int get_face_color_pair(const std::string& name) const;
  71. /// Get ncurses attributes (color pair + flags) for a face
  72. int get_face_attributes_ncurses(const std::string& name) const;
  73. /// Theme name
  74. const std::string& name() const { return name_; }
  75. /// Initialize all color pairs for ncurses
  76. void initialize_ncurses_colors();
  77. /// Helper to convert ThemeElement to face name
  78. static std::string element_to_face_name(ThemeElement element);
  79. private:
  80. std::string name_;
  81. // std::map<ThemeElement, std::pair<Color, Color>> colors_; // Legacy storage - removed
  82. std::map<std::string, FaceAttributes> faces_;
  83. mutable std::map<std::string, int> face_pairs_; // Cache for ncurses pairs
  84. mutable int next_pair_id_ = 1;
  85. // Helper for inheritance resolution
  86. std::optional<FaceAttributes> get_face_recursive(const std::string& name, int depth) const;
  87. };
  88. /// Theme manager - handles multiple themes and switching between them
  89. class ThemeManager {
  90. public:
  91. /// Register a new theme
  92. void register_theme(std::shared_ptr<Theme> theme);
  93. /// Set the active theme
  94. void set_active_theme(const std::string& name);
  95. /// Get the active theme
  96. std::shared_ptr<Theme> active_theme() const { return active_theme_; }
  97. /// Get available theme names
  98. std::vector<std::string> theme_names() const;
  99. /// Create default themes
  100. void create_default_themes();
  101. /// Create Everforest dark theme
  102. std::shared_ptr<Theme> create_everforest_theme();
  103. /// Create default light theme
  104. std::shared_ptr<Theme> create_default_theme();
  105. /// Create Dracula theme
  106. std::shared_ptr<Theme> create_dracula_theme();
  107. /// Create Solarized Dark theme
  108. std::shared_ptr<Theme> create_solarized_dark_theme();
  109. /// Create Nord theme
  110. std::shared_ptr<Theme> create_nord_theme();
  111. /// Create Gruvbox Light theme
  112. std::shared_ptr<Theme> create_gruvbox_light_theme();
  113. private:
  114. std::map<std::string, std::shared_ptr<Theme>> themes_;
  115. std::shared_ptr<Theme> active_theme_;
  116. };
  117. } // namespace lumacs