1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-30 23:37:17 +03:00

Handle all available input before redrawing

This commit is contained in:
Maxime Coste 2012-10-28 09:26:54 +01:00
parent 13a081ed4a
commit d9729cc29e
9 changed files with 40 additions and 10 deletions

View File

@ -654,7 +654,7 @@ public:
assert(m_pos < m_keys.size());
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 draw(const DisplayBuffer&, const String&) override {}
@ -681,8 +681,7 @@ void exec_keys(const KeyList& keys, Context& context)
scoped_edition edition(context.editor());
Context new_context(batch_input_handler, context.editor(), batch_ui);
while (batch_ui.has_key_left())
batch_input_handler.handle_next_input(new_context);
batch_input_handler.handle_available_inputs(new_context);
context.change_editor(new_context.editor());
}

View File

@ -625,11 +625,14 @@ void InputHandler::on_next_key(KeyCallback callback)
m_mode.reset(new InputModes::NextKey(*this, callback));
}
void InputHandler::handle_next_input(Context& context)
void InputHandler::handle_available_inputs(Context& context)
{
Key key = context.ui().get_key();
if (key != Key::Invalid)
m_mode->on_key(key, context);
while (context.ui().is_key_available())
{
Key key = context.ui().get_key();
if (key != Key::Invalid)
m_mode->on_key(key, context);
}
context.draw_ifn();
}

View File

@ -36,7 +36,7 @@ public:
void on_next_key(KeyCallback callback);
void handle_next_input(Context& context);
void handle_available_inputs(Context& context);
private:
friend class InputMode;

View File

@ -529,7 +529,7 @@ Client create_local_client(const String& file)
EventManager::instance().watch(0, [=](int) {
try
{
input_handler->handle_next_input(*context);
input_handler->handle_available_inputs(*context);
}
catch (Kakoune::runtime_error& error)
{
@ -573,7 +573,7 @@ void setup_server()
EventManager::instance().watch(sock, [=](int) {
try
{
input_handler->handle_next_input(*context);
input_handler->handle_available_inputs(*context);
}
catch (Kakoune::runtime_error& error)
{

View File

@ -211,6 +211,16 @@ struct getch_iterator
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()
{
const unsigned c = getch();

View File

@ -23,6 +23,7 @@ public:
const String& status_line) override;
void print_status(const String& status, CharCount cursor_pos) override;
bool is_key_available() override;
Key get_key() override;
void menu_show(const memoryview<String>& choices,

View File

@ -193,6 +193,20 @@ void RemoteUI::draw(const DisplayBuffer& display_buffer,
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 key = read<Key>(m_socket);

View File

@ -24,6 +24,8 @@ public:
void menu_hide() override;
void draw(const DisplayBuffer& display_buffer,
const String& status_line) override;
bool is_key_available() override;
Key get_key() override;
DisplayCoord dimensions() override;

View File

@ -31,6 +31,7 @@ public:
virtual void draw(const DisplayBuffer& display_buffer,
const String& status_line) = 0;
virtual DisplayCoord dimensions() = 0;
virtual bool is_key_available() = 0;
virtual Key get_key() = 0;
};