kakoune/src/client.hh

114 lines
2.9 KiB
C++
Raw Normal View History

2013-09-12 23:47:23 +02:00
#ifndef client_hh_INCLUDED
#define client_hh_INCLUDED
#include "color.hh"
#include "completion.hh"
2013-01-28 13:48:34 +01:00
#include "context.hh"
#include "editor.hh"
#include "keys.hh"
#include "string.hh"
#include "utils.hh"
#include "display_buffer.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&)>;
2013-07-26 01:44:25 +02:00
using KeyCallback = std::function<void (Key, Context&)>;
2012-10-17 13:14:03 +02:00
class InputMode;
enum class InsertMode : unsigned;
2012-09-24 19:39:40 +02:00
2013-09-12 23:47:23 +02:00
class Client : public SafeCountable
{
public:
2013-09-12 23:47:23 +02:00
Client(std::unique_ptr<UserInterface>&& ui, Editor& editor, String name);
~Client();
2013-01-17 14:27:32 +01:00
// switch to insert mode
void insert(InsertMode mode);
2013-01-17 14:27:32 +01:00
// repeat last insert mode key sequence
void repeat_last_insert();
2012-09-05 14:27:14 +02:00
2013-01-17 14:27:32 +01:00
// 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);
2013-01-17 14:27:32 +01:00
// 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
2013-07-26 01:17:12 +02:00
void menu(memoryview<String> choices,
MenuCallback callback);
2013-01-17 14:27:32 +01:00
// execute callback on next keypress and returns to normal mode
// if callback does not change the mode itself
void on_next_key(KeyCallback callback);
// handle all the keys currently available in the user interface
void handle_available_input();
// process the given key
void handle_key(Key key);
2013-02-18 18:58:07 +01:00
void start_recording(char reg);
bool is_recording() const;
void stop_recording();
2013-01-28 13:48:34 +01:00
Context& context() { return m_context; }
const Context& context() const { return m_context; }
const String& name() const { return m_name; }
2013-09-13 00:01:47 +02:00
void set_name(String name) { m_name = std::move(name); }
void print_status(DisplayLine status_line);
void redraw_ifn();
UserInterface& ui() const { return *m_ui; }
void reset_normal_mode();
private:
void change_input_mode(InputMode* new_mode);
DisplayLine generate_mode_line() const;
2013-01-28 13:48:34 +01:00
Context m_context;
2012-10-17 13:14:03 +02:00
friend class InputMode;
std::unique_ptr<UserInterface> m_ui;
2012-10-17 13:14:03 +02:00
std::unique_ptr<InputMode> m_mode;
std::vector<std::unique_ptr<InputMode>> m_mode_trash;
String m_name;
DisplayLine m_status_line;
using Insertion = std::pair<InsertMode, std::vector<Key>>;
Insertion m_last_insert = {InsertMode::Insert, {}};
2013-02-18 18:58:07 +01:00
char m_recording_reg = 0;
String m_recorded_keys;
};
}
2013-09-12 23:47:23 +02:00
#endif // client_hh_INCLUDED