diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-09-03 14:22:02 +0200 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-09-03 14:22:02 +0200 |
| commit | b08d8719e6a5b6cee67f93a9c62117b747ae4430 (patch) | |
| tree | 44c255b6f2415563c35b2ba1c79c91056a3fc2b9 /src/client.hh | |
| parent | d5f5f0989d516a3954876272b496c5e9b628c66a (diff) | |
move input handling, including menu and prompt, to the Client class
Diffstat (limited to 'src/client.hh')
| -rw-r--r-- | src/client.hh | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/src/client.hh b/src/client.hh index ea2d6e0a..dc830577 100644 --- a/src/client.hh +++ b/src/client.hh @@ -4,13 +4,13 @@ #include "keys.hh" #include "completion.hh" #include "utils.hh" +#include "string.hh" namespace Kakoune { class Editor; class Window; -class String; class Context; enum class MenuCommand @@ -21,19 +21,48 @@ enum class MenuCommand Close, }; +using MenuCallback = std::function<void (int, Context&)>; +using PromptCallback = std::function<void (const String&, Context&)>; + class Client : public SafeCountable { public: + Client(); virtual ~Client() {} + virtual void draw_window(Window& window) = 0; + virtual void print_status(const String& status, + CharCount cursor_pos = -1) = 0; + + void prompt(const String& prompt, Completer completer, + PromptCallback callback); - virtual void draw_window(Window& window) = 0; - virtual void print_status(const String& status) = 0; - virtual String prompt(const String& prompt, const Context& context, - Completer completer = complete_nothing) = 0; + void menu(const memoryview<String>& choices, + MenuCallback callback); + + void handle_next_input(Context& context); virtual Key get_key() = 0; +private: + virtual void show_menu(const memoryview<String>& choices) = 0; virtual void menu_ctrl(MenuCommand command) = 0; + + + void reset_normal_mode(); + class Mode + { + public: + Mode(Client& client) : m_client(client) {} + virtual ~Mode() {} + virtual void on_key(const Key& key, Context& context) = 0; + protected: + Client& m_client; + }; + std::unique_ptr<Mode> m_mode; + + class NormalMode; + class MenuMode; + class PromptMode; }; struct prompt_aborted {}; |
