#ifndef input_handler_hh_INCLUDED #define input_handler_hh_INCLUDED #include "keys.hh" #include "completion.hh" #include "utils.hh" #include "string.hh" #include "context.hh" namespace Kakoune { class Editor; enum class MenuEvent { Select, Abort, Validate }; using MenuCallback = std::function; enum class PromptEvent { Change, Abort, Validate }; using PromptCallback = std::function; using KeyCallback = std::function; class InputMode; enum class InsertMode : unsigned; class InputHandler : public SafeCountable { public: InputHandler(UserInterface& ui); ~InputHandler(); // switch to insert mode void insert(Context& context, InsertMode mode); // repeat last insert mode key sequence void repeat_last_insert(Context& context); // enter prompt mode, callback is called on each change, // abort or validation with corresponding PromptEvent value // returns to normal mode after validation if callback does // not change the mode itself void prompt(const String& prompt, Completer completer, PromptCallback callback, Context& context); // enter menu mode, callback is called on each selection change, // abort or validation with corresponding MenuEvent value // returns to normal mode after validation if callback does // not change the mode itself void menu(const memoryview& choices, MenuCallback callback, Context& context); // execute callback on next keypress and returns to normal mode // if callback does not change the mode itself void on_next_key(KeyCallback callback); // read and process all inputs available in context // user interface void handle_available_inputs(Context& context); Context& context() { return m_context; } private: Context m_context; friend class InputMode; std::unique_ptr m_mode; std::vector> m_mode_trash; }; struct prompt_aborted {}; } #endif // input_handler_hh_INCLUDED