ui_interface.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include <functional> // Required for EventCallback
  3. namespace lumacs {
  4. // Forward declarations
  5. class EditorCore;
  6. /// @brief Editor state change events triggered by core actions.
  7. /// Used by the UI layer to react to model updates.
  8. enum class EditorEvent {
  9. BufferModified, ///< The content of the active buffer has changed.
  10. CursorMoved, ///< The cursor position has changed.
  11. ViewportChanged, ///< The visible area (scroll/size) has changed.
  12. WindowLayoutChanged, ///< The window tree structure (splits) has changed.
  13. WindowFocused, ///< A different window has gained focus.
  14. Message, ///< A transient message should be displayed (e.g., in minibuffer).
  15. // Modal Interaction Events
  16. CommandMode, ///< Enter command input mode (M-x).
  17. BufferSwitchMode, ///< Enter buffer switching mode (C-x b).
  18. KillBufferMode, ///< Enter kill buffer mode (C-x k).
  19. FindFileMode, ///< Enter file finding mode (C-x C-f).
  20. ThemeSelectionMode, ///< Enter theme selection mode.
  21. ISearchMode, ///< Enter incremental search mode (C-s).
  22. ISearchBackwardMode, ///< Enter backward incremental search mode (C-r).
  23. TransientMessageCleared, ///< A transient message has been cleared.
  24. Quit, ///< The application should exit.
  25. ThemeChanged ///< The active theme has changed.
  26. };
  27. /// @brief Abstract interface for a Lumacs editor UI frontend.
  28. ///
  29. /// All editor UIs (ncurses, GTK, etc.) must implement this interface.
  30. /// This decouples the core logic from the specific display technology.
  31. class IEditorView {
  32. public:
  33. virtual ~IEditorView() = default;
  34. /// @brief Initialize the UI system (e.g., ncurses init, GTK window setup).
  35. /// This should be called before run().
  36. virtual void init() = 0;
  37. /// @brief Run the main UI loop.
  38. /// This method should block until the UI exits (e.g., gtk_main()).
  39. virtual void run() = 0;
  40. /// @brief Handle events emitted by the EditorCore.
  41. /// The EditorCore will notify the view of model changes (buffer modified, cursor moved).
  42. /// @param event The event type.
  43. virtual void handle_editor_event(EditorEvent event) = 0;
  44. /// @brief Set the EditorCore instance for the view to interact with.
  45. /// This is typically called once during setup.
  46. /// @param core Pointer to the core logic instance.
  47. virtual void set_core(EditorCore* core) = 0;
  48. };
  49. } // namespace lumacs