theme.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #pragma once
  2. #include <string>
  3. #include <map>
  4. #include <memory>
  5. #include <vector>
  6. namespace lumacs {
  7. /// RGB Color representation
  8. struct Color {
  9. int r, g, b;
  10. Color(int r = 0, int g = 0, int b = 0) : r(r), g(g), b(b) {}
  11. /// Convert to ncurses color index (will be assigned dynamically)
  12. int to_ncurses_color() const;
  13. /// Comparison operator for use in maps
  14. bool operator<(const Color& other) const;
  15. };
  16. /// Theme element types
  17. enum class ThemeElement {
  18. // Text elements
  19. Normal,
  20. Keyword,
  21. String,
  22. Comment,
  23. Function,
  24. Type,
  25. Number,
  26. Constant,
  27. Error,
  28. // UI elements
  29. StatusLine,
  30. StatusLineInactive,
  31. MessageLine,
  32. LineNumber,
  33. Cursor,
  34. Selection,
  35. SearchMatch,
  36. SearchFail,
  37. // Window elements
  38. WindowBorder,
  39. WindowBorderActive,
  40. // Special
  41. Background
  42. };
  43. /// A theme defines colors and attributes for various UI elements
  44. class Theme {
  45. public:
  46. Theme(const std::string& name) : name_(name) {}
  47. /// Set color for a theme element
  48. void set_color(ThemeElement element, const Color& fg, const Color& bg = Color(-1, -1, -1));
  49. /// Get foreground color for an element
  50. Color get_fg_color(ThemeElement element) const;
  51. /// Get background color for an element
  52. Color get_bg_color(ThemeElement element) const;
  53. /// Get ncurses color pair for an element
  54. int get_color_pair(ThemeElement element) const;
  55. /// Theme name
  56. const std::string& name() const { return name_; }
  57. /// Initialize all color pairs for ncurses
  58. void initialize_ncurses_colors();
  59. private:
  60. std::string name_;
  61. std::map<ThemeElement, std::pair<Color, Color>> colors_; // fg, bg
  62. mutable std::map<ThemeElement, int> color_pairs_;
  63. mutable int next_pair_id_ = 1;
  64. };
  65. /// Theme manager - handles multiple themes and switching between them
  66. class ThemeManager {
  67. public:
  68. /// Register a new theme
  69. void register_theme(std::shared_ptr<Theme> theme);
  70. /// Set the active theme
  71. void set_active_theme(const std::string& name);
  72. /// Get the active theme
  73. std::shared_ptr<Theme> active_theme() const { return active_theme_; }
  74. /// Get available theme names
  75. std::vector<std::string> theme_names() const;
  76. /// Create default themes
  77. void create_default_themes();
  78. /// Create Everforest dark theme
  79. std::shared_ptr<Theme> create_everforest_theme();
  80. /// Create default light theme
  81. std::shared_ptr<Theme> create_default_theme();
  82. private:
  83. std::map<std::string, std::shared_ptr<Theme>> themes_;
  84. std::shared_ptr<Theme> active_theme_;
  85. };
  86. } // namespace lumacs