modeline.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include <string>
  3. #include <vector>
  4. #include <memory>
  5. #include <functional>
  6. namespace lumacs {
  7. class Window; // Forward declaration
  8. /// @brief Represents a chunk of text in the modeline with a specific face.
  9. struct ModelineChunk {
  10. std::string text; ///< The text content to display.
  11. std::string face_name; ///< The face name for styling (e.g., "mode-line", "mode-line-inactive").
  12. };
  13. /// @brief Interface for a modeline segment (e.g., buffer name, line number).
  14. class ModelineSegment {
  15. public:
  16. virtual ~ModelineSegment() = default;
  17. /// @brief Generate the text chunks for this segment.
  18. /// @param window The window context.
  19. /// @param active Whether the window is currently focused.
  20. /// @return A vector of styled text chunks.
  21. virtual std::vector<ModelineChunk> generate(const std::shared_ptr<Window>& window, bool active) = 0;
  22. /// @brief Get the unique name of the segment (for debugging/config).
  23. virtual std::string name() const = 0;
  24. };
  25. /// @brief Manages the composition of the modeline from various segments.
  26. class ModelineManager {
  27. public:
  28. ModelineManager();
  29. /// @brief Initialize the default set of segments.
  30. void create_default_segments();
  31. /// @brief Register a new segment to be displayed.
  32. void add_segment(std::shared_ptr<ModelineSegment> segment);
  33. /// @brief Remove all registered segments.
  34. void clear_segments();
  35. /// @brief Generate the complete modeline content for a specific window.
  36. /// @param window The window to generate modeline for.
  37. /// @param active Whether the window is active (focused).
  38. /// @return Full list of styled chunks.
  39. std::vector<ModelineChunk> generate_content(const std::shared_ptr<Window>& window, bool active);
  40. private:
  41. std::vector<std::shared_ptr<ModelineSegment>> segments_;
  42. };
  43. } // namespace lumacs