2013-11-14 22:12:59 +01:00
|
|
|
#ifndef input_handler_hh_INCLUDED
|
|
|
|
#define input_handler_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "completion.hh"
|
|
|
|
#include "context.hh"
|
2014-07-11 01:27:04 +02:00
|
|
|
#include "face.hh"
|
2013-12-15 20:41:32 +01:00
|
|
|
#include "normal.hh"
|
2013-11-14 22:12:59 +01:00
|
|
|
#include "keys.hh"
|
|
|
|
#include "string.hh"
|
|
|
|
#include "utils.hh"
|
2014-08-12 01:30:13 +02:00
|
|
|
#include "safe_ptr.hh"
|
2013-11-14 22:12:59 +01:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
enum class MenuEvent
|
|
|
|
{
|
|
|
|
Select,
|
|
|
|
Abort,
|
|
|
|
Validate
|
|
|
|
};
|
|
|
|
using MenuCallback = std::function<void (int, MenuEvent, Context&)>;
|
|
|
|
|
|
|
|
enum class PromptEvent
|
|
|
|
{
|
|
|
|
Change,
|
|
|
|
Abort,
|
|
|
|
Validate
|
|
|
|
};
|
2014-11-01 20:31:13 +01:00
|
|
|
using PromptCallback = std::function<void (StringView, PromptEvent, Context&)>;
|
2013-11-14 22:12:59 +01:00
|
|
|
using KeyCallback = std::function<void (Key, Context&)>;
|
|
|
|
|
|
|
|
class InputMode;
|
2014-09-10 20:06:53 +02:00
|
|
|
class DisplayLine;
|
2013-11-14 22:12:59 +01:00
|
|
|
enum class InsertMode : unsigned;
|
2014-09-23 14:45:18 +02:00
|
|
|
enum class KeymapMode : int;
|
2013-11-14 22:12:59 +01:00
|
|
|
|
|
|
|
class InputHandler : public SafeCountable
|
|
|
|
{
|
|
|
|
public:
|
2014-12-19 00:12:58 +01:00
|
|
|
InputHandler(SelectionList selections,
|
|
|
|
Context::Flags flags = Context::Flags::None,
|
|
|
|
String name = "");
|
2013-11-14 22:12:59 +01:00
|
|
|
~InputHandler();
|
|
|
|
|
|
|
|
// 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
|
2014-11-01 20:31:13 +01:00
|
|
|
void prompt(StringView prompt, String initstr,
|
2014-07-11 01:27:04 +02:00
|
|
|
Face prompt_face, Completer completer,
|
2014-04-26 16:09:07 +02:00
|
|
|
PromptCallback callback);
|
2014-07-11 01:27:04 +02:00
|
|
|
void set_prompt_face(Face prompt_face);
|
2013-11-14 22:12:59 +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
|
2015-03-09 14:48:41 +01:00
|
|
|
void menu(ArrayView<const String> choices, MenuCallback callback);
|
2013-11-14 22:12:59 +01:00
|
|
|
|
|
|
|
// execute callback on next keypress and returns to normal mode
|
|
|
|
// if callback does not change the mode itself
|
2014-09-23 14:45:18 +02:00
|
|
|
void on_next_key(KeymapMode mode, KeyCallback callback);
|
2013-11-14 22:12:59 +01:00
|
|
|
|
|
|
|
// process the given key
|
|
|
|
void handle_key(Key key);
|
|
|
|
|
|
|
|
void start_recording(char reg);
|
|
|
|
bool is_recording() const;
|
|
|
|
void stop_recording();
|
|
|
|
char recording_reg() const { return m_recording_reg; }
|
|
|
|
|
|
|
|
void reset_normal_mode();
|
|
|
|
|
|
|
|
Context& context() { return m_context; }
|
|
|
|
const Context& context() const { return m_context; }
|
|
|
|
|
2014-09-10 20:06:53 +02:00
|
|
|
DisplayLine mode_line() const;
|
2013-11-14 22:12:59 +01:00
|
|
|
void clear_mode_trash();
|
2014-12-19 00:12:58 +01:00
|
|
|
|
2013-11-14 22:12:59 +01:00
|
|
|
private:
|
|
|
|
Context m_context;
|
|
|
|
|
|
|
|
friend class InputMode;
|
|
|
|
std::unique_ptr<InputMode> m_mode;
|
2015-01-12 14:58:41 +01:00
|
|
|
Vector<std::unique_ptr<InputMode>> m_mode_trash;
|
2013-11-14 22:12:59 +01:00
|
|
|
|
|
|
|
void change_input_mode(InputMode* new_mode);
|
|
|
|
|
2015-01-12 14:58:41 +01:00
|
|
|
using Insertion = std::pair<InsertMode, Vector<Key>>;
|
2013-11-14 22:12:59 +01:00
|
|
|
Insertion m_last_insert = {InsertMode::Insert, {}};
|
|
|
|
|
|
|
|
char m_recording_reg = 0;
|
|
|
|
String m_recorded_keys;
|
2014-11-21 20:00:34 +01:00
|
|
|
|
|
|
|
int m_handle_key_level = 0;
|
2013-11-14 22:12:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // input_handler_hh_INCLUDED
|