ui_interface.hpp 2.4 KB

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