theme.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. /// @brief Enumeration of standard UI elements for theming (Legacy).
  11. /// Used for mapping legacy theme definitions to the new Face system.
  12. enum class ThemeElement {
  13. // Text elements
  14. Normal,
  15. Keyword,
  16. String,
  17. Comment,
  18. Function,
  19. Type,
  20. Number,
  21. Constant,
  22. Error,
  23. Warning,
  24. Variable,
  25. Builtin,
  26. Preprocessor,
  27. Operator,
  28. // UI elements
  29. StatusLine,
  30. StatusLineInactive,
  31. MessageLine,
  32. LineNumber,
  33. LineNumberCurrent,
  34. Cursor,
  35. Selection,
  36. SearchMatch,
  37. SearchFail,
  38. MatchParen,
  39. // Minibuffer elements
  40. MinibufferPrompt,
  41. MinibufferInput,
  42. MinibufferCompletion,
  43. MinibufferMatch,
  44. // Window elements
  45. WindowBorder,
  46. WindowBorderActive,
  47. WindowSeparator,
  48. TabLine,
  49. TabLineSel,
  50. // Special
  51. Background,
  52. Foreground
  53. };
  54. /// @brief Defines a complete visual theme for the editor.
  55. ///
  56. /// A Theme is a collection of Faces (named sets of visual attributes like color and font style).
  57. /// It supports standard UI elements and custom face names.
  58. class Theme {
  59. public:
  60. explicit Theme(const std::string& name) : name_(name) {}
  61. /// @brief Set simple colors for a legacy theme element.
  62. void set_color(ThemeElement element, const Color& fg, const Color& bg = Color(-1, -1, -1));
  63. /// @brief Define a face with full attributes.
  64. void set_face(const std::string& name, const FaceAttributes& attrs);
  65. /// @brief Get attributes for a named face.
  66. std::optional<FaceAttributes> get_face(const std::string& name) const;
  67. /// @brief Get foreground color for an element (Legacy).
  68. Color get_fg_color(ThemeElement element) const;
  69. /// @brief Get background color for an element (Legacy).
  70. Color get_bg_color(ThemeElement element) const;
  71. /// @brief Get ncurses color pair ID for an element (Legacy).
  72. int get_color_pair(ThemeElement element) const;
  73. /// @brief Get ncurses color pair ID for a named face.
  74. int get_face_color_pair(const std::string& name) const;
  75. /// @brief Get ncurses attributes (color pair + flags) for a named face.
  76. int get_face_attributes_ncurses(const std::string& name) const;
  77. /// @brief Get the theme name.
  78. const std::string& name() const { return name_; }
  79. /// @brief Initialize all color pairs for ncurses (must be called after ncurses init).
  80. void initialize_ncurses_colors();
  81. /// @brief Helper to convert ThemeElement enum to standard face name string.
  82. static std::string element_to_face_name(ThemeElement element);
  83. private:
  84. std::string name_;
  85. // Storage for face definitions
  86. std::map<std::string, FaceAttributes> faces_;
  87. // Cache for ncurses pairs (mutable because generated on demand or at init)
  88. mutable std::map<std::string, int> face_pairs_;
  89. mutable int next_pair_id_ = 1;
  90. // Helper for inheritance resolution
  91. std::optional<FaceAttributes> get_face_recursive(const std::string& name, int depth) const;
  92. };
  93. /// @brief Manages available themes and the active theme.
  94. class ThemeManager {
  95. public:
  96. /// @brief Register a new theme.
  97. void register_theme(std::shared_ptr<Theme> theme);
  98. /// @brief Set the active theme by name.
  99. void set_active_theme(const std::string& name);
  100. /// @brief Get the currently active theme.
  101. std::shared_ptr<Theme> active_theme() const { return active_theme_; }
  102. /// @brief Get a list of all registered theme names.
  103. std::vector<std::string> theme_names() const;
  104. // Factory methods for built-in themes - REMOVED, now loaded from Lua
  105. // private: // If all private methods are removed, remove this too.
  106. // private: // Keeping private section if other members remain.
  107. private: // Still need this private keyword
  108. private:
  109. std::map<std::string, std::shared_ptr<Theme>> themes_;
  110. std::shared_ptr<Theme> active_theme_;
  111. };
  112. } // namespace lumacs