2013-11-15 01:12:59 +04:00
|
|
|
#ifndef input_handler_hh_INCLUDED
|
|
|
|
#define input_handler_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "completion.hh"
|
|
|
|
#include "context.hh"
|
2014-07-11 03:27:04 +04:00
|
|
|
#include "face.hh"
|
2013-12-15 23:41:32 +04:00
|
|
|
#include "normal.hh"
|
2013-11-15 01:12:59 +04:00
|
|
|
#include "keys.hh"
|
|
|
|
#include "string.hh"
|
|
|
|
#include "utils.hh"
|
2014-08-12 03:30:13 +04:00
|
|
|
#include "safe_ptr.hh"
|
2016-02-27 20:23:13 +03:00
|
|
|
#include "display_buffer.hh"
|
2013-11-15 01:12:59 +04: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 22:31:13 +03:00
|
|
|
using PromptCallback = std::function<void (StringView, PromptEvent, Context&)>;
|
2016-08-22 22:31:08 +03:00
|
|
|
enum class PromptFlags
|
|
|
|
{
|
|
|
|
None = 0,
|
|
|
|
Password = 1 << 0,
|
2017-10-28 05:07:28 +03:00
|
|
|
DropHistoryEntriesWithBlankPrefix = 1 << 1,
|
2016-08-22 22:31:08 +03:00
|
|
|
};
|
2017-03-15 20:55:34 +03:00
|
|
|
constexpr bool with_bit_ops(Meta::Type<PromptFlags>) { return true; }
|
2016-08-22 22:31:08 +03:00
|
|
|
|
|
|
|
|
2013-11-15 01:12:59 +04:00
|
|
|
using KeyCallback = std::function<void (Key, Context&)>;
|
|
|
|
|
|
|
|
class InputMode;
|
|
|
|
enum class InsertMode : unsigned;
|
2015-04-11 19:22:37 +03:00
|
|
|
enum class KeymapMode : char;
|
2017-04-12 12:39:17 +03:00
|
|
|
enum class CursorMode;
|
2013-11-15 01:12:59 +04:00
|
|
|
|
|
|
|
class InputHandler : public SafeCountable
|
|
|
|
{
|
|
|
|
public:
|
2014-12-19 02:12:58 +03:00
|
|
|
InputHandler(SelectionList selections,
|
|
|
|
Context::Flags flags = Context::Flags::None,
|
|
|
|
String name = "");
|
2013-11-15 01:12:59 +04:00
|
|
|
~InputHandler();
|
|
|
|
|
|
|
|
// switch to insert mode
|
2016-10-24 21:41:05 +03:00
|
|
|
void insert(InsertMode mode, int count);
|
2013-11-15 01:12:59 +04:00
|
|
|
// 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
|
2017-10-31 04:54:21 +03:00
|
|
|
void prompt(StringView prompt, String initstr, String emptystr,
|
2016-08-22 22:31:08 +03:00
|
|
|
Face prompt_face, PromptFlags flags,
|
2016-04-19 11:51:09 +03:00
|
|
|
Completer completer, PromptCallback callback);
|
2014-07-11 03:27:04 +04:00
|
|
|
void set_prompt_face(Face prompt_face);
|
2013-11-15 01:12:59 +04: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
|
2016-02-27 20:23:13 +03:00
|
|
|
void menu(Vector<DisplayLine> choices, MenuCallback callback);
|
2013-11-15 01:12:59 +04:00
|
|
|
|
|
|
|
// execute callback on next keypress and returns to normal mode
|
|
|
|
// if callback does not change the mode itself
|
2014-09-23 16:45:18 +04:00
|
|
|
void on_next_key(KeymapMode mode, KeyCallback callback);
|
2013-11-15 01:12:59 +04: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 22:06:53 +04:00
|
|
|
DisplayLine mode_line() const;
|
2014-12-19 02:12:58 +03:00
|
|
|
|
2017-04-12 12:39:17 +03:00
|
|
|
std::pair<CursorMode, DisplayCoord> get_cursor_info() const;
|
|
|
|
|
2016-03-23 01:54:29 +03:00
|
|
|
// Force an input handler into normal mode temporarily
|
|
|
|
struct ScopedForceNormal
|
|
|
|
{
|
2016-11-03 02:12:57 +03:00
|
|
|
ScopedForceNormal(InputHandler& handler, NormalParams params);
|
2016-03-23 01:54:29 +03:00
|
|
|
~ScopedForceNormal();
|
|
|
|
|
|
|
|
private:
|
|
|
|
InputHandler& m_handler;
|
|
|
|
InputMode* m_mode;
|
|
|
|
};
|
|
|
|
|
2013-11-15 01:12:59 +04:00
|
|
|
private:
|
|
|
|
Context m_context;
|
|
|
|
|
|
|
|
friend class InputMode;
|
2016-11-28 16:59:55 +03:00
|
|
|
Vector<RefPtr<InputMode>, MemoryDomain::Client> m_mode_stack;
|
2013-11-15 01:12:59 +04:00
|
|
|
|
2015-06-02 22:56:57 +03:00
|
|
|
InputMode& current_mode() const { return *m_mode_stack.back(); }
|
|
|
|
|
|
|
|
void push_mode(InputMode* new_mode);
|
2015-12-13 02:51:51 +03:00
|
|
|
void pop_mode(InputMode* current_mode);
|
2013-11-15 01:12:59 +04:00
|
|
|
|
2017-06-25 09:25:31 +03:00
|
|
|
struct Insertion{ InsertMode mode; Vector<Key> keys; bool disable_hooks; int count; };
|
|
|
|
Insertion m_last_insert = { InsertMode::Insert, {}, false, 1 };
|
2013-11-15 01:12:59 +04:00
|
|
|
|
|
|
|
char m_recording_reg = 0;
|
|
|
|
String m_recorded_keys;
|
2016-04-13 23:21:49 +03:00
|
|
|
int m_recording_level = -1;
|
2014-11-21 22:00:34 +03:00
|
|
|
|
|
|
|
int m_handle_key_level = 0;
|
2013-11-15 01:12:59 +04:00
|
|
|
};
|
|
|
|
|
2015-11-20 11:50:53 +03:00
|
|
|
enum class AutoInfo
|
|
|
|
{
|
|
|
|
None = 0,
|
|
|
|
Command = 1 << 0,
|
|
|
|
OnKey = 1 << 1,
|
|
|
|
Normal = 1 << 2
|
|
|
|
};
|
|
|
|
|
2017-03-15 20:55:34 +03:00
|
|
|
constexpr bool with_bit_ops(Meta::Type<AutoInfo>) { return true; }
|
2015-11-20 11:50:53 +03:00
|
|
|
|
2017-08-12 18:11:58 +03:00
|
|
|
constexpr auto enum_desc(Meta::Type<AutoInfo>)
|
2015-11-20 11:50:53 +03:00
|
|
|
{
|
2017-08-18 04:15:18 +03:00
|
|
|
return make_array<EnumDesc<AutoInfo>, 3>({
|
2015-11-20 11:50:53 +03:00
|
|
|
{ AutoInfo::Command, "command"},
|
|
|
|
{ AutoInfo::OnKey, "onkey"},
|
|
|
|
{ AutoInfo::Normal, "normal" }
|
2017-08-12 18:11:58 +03:00
|
|
|
});
|
2015-11-20 11:50:53 +03:00
|
|
|
}
|
|
|
|
|
2015-11-19 02:43:51 +03:00
|
|
|
bool show_auto_info_ifn(StringView title, StringView info, AutoInfo mask, const Context& context);
|
2016-02-27 20:23:13 +03:00
|
|
|
void hide_auto_info_ifn(const Context& context, bool hide);
|
2015-08-11 22:36:07 +03:00
|
|
|
|
|
|
|
template<typename Cmd>
|
|
|
|
void on_next_key_with_autoinfo(const Context& context, KeymapMode keymap_mode, Cmd cmd,
|
|
|
|
StringView title, StringView info)
|
|
|
|
{
|
2015-11-19 02:43:51 +03:00
|
|
|
const bool hide = show_auto_info_ifn(title, info, AutoInfo::OnKey, context);
|
2015-08-11 22:36:07 +03:00
|
|
|
context.input_handler().on_next_key(
|
|
|
|
keymap_mode, [hide,cmd](Key key, Context& context) mutable {
|
2016-02-27 20:23:13 +03:00
|
|
|
hide_auto_info_ifn(context, hide);
|
2015-08-11 22:36:07 +03:00
|
|
|
cmd(key, context);
|
|
|
|
});
|
|
|
|
}
|
2016-02-27 20:23:13 +03:00
|
|
|
|
2016-07-28 11:51:49 +03:00
|
|
|
void scroll_window(Context& context, LineCount offset);
|
|
|
|
|
2013-11-15 01:12:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // input_handler_hh_INCLUDED
|