diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-09-12 23:47:23 +0200 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-09-12 23:47:23 +0200 |
| commit | 823812fd1ae92def5b42fdb7a5468281ffc0b40f (patch) | |
| tree | 97f26a6bdaa5307b02813a5c8f2839c26f1315f9 /src/client.hh | |
| parent | ac7e437730ecbe32f9e4e168a3ee4a7b7f3cd761 (diff) | |
rename InputHandler to Client
Diffstat (limited to 'src/client.hh')
| -rw-r--r-- | src/client.hh | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/client.hh b/src/client.hh new file mode 100644 index 00000000..deb44007 --- /dev/null +++ b/src/client.hh @@ -0,0 +1,99 @@ +#ifndef client_hh_INCLUDED +#define client_hh_INCLUDED + +#include "color.hh" +#include "completion.hh" +#include "context.hh" +#include "editor.hh" +#include "keys.hh" +#include "string.hh" +#include "utils.hh" + +namespace Kakoune +{ + +class Editor; + +enum class MenuEvent +{ + Select, + Abort, + Validate +}; +using MenuCallback = std::function<void (int, MenuEvent, Context&)>; + +enum class PromptEvent +{ + Change, + Abort, + Validate +}; +using PromptCallback = std::function<void (const String&, PromptEvent, Context&)>; +using KeyCallback = std::function<void (Key, Context&)>; + +class InputMode; +enum class InsertMode : unsigned; + +class Client : public SafeCountable +{ +public: + Client(std::unique_ptr<UserInterface>&& ui, Editor& editor, String name); + ~Client(); + + // switch to insert mode + void insert(InsertMode mode); + // repeat last insert mode key sequence + void repeat_last_insert(); + + // 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, ColorPair prompt_colors, + Completer completer, PromptCallback callback); + void set_prompt_colors(ColorPair prompt_colors); + + // 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(memoryview<String> choices, + MenuCallback callback); + + // execute callback on next keypress and returns to normal mode + // if callback does not change the mode itself + void on_next_key(KeyCallback callback); + + // process the given key + void handle_key(Key key); + + void start_recording(char reg); + bool is_recording() const; + void stop_recording(); + + Context& context() { return m_context; } + const String& name() const { return m_name; } + + UserInterface& ui() const { return *m_ui; } +private: + Context m_context; + friend class InputMode; + friend class ClientManager; + std::unique_ptr<UserInterface> m_ui; + std::unique_ptr<InputMode> m_mode; + std::vector<std::unique_ptr<InputMode>> m_mode_trash; + + String m_name; + + using Insertion = std::pair<InsertMode, std::vector<Key>>; + Insertion m_last_insert = {InsertMode::Insert, {}}; + + char m_recording_reg = 0; + String m_recorded_keys; +}; + +struct prompt_aborted {}; + +} + +#endif // client_hh_INCLUDED |
