rename InputHandler to Client
This commit is contained in:
parent
ac7e437730
commit
823812fd1a
|
@ -1,4 +1,4 @@
|
||||||
#include "input_handler.hh"
|
#include "client.hh"
|
||||||
|
|
||||||
#include "color_registry.hh"
|
#include "color_registry.hh"
|
||||||
#include "context.hh"
|
#include "context.hh"
|
||||||
|
@ -20,21 +20,21 @@ namespace Kakoune
|
||||||
class InputMode
|
class InputMode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InputMode(InputHandler& input_handler) : m_input_handler(input_handler) {}
|
InputMode(Client& client) : m_client(client) {}
|
||||||
virtual ~InputMode() {}
|
virtual ~InputMode() {}
|
||||||
InputMode(const InputMode&) = delete;
|
InputMode(const InputMode&) = delete;
|
||||||
InputMode& operator=(const InputMode&) = delete;
|
InputMode& operator=(const InputMode&) = delete;
|
||||||
|
|
||||||
virtual void on_key(Key key) = 0;
|
virtual void on_key(Key key) = 0;
|
||||||
Context& context() const { return m_input_handler.context(); }
|
Context& context() const { return m_client.context(); }
|
||||||
|
|
||||||
using Insertion = InputHandler::Insertion;
|
using Insertion = Client::Insertion;
|
||||||
Insertion& last_insert() { return m_input_handler.m_last_insert; }
|
Insertion& last_insert() { return m_client.m_last_insert; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
InputMode& reset_normal_mode();
|
InputMode& reset_normal_mode();
|
||||||
private:
|
private:
|
||||||
InputHandler& m_input_handler;
|
Client& m_client;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace InputModes
|
namespace InputModes
|
||||||
|
@ -45,8 +45,8 @@ static constexpr std::chrono::milliseconds idle_timeout{100};
|
||||||
class Normal : public InputMode
|
class Normal : public InputMode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Normal(InputHandler& input_handler)
|
Normal(Client& client)
|
||||||
: InputMode(input_handler),
|
: InputMode(client),
|
||||||
m_idle_timer{Clock::now() + idle_timeout, [this](Timer& timer) {
|
m_idle_timer{Clock::now() + idle_timeout, [this](Timer& timer) {
|
||||||
context().hooks().run_hook("NormalIdle", "", context());
|
context().hooks().run_hook("NormalIdle", "", context());
|
||||||
}}
|
}}
|
||||||
|
@ -162,9 +162,9 @@ private:
|
||||||
class Menu : public InputMode
|
class Menu : public InputMode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Menu(InputHandler& input_handler, memoryview<String> choices,
|
Menu(Client& client, memoryview<String> choices,
|
||||||
MenuCallback callback)
|
MenuCallback callback)
|
||||||
: InputMode(input_handler),
|
: InputMode(client),
|
||||||
m_callback(callback), m_choices(choices.begin(), choices.end()),
|
m_callback(callback), m_choices(choices.begin(), choices.end()),
|
||||||
m_selected(m_choices.begin())
|
m_selected(m_choices.begin())
|
||||||
{
|
{
|
||||||
|
@ -291,9 +291,9 @@ String common_prefix(memoryview<String> strings)
|
||||||
class Prompt : public InputMode
|
class Prompt : public InputMode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Prompt(InputHandler& input_handler, const String& prompt,
|
Prompt(Client& client, const String& prompt,
|
||||||
ColorPair colors, Completer completer, PromptCallback callback)
|
ColorPair colors, Completer completer, PromptCallback callback)
|
||||||
: InputMode(input_handler), m_prompt(prompt), m_prompt_colors(colors),
|
: InputMode(client), m_prompt(prompt), m_prompt_colors(colors),
|
||||||
m_completer(completer), m_callback(callback)
|
m_completer(completer), m_callback(callback)
|
||||||
{
|
{
|
||||||
m_history_it = ms_history[m_prompt].end();
|
m_history_it = ms_history[m_prompt].end();
|
||||||
|
@ -474,8 +474,8 @@ std::unordered_map<String, std::vector<String>> Prompt::ms_history;
|
||||||
class NextKey : public InputMode
|
class NextKey : public InputMode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NextKey(InputHandler& input_handler, KeyCallback callback)
|
NextKey(Client& client, KeyCallback callback)
|
||||||
: InputMode(input_handler), m_callback(callback) {}
|
: InputMode(client), m_callback(callback) {}
|
||||||
|
|
||||||
void on_key(Key key) override
|
void on_key(Key key) override
|
||||||
{
|
{
|
||||||
|
@ -795,8 +795,8 @@ private:
|
||||||
class Insert : public InputMode
|
class Insert : public InputMode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Insert(InputHandler& input_handler, InsertMode mode)
|
Insert(Client& client, InsertMode mode)
|
||||||
: InputMode(input_handler),
|
: InputMode(client),
|
||||||
m_inserter(context().editor(), mode),
|
m_inserter(context().editor(), mode),
|
||||||
m_completer(context()),
|
m_completer(context()),
|
||||||
m_idle_timer{Clock::now() + idle_timeout,
|
m_idle_timer{Clock::now() + idle_timeout,
|
||||||
|
@ -908,28 +908,28 @@ private:
|
||||||
|
|
||||||
InputMode& InputMode::reset_normal_mode()
|
InputMode& InputMode::reset_normal_mode()
|
||||||
{
|
{
|
||||||
m_input_handler.m_mode_trash.emplace_back(std::move(m_input_handler.m_mode));
|
m_client.m_mode_trash.emplace_back(std::move(m_client.m_mode));
|
||||||
m_input_handler.m_mode.reset(new InputModes::Normal(m_input_handler));
|
m_client.m_mode.reset(new InputModes::Normal(m_client));
|
||||||
return *m_input_handler.m_mode;
|
return *m_client.m_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
InputHandler::InputHandler(std::unique_ptr<UserInterface>&& ui, Editor& editor, String name)
|
Client::Client(std::unique_ptr<UserInterface>&& ui, Editor& editor, String name)
|
||||||
: m_ui(std::move(ui)), m_context(*this, editor), m_mode(new InputModes::Normal(*this)), m_name(name)
|
: m_ui(std::move(ui)), m_context(*this, editor), m_mode(new InputModes::Normal(*this)), m_name(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
InputHandler::~InputHandler()
|
Client::~Client()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler::insert(InsertMode mode)
|
void Client::insert(InsertMode mode)
|
||||||
{
|
{
|
||||||
m_mode_trash.emplace_back(std::move(m_mode));
|
m_mode_trash.emplace_back(std::move(m_mode));
|
||||||
m_mode.reset(new InputModes::Insert(*this, mode));
|
m_mode.reset(new InputModes::Insert(*this, mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler::repeat_last_insert()
|
void Client::repeat_last_insert()
|
||||||
{
|
{
|
||||||
if (m_last_insert.second.empty())
|
if (m_last_insert.second.empty())
|
||||||
return;
|
return;
|
||||||
|
@ -945,7 +945,7 @@ void InputHandler::repeat_last_insert()
|
||||||
kak_assert(dynamic_cast<InputModes::Normal*>(m_mode.get()) != nullptr);
|
kak_assert(dynamic_cast<InputModes::Normal*>(m_mode.get()) != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler::prompt(const String& prompt, ColorPair prompt_colors,
|
void Client::prompt(const String& prompt, ColorPair prompt_colors,
|
||||||
Completer completer, PromptCallback callback)
|
Completer completer, PromptCallback callback)
|
||||||
{
|
{
|
||||||
m_mode_trash.emplace_back(std::move(m_mode));
|
m_mode_trash.emplace_back(std::move(m_mode));
|
||||||
|
@ -953,21 +953,21 @@ void InputHandler::prompt(const String& prompt, ColorPair prompt_colors,
|
||||||
completer, callback));
|
completer, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler::set_prompt_colors(ColorPair prompt_colors)
|
void Client::set_prompt_colors(ColorPair prompt_colors)
|
||||||
{
|
{
|
||||||
InputModes::Prompt* prompt = dynamic_cast<InputModes::Prompt*>(m_mode.get());
|
InputModes::Prompt* prompt = dynamic_cast<InputModes::Prompt*>(m_mode.get());
|
||||||
if (prompt)
|
if (prompt)
|
||||||
prompt->set_prompt_colors(prompt_colors);
|
prompt->set_prompt_colors(prompt_colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler::menu(memoryview<String> choices,
|
void Client::menu(memoryview<String> choices,
|
||||||
MenuCallback callback)
|
MenuCallback callback)
|
||||||
{
|
{
|
||||||
m_mode_trash.emplace_back(std::move(m_mode));
|
m_mode_trash.emplace_back(std::move(m_mode));
|
||||||
m_mode.reset(new InputModes::Menu(*this, choices, callback));
|
m_mode.reset(new InputModes::Menu(*this, choices, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler::on_next_key(KeyCallback callback)
|
void Client::on_next_key(KeyCallback callback)
|
||||||
{
|
{
|
||||||
m_mode_trash.emplace_back(std::move(m_mode));
|
m_mode_trash.emplace_back(std::move(m_mode));
|
||||||
m_mode.reset(new InputModes::NextKey(*this, callback));
|
m_mode.reset(new InputModes::NextKey(*this, callback));
|
||||||
|
@ -978,7 +978,7 @@ bool is_valid(Key key)
|
||||||
return key != Key::Invalid and key.key <= 0x10FFFF;
|
return key != Key::Invalid and key.key <= 0x10FFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler::handle_key(Key key)
|
void Client::handle_key(Key key)
|
||||||
{
|
{
|
||||||
if (is_valid(key))
|
if (is_valid(key))
|
||||||
{
|
{
|
||||||
|
@ -993,19 +993,19 @@ void InputHandler::handle_key(Key key)
|
||||||
m_mode_trash.clear();
|
m_mode_trash.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler::start_recording(char reg)
|
void Client::start_recording(char reg)
|
||||||
{
|
{
|
||||||
kak_assert(m_recording_reg == 0);
|
kak_assert(m_recording_reg == 0);
|
||||||
m_recorded_keys = "";
|
m_recorded_keys = "";
|
||||||
m_recording_reg = reg;
|
m_recording_reg = reg;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputHandler::is_recording() const
|
bool Client::is_recording() const
|
||||||
{
|
{
|
||||||
return m_recording_reg != 0;
|
return m_recording_reg != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler::stop_recording()
|
void Client::stop_recording()
|
||||||
{
|
{
|
||||||
kak_assert(m_recording_reg != 0);
|
kak_assert(m_recording_reg != 0);
|
||||||
RegisterManager::instance()[m_recording_reg] = memoryview<String>(m_recorded_keys);
|
RegisterManager::instance()[m_recording_reg] = memoryview<String>(m_recorded_keys);
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef input_handler_hh_INCLUDED
|
#ifndef client_hh_INCLUDED
|
||||||
#define input_handler_hh_INCLUDED
|
#define client_hh_INCLUDED
|
||||||
|
|
||||||
#include "color.hh"
|
#include "color.hh"
|
||||||
#include "completion.hh"
|
#include "completion.hh"
|
||||||
|
@ -34,11 +34,11 @@ using KeyCallback = std::function<void (Key, Context&)>;
|
||||||
class InputMode;
|
class InputMode;
|
||||||
enum class InsertMode : unsigned;
|
enum class InsertMode : unsigned;
|
||||||
|
|
||||||
class InputHandler : public SafeCountable
|
class Client : public SafeCountable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InputHandler(std::unique_ptr<UserInterface>&& ui, Editor& editor, String name);
|
Client(std::unique_ptr<UserInterface>&& ui, Editor& editor, String name);
|
||||||
~InputHandler();
|
~Client();
|
||||||
|
|
||||||
// switch to insert mode
|
// switch to insert mode
|
||||||
void insert(InsertMode mode);
|
void insert(InsertMode mode);
|
||||||
|
@ -96,4 +96,4 @@ struct prompt_aborted {};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // input_handler_hh_INCLUDED
|
#endif // client_hh_INCLUDED
|
|
@ -33,11 +33,11 @@ String ClientManager::generate_name() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InputHandler* ClientManager::create_client(std::unique_ptr<UserInterface>&& ui,
|
Client* ClientManager::create_client(std::unique_ptr<UserInterface>&& ui,
|
||||||
const String& init_commands)
|
const String& init_commands)
|
||||||
{
|
{
|
||||||
Buffer& buffer = **BufferManager::instance().begin();
|
Buffer& buffer = **BufferManager::instance().begin();
|
||||||
InputHandler* client = new InputHandler{std::move(ui), get_unused_window_for_buffer(buffer),
|
Client* client = new Client{std::move(ui), get_unused_window_for_buffer(buffer),
|
||||||
generate_name()};
|
generate_name()};
|
||||||
m_clients.emplace_back(client);
|
m_clients.emplace_back(client);
|
||||||
try
|
try
|
||||||
|
@ -80,7 +80,7 @@ InputHandler* ClientManager::create_client(std::unique_ptr<UserInterface>&& ui,
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientManager::remove_client(InputHandler& client)
|
void ClientManager::remove_client(Client& client)
|
||||||
{
|
{
|
||||||
for (auto it = m_clients.begin(); it != m_clients.end(); ++it)
|
for (auto it = m_clients.begin(); it != m_clients.end(); ++it)
|
||||||
{
|
{
|
||||||
|
@ -101,7 +101,7 @@ Window& ClientManager::get_unused_window_for_buffer(Buffer& buffer)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto it = std::find_if(m_clients.begin(), m_clients.end(),
|
auto it = std::find_if(m_clients.begin(), m_clients.end(),
|
||||||
[&](const std::unique_ptr<InputHandler>& client)
|
[&](const std::unique_ptr<Client>& client)
|
||||||
{ return &client->context().window() == w.get(); });
|
{ return &client->context().window() == w.get(); });
|
||||||
if (it == m_clients.end())
|
if (it == m_clients.end())
|
||||||
{
|
{
|
||||||
|
@ -145,16 +145,16 @@ void ClientManager::ensure_no_client_uses_buffer(Buffer& buffer)
|
||||||
m_windows.erase(end, m_windows.end());
|
m_windows.erase(end, m_windows.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientManager::set_client_name(InputHandler& client, String name)
|
void ClientManager::set_client_name(Client& client, String name)
|
||||||
{
|
{
|
||||||
auto it = find_if(m_clients, [&name](std::unique_ptr<InputHandler>& client)
|
auto it = find_if(m_clients, [&name](std::unique_ptr<Client>& client)
|
||||||
{ return client->m_name == name; });
|
{ return client->m_name == name; });
|
||||||
if (it != m_clients.end() and it->get() != &client)
|
if (it != m_clients.end() and it->get() != &client)
|
||||||
throw runtime_error("name not unique: " + name);
|
throw runtime_error("name not unique: " + name);
|
||||||
client.m_name = std::move(name);
|
client.m_name = std::move(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
InputHandler& ClientManager::get_client(const Context& context)
|
Client& ClientManager::get_client(const Context& context)
|
||||||
{
|
{
|
||||||
for (auto& client : m_clients)
|
for (auto& client : m_clients)
|
||||||
{
|
{
|
||||||
|
@ -164,7 +164,7 @@ InputHandler& ClientManager::get_client(const Context& context)
|
||||||
throw runtime_error("no client for current context");
|
throw runtime_error("no client for current context");
|
||||||
}
|
}
|
||||||
|
|
||||||
InputHandler& ClientManager::get_client(const String& name)
|
Client& ClientManager::get_client(const String& name)
|
||||||
{
|
{
|
||||||
for (auto& client : m_clients)
|
for (auto& client : m_clients)
|
||||||
{
|
{
|
||||||
|
@ -174,7 +174,7 @@ InputHandler& ClientManager::get_client(const String& name)
|
||||||
throw runtime_error("no client named: " + name);
|
throw runtime_error("no client named: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static DisplayLine generate_status_line(InputHandler& client)
|
static DisplayLine generate_status_line(Client& client)
|
||||||
{
|
{
|
||||||
auto& context = client.context();
|
auto& context = client.context();
|
||||||
auto pos = context.editor().main_selection().last();
|
auto pos = context.editor().main_selection().last();
|
||||||
|
@ -185,7 +185,7 @@ static DisplayLine generate_status_line(InputHandler& client)
|
||||||
<< " " << (int)pos.line+1 << ":" << (int)col+1;
|
<< " " << (int)pos.line+1 << ":" << (int)col+1;
|
||||||
if (context.buffer().is_modified())
|
if (context.buffer().is_modified())
|
||||||
oss << " [+]";
|
oss << " [+]";
|
||||||
if (context.input_handler().is_recording())
|
if (context.client().is_recording())
|
||||||
oss << " [recording]";
|
oss << " [recording]";
|
||||||
if (context.buffer().flags() & Buffer::Flags::New)
|
if (context.buffer().flags() & Buffer::Flags::New)
|
||||||
oss << " [new file]";
|
oss << " [new file]";
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define client_manager_hh_INCLUDED
|
#define client_manager_hh_INCLUDED
|
||||||
|
|
||||||
#include "context.hh"
|
#include "context.hh"
|
||||||
#include "input_handler.hh"
|
#include "client.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,7 @@ public:
|
||||||
ClientManager();
|
ClientManager();
|
||||||
~ClientManager();
|
~ClientManager();
|
||||||
|
|
||||||
InputHandler* create_client(std::unique_ptr<UserInterface>&& ui,
|
Client* create_client(std::unique_ptr<UserInterface>&& ui,
|
||||||
const String& init_cmd);
|
const String& init_cmd);
|
||||||
|
|
||||||
bool empty() const { return m_clients.empty(); }
|
bool empty() const { return m_clients.empty(); }
|
||||||
|
@ -26,15 +26,15 @@ public:
|
||||||
|
|
||||||
void redraw_clients() const;
|
void redraw_clients() const;
|
||||||
|
|
||||||
InputHandler& get_client(const Context& context);
|
Client& get_client(const Context& context);
|
||||||
InputHandler& get_client(const String& name);
|
Client& get_client(const String& name);
|
||||||
void set_client_name(InputHandler& client, String name);
|
void set_client_name(Client& client, String name);
|
||||||
void remove_client(InputHandler& client);
|
void remove_client(Client& client);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String generate_name() const;
|
String generate_name() const;
|
||||||
|
|
||||||
std::vector<std::unique_ptr<InputHandler>> m_clients;
|
std::vector<std::unique_ptr<Client>> m_clients;
|
||||||
std::vector<std::unique_ptr<Window>> m_windows;
|
std::vector<std::unique_ptr<Window>> m_windows;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include "filter.hh"
|
#include "filter.hh"
|
||||||
#include "highlighter.hh"
|
#include "highlighter.hh"
|
||||||
#include "highlighters.hh"
|
#include "highlighters.hh"
|
||||||
#include "input_handler.hh"
|
#include "client.hh"
|
||||||
#include "option_manager.hh"
|
#include "option_manager.hh"
|
||||||
#include "option_types.hh"
|
#include "option_types.hh"
|
||||||
#include "parameters_parser.hh"
|
#include "parameters_parser.hh"
|
||||||
|
@ -570,12 +570,12 @@ void context_wrap(CommandParameters params, Context& context, Func func)
|
||||||
if (parser.has_option("draft"))
|
if (parser.has_option("draft"))
|
||||||
{
|
{
|
||||||
Editor& editor = real_context.editor();
|
Editor& editor = real_context.editor();
|
||||||
InputHandler input_handler(std::unique_ptr<UserInterface>(new DraftUI()), editor,
|
Client client(std::unique_ptr<UserInterface>(new DraftUI()), editor,
|
||||||
real_context.has_input_handler() ?
|
real_context.has_client() ?
|
||||||
real_context.input_handler().name() : "");
|
real_context.client().name() : "");
|
||||||
DynamicSelectionList sels{editor.buffer(), editor.selections()};
|
DynamicSelectionList sels{editor.buffer(), editor.selections()};
|
||||||
auto restore_sels = on_scope_end([&]{ editor.select(sels); });
|
auto restore_sels = on_scope_end([&]{ editor.select(sels); });
|
||||||
func(parser, input_handler.context());
|
func(parser, client.context());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
func(parser, real_context);
|
func(parser, real_context);
|
||||||
|
@ -637,7 +637,7 @@ void menu(CommandParameters params, Context& context)
|
||||||
select_cmds.push_back(parser[i+2]);
|
select_cmds.push_back(parser[i+2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
context.input_handler().menu(choices,
|
context.client().menu(choices,
|
||||||
[=](int choice, MenuEvent event, Context& context) {
|
[=](int choice, MenuEvent event, Context& context) {
|
||||||
if (event == MenuEvent::Validate and choice >= 0 and choice < commands.size())
|
if (event == MenuEvent::Validate and choice >= 0 and choice < commands.size())
|
||||||
CommandManager::instance().execute(commands[choice], context);
|
CommandManager::instance().execute(commands[choice], context);
|
||||||
|
@ -860,7 +860,7 @@ void exec_keys(const KeyList& keys, Context& context)
|
||||||
scoped_edition edition(context.editor());
|
scoped_edition edition(context.editor());
|
||||||
|
|
||||||
for (auto& key : keys)
|
for (auto& key : keys)
|
||||||
context.input_handler().handle_key(key);
|
context.client().handle_key(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_commands()
|
void register_commands()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "context.hh"
|
#include "context.hh"
|
||||||
|
|
||||||
#include "input_handler.hh"
|
#include "client.hh"
|
||||||
#include "user_interface.hh"
|
#include "user_interface.hh"
|
||||||
#include "window.hh"
|
#include "window.hh"
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@ Context::Context() = default;
|
||||||
Context::Context(Editor& editor)
|
Context::Context(Editor& editor)
|
||||||
: m_editor(&editor) {}
|
: m_editor(&editor) {}
|
||||||
|
|
||||||
Context::Context(InputHandler& input_handler, Editor& editor)
|
Context::Context(Client& client, Editor& editor)
|
||||||
: m_input_handler(&input_handler), m_editor(&editor) {}
|
: m_client(&client), m_editor(&editor) {}
|
||||||
|
|
||||||
Context::~Context() = default;
|
Context::~Context() = default;
|
||||||
|
|
||||||
|
@ -43,18 +43,18 @@ bool Context::has_window() const
|
||||||
return (bool)m_editor and dynamic_cast<Window*>(m_editor.get());
|
return (bool)m_editor and dynamic_cast<Window*>(m_editor.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
InputHandler& Context::input_handler() const
|
Client& Context::client() const
|
||||||
{
|
{
|
||||||
if (not has_input_handler())
|
if (not has_client())
|
||||||
throw runtime_error("no input handler in context");
|
throw runtime_error("no input handler in context");
|
||||||
return *m_input_handler;
|
return *m_client;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserInterface& Context::ui() const
|
UserInterface& Context::ui() const
|
||||||
{
|
{
|
||||||
if (not has_ui())
|
if (not has_ui())
|
||||||
throw runtime_error("no user interface in context");
|
throw runtime_error("no user interface in context");
|
||||||
return m_input_handler->ui();
|
return m_client->ui();
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionManager& Context::options() const
|
OptionManager& Context::options() const
|
||||||
|
|
|
@ -9,21 +9,21 @@ namespace Kakoune
|
||||||
class Editor;
|
class Editor;
|
||||||
class Window;
|
class Window;
|
||||||
class Buffer;
|
class Buffer;
|
||||||
class InputHandler;
|
class Client;
|
||||||
class UserInterface;
|
class UserInterface;
|
||||||
class DisplayLine;
|
class DisplayLine;
|
||||||
|
|
||||||
// A Context is used to access non singleton objects for various services
|
// A Context is used to access non singleton objects for various services
|
||||||
// in commands.
|
// in commands.
|
||||||
//
|
//
|
||||||
// The Context object links an InputHandler, an Editor (which may be a Window),
|
// The Context object links an Client, an Editor (which may be a Window),
|
||||||
// and a UserInterface. It may represent an interactive user window, or
|
// and a UserInterface. It may represent an interactive user window, or
|
||||||
// a hook execution or a macro replay.
|
// a hook execution or a macro replay.
|
||||||
struct Context
|
struct Context
|
||||||
{
|
{
|
||||||
Context();
|
Context();
|
||||||
explicit Context(Editor& editor);
|
explicit Context(Editor& editor);
|
||||||
Context(InputHandler& input_handler, Editor& editor);
|
Context(Client& client, Editor& editor);
|
||||||
~Context();
|
~Context();
|
||||||
|
|
||||||
Context(const Context&) = delete;
|
Context(const Context&) = delete;
|
||||||
|
@ -38,11 +38,11 @@ struct Context
|
||||||
Window& window() const;
|
Window& window() const;
|
||||||
bool has_window() const;
|
bool has_window() const;
|
||||||
|
|
||||||
InputHandler& input_handler() const;
|
Client& client() const;
|
||||||
bool has_input_handler() const { return (bool)m_input_handler; }
|
bool has_client() const { return (bool)m_client; }
|
||||||
|
|
||||||
UserInterface& ui() const;
|
UserInterface& ui() const;
|
||||||
bool has_ui() const { return (bool)m_input_handler; }
|
bool has_ui() const { return (bool)m_client; }
|
||||||
|
|
||||||
void change_editor(Editor& editor);
|
void change_editor(Editor& editor);
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ struct Context
|
||||||
int& numeric_param() { return m_numeric_param; }
|
int& numeric_param() { return m_numeric_param; }
|
||||||
private:
|
private:
|
||||||
safe_ptr<Editor> m_editor;
|
safe_ptr<Editor> m_editor;
|
||||||
safe_ptr<InputHandler> m_input_handler;
|
safe_ptr<Client> m_client;
|
||||||
|
|
||||||
int m_numeric_param = 0;
|
int m_numeric_param = 0;
|
||||||
|
|
||||||
|
|
|
@ -150,7 +150,7 @@ void create_local_client(const String& init_command)
|
||||||
};
|
};
|
||||||
|
|
||||||
UserInterface* ui = new LocalNCursesUI{};
|
UserInterface* ui = new LocalNCursesUI{};
|
||||||
static InputHandler* client = ClientManager::instance().create_client(
|
static Client* client = ClientManager::instance().create_client(
|
||||||
std::unique_ptr<UserInterface>{ui}, init_command);
|
std::unique_ptr<UserInterface>{ui}, init_command);
|
||||||
signal(SIGHUP, [](int) {
|
signal(SIGHUP, [](int) {
|
||||||
if (client)
|
if (client)
|
||||||
|
|
|
@ -25,12 +25,12 @@ using namespace std::placeholders;
|
||||||
template<InsertMode mode>
|
template<InsertMode mode>
|
||||||
void insert(Context& context)
|
void insert(Context& context)
|
||||||
{
|
{
|
||||||
context.input_handler().insert(mode);
|
context.client().insert(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void repeat_insert(Context& context)
|
void repeat_insert(Context& context)
|
||||||
{
|
{
|
||||||
context.input_handler().repeat_last_insert();
|
context.client().repeat_last_insert();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool show_auto_info_ifn(const String& info, const Context& context)
|
bool show_auto_info_ifn(const String& info, const Context& context)
|
||||||
|
@ -48,7 +48,7 @@ template<typename Cmd>
|
||||||
void on_next_key_with_autoinfo(const Context& context, Cmd cmd, const std::string& info)
|
void on_next_key_with_autoinfo(const Context& context, Cmd cmd, const std::string& info)
|
||||||
{
|
{
|
||||||
const bool hide = show_auto_info_ifn(info, context);
|
const bool hide = show_auto_info_ifn(info, context);
|
||||||
context.input_handler().on_next_key([hide,cmd](Key key, Context& context) mutable {
|
context.client().on_next_key([hide,cmd](Key key, Context& context) mutable {
|
||||||
if (hide)
|
if (hide)
|
||||||
context.ui().info_hide();
|
context.ui().info_hide();
|
||||||
cmd(key, context);
|
cmd(key, context);
|
||||||
|
@ -253,7 +253,7 @@ void for_each_char(Context& context)
|
||||||
|
|
||||||
void command(Context& context)
|
void command(Context& context)
|
||||||
{
|
{
|
||||||
context.input_handler().prompt(
|
context.client().prompt(
|
||||||
":", get_color("Prompt"),
|
":", get_color("Prompt"),
|
||||||
std::bind(&CommandManager::complete, &CommandManager::instance(), _1, _2, _3),
|
std::bind(&CommandManager::complete, &CommandManager::instance(), _1, _2, _3),
|
||||||
[](const String& cmdline, PromptEvent event, Context& context) {
|
[](const String& cmdline, PromptEvent event, Context& context) {
|
||||||
|
@ -264,7 +264,7 @@ void command(Context& context)
|
||||||
|
|
||||||
void pipe(Context& context)
|
void pipe(Context& context)
|
||||||
{
|
{
|
||||||
context.input_handler().prompt("pipe:", get_color("Prompt"), complete_nothing,
|
context.client().prompt("pipe:", get_color("Prompt"), complete_nothing,
|
||||||
[](const String& cmdline, PromptEvent event, Context& context)
|
[](const String& cmdline, PromptEvent event, Context& context)
|
||||||
{
|
{
|
||||||
if (event != PromptEvent::Validate)
|
if (event != PromptEvent::Validate)
|
||||||
|
@ -293,7 +293,7 @@ void search(Context& context)
|
||||||
{
|
{
|
||||||
const char* prompt = direction == Forward ? "search:" : "reverse search:";
|
const char* prompt = direction == Forward ? "search:" : "reverse search:";
|
||||||
DynamicSelectionList selections{context.buffer(), context.editor().selections()};
|
DynamicSelectionList selections{context.buffer(), context.editor().selections()};
|
||||||
context.input_handler().prompt(prompt, get_color("Prompt"), complete_nothing,
|
context.client().prompt(prompt, get_color("Prompt"), complete_nothing,
|
||||||
[selections](const String& str, PromptEvent event, Context& context) {
|
[selections](const String& str, PromptEvent event, Context& context) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -303,7 +303,7 @@ void search(Context& context)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Regex ex{str};
|
Regex ex{str};
|
||||||
context.input_handler().set_prompt_colors(get_color("Prompt"));
|
context.client().set_prompt_colors(get_color("Prompt"));
|
||||||
if (event == PromptEvent::Validate)
|
if (event == PromptEvent::Validate)
|
||||||
{
|
{
|
||||||
if (str.empty())
|
if (str.empty())
|
||||||
|
@ -322,7 +322,7 @@ void search(Context& context)
|
||||||
if (event == PromptEvent::Validate)
|
if (event == PromptEvent::Validate)
|
||||||
throw runtime_error("regex error: "_str + err.what());
|
throw runtime_error("regex error: "_str + err.what());
|
||||||
else
|
else
|
||||||
context.input_handler().set_prompt_colors(get_color("Error"));
|
context.client().set_prompt_colors(get_color("Error"));
|
||||||
}
|
}
|
||||||
catch (runtime_error&)
|
catch (runtime_error&)
|
||||||
{
|
{
|
||||||
|
@ -446,7 +446,7 @@ void paste(Context& context)
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void regex_prompt(Context& context, const String prompt, T on_validate)
|
void regex_prompt(Context& context, const String prompt, T on_validate)
|
||||||
{
|
{
|
||||||
context.input_handler().prompt(prompt, get_color("Prompt"), complete_nothing,
|
context.client().prompt(prompt, get_color("Prompt"), complete_nothing,
|
||||||
[=](const String& str, PromptEvent event, Context& context) {
|
[=](const String& str, PromptEvent event, Context& context) {
|
||||||
if (event == PromptEvent::Validate)
|
if (event == PromptEvent::Validate)
|
||||||
{
|
{
|
||||||
|
@ -462,7 +462,7 @@ void regex_prompt(Context& context, const String prompt, T on_validate)
|
||||||
else if (event == PromptEvent::Change)
|
else if (event == PromptEvent::Change)
|
||||||
{
|
{
|
||||||
const bool ok = Regex{str, boost::regex_constants::no_except}.status() == 0;
|
const bool ok = Regex{str, boost::regex_constants::no_except}.status() == 0;
|
||||||
context.input_handler().set_prompt_colors(get_color(ok ? "Prompt" : "Error"));
|
context.client().set_prompt_colors(get_color(ok ? "Prompt" : "Error"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -693,12 +693,12 @@ void select_to_next_char(Context& context)
|
||||||
|
|
||||||
void start_or_end_macro_recording(Context& context)
|
void start_or_end_macro_recording(Context& context)
|
||||||
{
|
{
|
||||||
if (context.input_handler().is_recording())
|
if (context.client().is_recording())
|
||||||
context.input_handler().stop_recording();
|
context.client().stop_recording();
|
||||||
else
|
else
|
||||||
on_next_key_with_autoinfo(context, [](Key key, Context& context) {
|
on_next_key_with_autoinfo(context, [](Key key, Context& context) {
|
||||||
if (key.modifiers == Key::Modifiers::None)
|
if (key.modifiers == Key::Modifiers::None)
|
||||||
context.input_handler().start_recording(key.key);
|
context.client().start_recording(key.key);
|
||||||
},
|
},
|
||||||
"╭──┤record macro├──╮\n"
|
"╭──┤record macro├──╮\n"
|
||||||
"│ enter macro name │\n"
|
"│ enter macro name │\n"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user