2012-06-28 14:11:43 +02:00
|
|
|
#ifndef client_hh_INCLUDED
|
|
|
|
#define client_hh_INCLUDED
|
2012-06-06 01:15:19 +02:00
|
|
|
|
|
|
|
#include "keys.hh"
|
|
|
|
#include "completion.hh"
|
2012-08-15 22:36:45 +02:00
|
|
|
#include "utils.hh"
|
2012-09-03 14:22:02 +02:00
|
|
|
#include "string.hh"
|
2012-06-06 01:15:19 +02:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
class Editor;
|
|
|
|
class Window;
|
2012-08-05 20:13:41 +02:00
|
|
|
class Context;
|
2012-06-06 01:15:19 +02:00
|
|
|
|
2012-08-30 21:53:22 +02:00
|
|
|
enum class MenuCommand
|
|
|
|
{
|
2012-08-31 14:14:16 +02:00
|
|
|
SelectFirst,
|
2012-08-30 21:53:22 +02:00
|
|
|
SelectPrev,
|
|
|
|
SelectNext,
|
|
|
|
Close,
|
|
|
|
};
|
|
|
|
|
2012-09-03 14:22:02 +02:00
|
|
|
using MenuCallback = std::function<void (int, Context&)>;
|
|
|
|
using PromptCallback = std::function<void (const String&, Context&)>;
|
|
|
|
|
2012-08-15 22:36:45 +02:00
|
|
|
class Client : public SafeCountable
|
2012-06-06 01:15:19 +02:00
|
|
|
{
|
|
|
|
public:
|
2012-09-03 14:22:02 +02:00
|
|
|
Client();
|
2012-06-28 14:11:43 +02:00
|
|
|
virtual ~Client() {}
|
2012-09-03 14:22:02 +02:00
|
|
|
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);
|
2012-06-06 01:15:19 +02:00
|
|
|
|
2012-09-03 14:22:02 +02:00
|
|
|
void menu(const memoryview<String>& choices,
|
|
|
|
MenuCallback callback);
|
|
|
|
|
|
|
|
void handle_next_input(Context& context);
|
2012-06-06 01:15:19 +02:00
|
|
|
virtual Key get_key() = 0;
|
2012-08-30 21:53:22 +02:00
|
|
|
|
2012-09-03 14:22:02 +02:00
|
|
|
private:
|
|
|
|
|
2012-08-30 21:53:22 +02:00
|
|
|
virtual void show_menu(const memoryview<String>& choices) = 0;
|
|
|
|
virtual void menu_ctrl(MenuCommand command) = 0;
|
2012-09-03 14:22:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
2012-06-06 01:15:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct prompt_aborted {};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-28 14:11:43 +02:00
|
|
|
#endif // client_hh_INCLUDED
|