2013-09-12 23:47:23 +02:00
|
|
|
#ifndef client_hh_INCLUDED
|
|
|
|
#define client_hh_INCLUDED
|
2012-06-06 01:15:19 +02:00
|
|
|
|
2013-04-09 19:39:03 +02:00
|
|
|
#include "color.hh"
|
2012-06-06 01:15:19 +02:00
|
|
|
#include "completion.hh"
|
2013-01-28 13:48:34 +01:00
|
|
|
#include "context.hh"
|
2013-04-09 19:39:03 +02:00
|
|
|
#include "editor.hh"
|
|
|
|
#include "keys.hh"
|
|
|
|
#include "string.hh"
|
|
|
|
#include "utils.hh"
|
2013-09-16 20:15:13 +02:00
|
|
|
#include "display_buffer.hh"
|
2012-06-06 01:15:19 +02:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
class Editor;
|
|
|
|
|
2012-12-14 19:38:11 +01:00
|
|
|
enum class MenuEvent
|
|
|
|
{
|
|
|
|
Select,
|
|
|
|
Abort,
|
|
|
|
Validate
|
|
|
|
};
|
|
|
|
using MenuCallback = std::function<void (int, MenuEvent, Context&)>;
|
2012-12-05 19:22:40 +01:00
|
|
|
|
|
|
|
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-09-03 14:22:02 +02:00
|
|
|
|
2012-10-17 13:14:03 +02:00
|
|
|
class InputMode;
|
2012-09-26 14:22:24 +02:00
|
|
|
enum class InsertMode : unsigned;
|
2012-09-24 19:39:40 +02:00
|
|
|
|
2013-11-14 19:09:15 +01:00
|
|
|
class InputHandler : public SafeCountable
|
2012-06-06 01:15:19 +02:00
|
|
|
{
|
|
|
|
public:
|
2013-11-14 21:51:25 +01:00
|
|
|
InputHandler(Editor& editor, String name = "");
|
2013-11-14 19:09:15 +01:00
|
|
|
~InputHandler();
|
2012-09-03 14:22:02 +02:00
|
|
|
|
2013-01-17 14:27:32 +01:00
|
|
|
// switch to insert mode
|
2013-01-29 13:49:01 +01:00
|
|
|
void insert(InsertMode mode);
|
2013-01-17 14:27:32 +01:00
|
|
|
// repeat last insert mode key sequence
|
2013-01-29 13:49:01 +01:00
|
|
|
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
|
2013-04-04 19:03:59 +02:00
|
|
|
void prompt(const String& prompt, ColorPair prompt_colors,
|
|
|
|
Completer completer, PromptCallback callback);
|
2013-04-04 19:09:34 +02:00
|
|
|
void set_prompt_colors(ColorPair prompt_colors);
|
2012-06-06 01:15:19 +02:00
|
|
|
|
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,
|
2013-01-29 13:49:01 +01:00
|
|
|
MenuCallback callback);
|
2012-09-24 19:24:27 +02:00
|
|
|
|
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
|
2012-09-05 00:21:19 +02:00
|
|
|
void on_next_key(KeyCallback callback);
|
|
|
|
|
2013-09-11 19:54:30 +02:00
|
|
|
// process the given key
|
|
|
|
void handle_key(Key key);
|
2012-08-30 21:53:22 +02:00
|
|
|
|
2013-02-18 18:58:07 +01:00
|
|
|
void start_recording(char reg);
|
|
|
|
bool is_recording() const;
|
|
|
|
void stop_recording();
|
2013-11-14 19:09:15 +01:00
|
|
|
char recording_reg() const { return m_recording_reg; }
|
|
|
|
|
|
|
|
void reset_normal_mode();
|
2013-02-18 18:58:07 +01:00
|
|
|
|
2013-01-28 13:48:34 +01:00
|
|
|
Context& context() { return m_context; }
|
2013-10-10 22:34:19 +02:00
|
|
|
const Context& context() const { return m_context; }
|
2013-11-14 19:09:15 +01:00
|
|
|
|
|
|
|
const InputMode& mode() const { return *m_mode; }
|
|
|
|
void clear_mode_trash();
|
|
|
|
private:
|
|
|
|
Context m_context;
|
|
|
|
|
|
|
|
friend class InputMode;
|
|
|
|
std::unique_ptr<InputMode> m_mode;
|
|
|
|
std::vector<std::unique_ptr<InputMode>> m_mode_trash;
|
|
|
|
|
|
|
|
void change_input_mode(InputMode* new_mode);
|
|
|
|
|
|
|
|
using Insertion = std::pair<InsertMode, std::vector<Key>>;
|
|
|
|
Insertion m_last_insert = {InsertMode::Insert, {}};
|
|
|
|
|
|
|
|
char m_recording_reg = 0;
|
|
|
|
String m_recorded_keys;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Client : public SafeCountable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Client(std::unique_ptr<UserInterface>&& ui, Editor& editor, String name);
|
|
|
|
~Client();
|
|
|
|
|
|
|
|
// handle all the keys currently available in the user interface
|
|
|
|
void handle_available_input();
|
|
|
|
|
2013-09-16 20:15:13 +02:00
|
|
|
void print_status(DisplayLine status_line);
|
|
|
|
|
|
|
|
void redraw_ifn();
|
|
|
|
|
2013-09-12 23:39:34 +02:00
|
|
|
UserInterface& ui() const { return *m_ui; }
|
2013-10-15 19:50:43 +02:00
|
|
|
|
2013-10-15 19:51:31 +02:00
|
|
|
void check_buffer_fs_timestamp();
|
|
|
|
|
2013-11-14 19:09:15 +01:00
|
|
|
Context& context() { return m_input_handler.context(); }
|
|
|
|
const Context& context() const { return m_input_handler.context(); }
|
|
|
|
|
2012-09-03 14:22:02 +02:00
|
|
|
private:
|
2013-11-14 19:09:15 +01:00
|
|
|
InputHandler m_input_handler;
|
2013-10-10 22:34:19 +02:00
|
|
|
|
|
|
|
DisplayLine generate_mode_line() const;
|
|
|
|
|
2013-09-12 23:39:34 +02:00
|
|
|
std::unique_ptr<UserInterface> m_ui;
|
2013-02-18 14:07:30 +01:00
|
|
|
|
2013-09-16 20:15:13 +02:00
|
|
|
DisplayLine m_status_line;
|
2012-06-06 01:15:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-09-12 23:47:23 +02:00
|
|
|
#endif // client_hh_INCLUDED
|