summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVille Hakulinen <ville.hakulinen@gmail.com>2020-08-16 15:12:51 +0300
committerVille Hakulinen <ville.hakulinen@gmail.com>2020-08-16 15:12:51 +0300
commitadc8322c99da0d3d8e1d4363e7375b88f00069cb (patch)
tree4c2c12e70c8b2d4242bba274d1a35100ad56e071
parent230752ba06e2ee354abd58ee20f1599010d988b4 (diff)
Refactor ui_set_option calls
-rw-r--r--src/ui/state.rs52
1 files changed, 13 insertions, 39 deletions
diff --git a/src/ui/state.rs b/src/ui/state.rs
index d2b9908..884d9c5 100644
--- a/src/ui/state.rs
+++ b/src/ui/state.rs
@@ -858,6 +858,16 @@ impl UIState {
}
}
+ fn set_ui_option(&self, opt: String, enable: bool, nvim: GioNeovim) {
+ spawn_local(async move {
+ if let Err(err) =
+ nvim.ui_set_option(&opt, rmpv::Value::Boolean(enable)).await
+ {
+ error!("Failed to set '{}' option: {}", opt, err);
+ }
+ });
+ }
+
fn handle_gnvim_event(&mut self, event: &GnvimEvent, nvim: &GioNeovim) {
match event {
GnvimEvent::CompletionMenuToggleInfo => {
@@ -876,49 +886,13 @@ impl UIState {
self.enable_cursor_animations(*enable);
}
GnvimEvent::EnableExtTabline(enable) => {
- let nvim = nvim.clone();
- let enable = *enable;
- spawn_local(async move {
- if let Err(err) = nvim
- .ui_set_option(
- "ext_tabline",
- rmpv::Value::Boolean(enable),
- )
- .await
- {
- error!("Failed to set ext_tabline option: {}", err);
- }
- });
+ self.set_ui_option("ext_tabline".into(), *enable, nvim.clone());
}
GnvimEvent::EnableExtCmdline(enable) => {
- let nvim = nvim.clone();
- let enable = *enable;
- spawn_local(async move {
- if let Err(err) = nvim
- .ui_set_option(
- "ext_cmdline",
- rmpv::Value::Boolean(enable),
- )
- .await
- {
- error!("Failed to set ext_cmdline option: {}", err);
- }
- });
+ self.set_ui_option("ext_cmdline".into(), *enable, nvim.clone());
}
GnvimEvent::EnableExtPopupmenu(enable) => {
- let nvim = nvim.clone();
- let enable = *enable;
- spawn_local(async move {
- if let Err(err) = nvim
- .ui_set_option(
- "ext_popupmenu",
- rmpv::Value::Boolean(enable),
- )
- .await
- {
- error!("Failed to set ext_popupmenu option: {}", err);
- }
- });
+ self.set_ui_option("ext_popupmenu".into(), *enable, nvim.clone());
}
GnvimEvent::Unknown(msg) => {
debug!("Received unknown GnvimEvent: {}", msg);