Handle all available input before redrawing
This commit is contained in:
parent
13a081ed4a
commit
d9729cc29e
|
@ -654,7 +654,7 @@ public:
|
||||||
assert(m_pos < m_keys.size());
|
assert(m_pos < m_keys.size());
|
||||||
return m_keys[m_pos++];
|
return m_keys[m_pos++];
|
||||||
}
|
}
|
||||||
bool has_key_left() const { return m_pos < m_keys.size(); }
|
bool is_key_available() override { return m_pos < m_keys.size(); }
|
||||||
|
|
||||||
void print_status(const String& , CharCount) override {}
|
void print_status(const String& , CharCount) override {}
|
||||||
void draw(const DisplayBuffer&, const String&) override {}
|
void draw(const DisplayBuffer&, const String&) override {}
|
||||||
|
@ -681,8 +681,7 @@ void exec_keys(const KeyList& keys, Context& context)
|
||||||
scoped_edition edition(context.editor());
|
scoped_edition edition(context.editor());
|
||||||
|
|
||||||
Context new_context(batch_input_handler, context.editor(), batch_ui);
|
Context new_context(batch_input_handler, context.editor(), batch_ui);
|
||||||
while (batch_ui.has_key_left())
|
batch_input_handler.handle_available_inputs(new_context);
|
||||||
batch_input_handler.handle_next_input(new_context);
|
|
||||||
context.change_editor(new_context.editor());
|
context.change_editor(new_context.editor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -625,11 +625,14 @@ void InputHandler::on_next_key(KeyCallback callback)
|
||||||
m_mode.reset(new InputModes::NextKey(*this, callback));
|
m_mode.reset(new InputModes::NextKey(*this, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler::handle_next_input(Context& context)
|
void InputHandler::handle_available_inputs(Context& context)
|
||||||
|
{
|
||||||
|
while (context.ui().is_key_available())
|
||||||
{
|
{
|
||||||
Key key = context.ui().get_key();
|
Key key = context.ui().get_key();
|
||||||
if (key != Key::Invalid)
|
if (key != Key::Invalid)
|
||||||
m_mode->on_key(key, context);
|
m_mode->on_key(key, context);
|
||||||
|
}
|
||||||
context.draw_ifn();
|
context.draw_ifn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
|
|
||||||
void on_next_key(KeyCallback callback);
|
void on_next_key(KeyCallback callback);
|
||||||
|
|
||||||
void handle_next_input(Context& context);
|
void handle_available_inputs(Context& context);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class InputMode;
|
friend class InputMode;
|
||||||
|
|
|
@ -529,7 +529,7 @@ Client create_local_client(const String& file)
|
||||||
EventManager::instance().watch(0, [=](int) {
|
EventManager::instance().watch(0, [=](int) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
input_handler->handle_next_input(*context);
|
input_handler->handle_available_inputs(*context);
|
||||||
}
|
}
|
||||||
catch (Kakoune::runtime_error& error)
|
catch (Kakoune::runtime_error& error)
|
||||||
{
|
{
|
||||||
|
@ -573,7 +573,7 @@ void setup_server()
|
||||||
EventManager::instance().watch(sock, [=](int) {
|
EventManager::instance().watch(sock, [=](int) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
input_handler->handle_next_input(*context);
|
input_handler->handle_available_inputs(*context);
|
||||||
}
|
}
|
||||||
catch (Kakoune::runtime_error& error)
|
catch (Kakoune::runtime_error& error)
|
||||||
{
|
{
|
||||||
|
|
|
@ -211,6 +211,16 @@ struct getch_iterator
|
||||||
getch_iterator& operator++(int) { return *this; }
|
getch_iterator& operator++(int) { return *this; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool NCursesUI::is_key_available()
|
||||||
|
{
|
||||||
|
timeout(0);
|
||||||
|
const int c = getch();
|
||||||
|
if (c != ERR)
|
||||||
|
ungetch(c);
|
||||||
|
timeout(-1);
|
||||||
|
return c != ERR;
|
||||||
|
}
|
||||||
|
|
||||||
Key NCursesUI::get_key()
|
Key NCursesUI::get_key()
|
||||||
{
|
{
|
||||||
const unsigned c = getch();
|
const unsigned c = getch();
|
||||||
|
|
|
@ -23,6 +23,7 @@ public:
|
||||||
const String& status_line) override;
|
const String& status_line) override;
|
||||||
void print_status(const String& status, CharCount cursor_pos) override;
|
void print_status(const String& status, CharCount cursor_pos) override;
|
||||||
|
|
||||||
|
bool is_key_available() override;
|
||||||
Key get_key() override;
|
Key get_key() override;
|
||||||
|
|
||||||
void menu_show(const memoryview<String>& choices,
|
void menu_show(const memoryview<String>& choices,
|
||||||
|
|
|
@ -193,6 +193,20 @@ void RemoteUI::draw(const DisplayBuffer& display_buffer,
|
||||||
|
|
||||||
static const Key::Modifiers resize_modifier = (Key::Modifiers)0x80;
|
static const Key::Modifiers resize_modifier = (Key::Modifiers)0x80;
|
||||||
|
|
||||||
|
bool RemoteUI::is_key_available()
|
||||||
|
{
|
||||||
|
timeval tv;
|
||||||
|
fd_set rfds;
|
||||||
|
|
||||||
|
FD_ZERO(&rfds);
|
||||||
|
FD_SET(m_socket, &rfds);
|
||||||
|
|
||||||
|
tv.tv_sec = 0;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
int res = select(m_socket+1, &rfds, NULL, NULL, &tv);
|
||||||
|
return res == 1;
|
||||||
|
}
|
||||||
|
|
||||||
Key RemoteUI::get_key()
|
Key RemoteUI::get_key()
|
||||||
{
|
{
|
||||||
Key key = read<Key>(m_socket);
|
Key key = read<Key>(m_socket);
|
||||||
|
|
|
@ -24,6 +24,8 @@ public:
|
||||||
void menu_hide() override;
|
void menu_hide() override;
|
||||||
void draw(const DisplayBuffer& display_buffer,
|
void draw(const DisplayBuffer& display_buffer,
|
||||||
const String& status_line) override;
|
const String& status_line) override;
|
||||||
|
|
||||||
|
bool is_key_available() override;
|
||||||
Key get_key() override;
|
Key get_key() override;
|
||||||
DisplayCoord dimensions() override;
|
DisplayCoord dimensions() override;
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
virtual void draw(const DisplayBuffer& display_buffer,
|
virtual void draw(const DisplayBuffer& display_buffer,
|
||||||
const String& status_line) = 0;
|
const String& status_line) = 0;
|
||||||
virtual DisplayCoord dimensions() = 0;
|
virtual DisplayCoord dimensions() = 0;
|
||||||
|
virtual bool is_key_available() = 0;
|
||||||
virtual Key get_key() = 0;
|
virtual Key get_key() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user