ui_interface.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. FontChanged ///< The font size has changed.
  27. };
  28. /// @brief Abstract interface for a Lumacs editor UI frontend.
  29. ///
  30. /// All editor UIs (ncurses, GTK, etc.) must implement this interface.
  31. /// This decouples the core logic from the specific display technology.
  32. class IEditorView {
  33. public:
  34. virtual ~IEditorView() = default;
  35. /// @brief Initialize the UI system (e.g., ncurses init, GTK window setup).
  36. /// This should be called before run().
  37. virtual void init() = 0;
  38. /// @brief Run the main UI loop.
  39. /// This method should block until the UI exits (e.g., gtk_main()).
  40. virtual void run() = 0;
  41. /// @brief Handle events emitted by the EditorCore.
  42. /// The EditorCore will notify the view of model changes (buffer modified, cursor moved).
  43. /// @param event The event type.
  44. virtual void handle_editor_event(EditorEvent event) = 0;
  45. /// @brief Set the EditorCore instance for the view to interact with.
  46. /// This is typically called once during setup.
  47. /// @param core Pointer to the core logic instance.
  48. virtual void set_core(EditorCore* core) = 0;
  49. };
  50. } // namespace lumacs