summaryrefslogtreecommitdiff
path: root/src/json_ui.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-11-29 21:35:53 +0000
committerMaxime Coste <frrrwww@gmail.com>2016-11-29 21:59:36 +0000
commit3a81260917319e15b13e4f09dd9bc38f0b72b194 (patch)
treef79d0cf3c7546f217281e9112b635096af57d507 /src/json_ui.cc
parent2fd1414b051cc95d0e0a4cd8c983c92408e67ac8 (diff)
Simplify greatly UI input handling
This round trip through an input callback expected to call is_key_available and get_key was overcomplicated, just send the keys as they arrive, the client is already buffering due to urgent event mode.
Diffstat (limited to 'src/json_ui.cc')
-rw-r--r--src/json_ui.cc32
1 files changed, 10 insertions, 22 deletions
diff --git a/src/json_ui.cc b/src/json_ui.cc
index f24b78c5..0a82e07e 100644
--- a/src/json_ui.cc
+++ b/src/json_ui.cc
@@ -184,18 +184,6 @@ void JsonUI::draw_status(const DisplayLine& status_line,
rpc_call("draw_status", status_line, mode_line, default_face);
}
-bool JsonUI::is_key_available()
-{
- return not m_pending_keys.empty();
-}
-
-Key JsonUI::get_key()
-{
- kak_assert(not m_pending_keys.empty());
- Key key = m_pending_keys.front();
- m_pending_keys.erase(m_pending_keys.begin());
- return key;
-}
void JsonUI::menu_show(ConstArrayView<DisplayLine> items,
DisplayCoord anchor, Face fg, Face bg,
@@ -231,11 +219,6 @@ void JsonUI::refresh(bool force)
rpc_call("refresh", force);
}
-void JsonUI::set_input_callback(InputCallback callback)
-{
- m_input_callback = std::move(callback);
-}
-
void JsonUI::set_ui_options(const Options& options)
{
// rpc_call("set_ui_options", options);
@@ -246,6 +229,11 @@ DisplayCoord JsonUI::dimensions()
return m_dimensions;
}
+void JsonUI::set_on_key(OnKeyCallback callback)
+{
+ m_on_key = std::move(callback);
+}
+
using JsonArray = Vector<Value>;
using JsonObject = IdMap<Value>;
@@ -384,7 +372,7 @@ void JsonUI::eval_json(const Value& json)
for (auto& key_val : params)
{
for (auto& key : parse_keys(key_val.as<String>()))
- m_pending_keys.push_back(key);
+ m_on_key(key);
}
}
else if (method == "resize")
@@ -394,7 +382,7 @@ void JsonUI::eval_json(const Value& json)
DisplayCoord dim{params[0].as<int>(), params[1].as<int>()};
m_dimensions = dim;
- m_pending_keys.push_back(resize(dim));
+ m_on_key(resize(dim));
}
else
throw runtime_error("unknown method");
@@ -413,6 +401,9 @@ void JsonUI::parse_requests(EventMode mode)
m_requests += StringView{buf, buf + size};
}
+ if (not m_on_key)
+ return;
+
while (not m_requests.empty())
{
const char* pos = nullptr;
@@ -435,9 +426,6 @@ void JsonUI::parse_requests(EventMode mode)
m_requests = String{pos, m_requests.end()};
}
-
- while (m_input_callback and not m_pending_keys.empty())
- m_input_callback(mode);
}
UnitTest test_json_parser{[]()