Add option to enable external cmdline

This commit is contained in:
daa84 2018-03-30 13:01:14 +03:00
parent fb9d51c928
commit 7b59a2c1eb
3 changed files with 65 additions and 80 deletions

View File

@ -24,8 +24,6 @@ pub struct Level {
}
impl Level {
//TODO: im
pub fn insert(&mut self, c: &str, shift: bool, render_state: &shell::RenderState) {
self.model_layout.insert_char(c, shift);
self.update_preferred_size(render_state);
@ -428,7 +426,6 @@ fn gtk_draw(ctx: &cairo::Context, state: &Arc<UiMutex<State>>) -> Inhibit {
}
if let Some(level) = level {
//TODO: limit model to row filled
render::render(
ctx,
state.cursor.as_ref().unwrap(),

View File

@ -1,4 +1,3 @@
mod client;
mod handler;
mod mode_info;
@ -6,16 +5,16 @@ mod redraw_handler;
mod repaint_mode;
mod ext;
pub use self::redraw_handler::{RedrawEvents, GuiApi, CompleteItem};
pub use self::redraw_handler::{CompleteItem, GuiApi, RedrawEvents};
pub use self::repaint_mode::RepaintMode;
pub use self::client::{NeovimClient, NeovimClientAsync, NeovimRef};
pub use self::mode_info::{ModeInfo, CursorShape};
pub use self::mode_info::{CursorShape, ModeInfo};
pub use self::ext::ErrorReport;
use std::error;
use std::fmt;
use std::env;
use std::process::{Stdio, Command};
use std::process::{Command, Stdio};
use std::result;
use std::sync::Arc;
use std::time::Duration;
@ -85,7 +84,6 @@ fn set_windows_creation_flags(cmd: &mut Command) {
cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
}
pub fn start(
shell: Arc<UiMutex<shell::State>>,
nvim_bin_path: Option<&String>,
@ -111,14 +109,11 @@ pub fn start(
set_windows_creation_flags(&mut cmd);
if let Ok(runtime_path) = env::var("NVIM_GTK_RUNTIME_PATH") {
cmd.arg("--cmd").arg(
format!("let &rtp.=',{}'", runtime_path),
);
cmd.arg("--cmd")
.arg(format!("let &rtp.=',{}'", runtime_path));
} else if let Some(prefix) = option_env!("PREFIX") {
cmd.arg("--cmd").arg(format!(
"let &rtp.=',{}/share/nvim-gtk/runtime'",
prefix
));
cmd.arg("--cmd")
.arg(format!("let &rtp.=',{}/share/nvim-gtk/runtime'", prefix));
} else {
cmd.arg("--cmd").arg("let &rtp.=',runtime'");
}
@ -140,9 +135,8 @@ pub fn start(
let mut nvim = Neovim::new(session);
nvim.session.start_event_loop_handler(
handler::NvimHandler::new(shell),
);
nvim.session
.start_event_loop_handler(handler::NvimHandler::new(shell));
Ok(nvim)
}
@ -160,8 +154,7 @@ pub fn post_start_init(
rows,
UiAttachOptions::new()
.set_popupmenu_external(true)
.set_tabline_external(true)
.set_cmdline_external(true),
.set_tabline_external(true),
)
.map_err(NvimInitError::new_post_init)?;
@ -186,4 +179,3 @@ pub fn post_start_init(
Ok(())
}

View File

@ -2,7 +2,7 @@ use std::result;
use std::collections::HashMap;
use std::sync::Arc;
use neovim_lib::{Value, UiOption};
use neovim_lib::{UiOption, Value};
use neovim_lib::neovim_api::Tabpage;
use ui::UiMutex;
@ -158,9 +158,9 @@ macro_rules! call {
($s:ident -> $c:ident ($args:ident : $($arg_type:ident),+ )) => (
{
let mut iter = $args.into_iter();
$s.$c($(
$s.$c($(
try_arg!(iter.next()
.ok_or_else(|| format!("No such argument for {}", stringify!($c)))?,
.ok_or_else(|| format!("No such argument for {}", stringify!($c)))?,
$arg_type
)
),+ )
@ -175,38 +175,34 @@ pub fn call_gui_event(
) -> result::Result<(), String> {
match method {
"Font" => ui.set_font(try_str!(args[0])),
"Clipboard" => {
match try_str!(args[0]) {
"Set" => {
match try_str!(args[1]) {
"*" => ui.clipboard_primary_set(try_str!(args[2])),
_ => ui.clipboard_clipboard_set(try_str!(args[2])),
}
},
opt => error!("Unknown option {}", opt),
}
"Clipboard" => match try_str!(args[0]) {
"Set" => match try_str!(args[1]) {
"*" => ui.clipboard_primary_set(try_str!(args[2])),
_ => ui.clipboard_clipboard_set(try_str!(args[2])),
},
opt => error!("Unknown option {}", opt),
},
"Option" => match try_str!(args[0]) {
"Popupmenu" => ui.nvim()
.ok_or_else(|| "Nvim not initialized".to_owned())
.and_then(|mut nvim| {
nvim.set_option(UiOption::ExtPopupmenu(try_uint!(args[1]) == 1))
.map_err(|e| e.to_string())
})?,
"Tabline" => ui.nvim()
.ok_or_else(|| "Nvim not initialized".to_owned())
.and_then(|mut nvim| {
nvim.set_option(UiOption::ExtTabline(try_uint!(args[1]) == 1))
.map_err(|e| e.to_string())
})?,
"Cmdline" => ui.nvim()
.ok_or_else(|| "Nvim not initialized".to_owned())
.and_then(|mut nvim| {
nvim.set_option(UiOption::ExtCmdline(try_uint!(args[1]) == 1))
.map_err(|e| e.to_string())
})?,
opt => error!("Unknown option {}", opt),
},
"Option" => {
match try_str!(args[0]) {
"Popupmenu" => {
ui.nvim()
.ok_or_else(|| "Nvim not initialized".to_owned())
.and_then(|mut nvim| {
nvim.set_option(UiOption::ExtPopupmenu(try_uint!(args[1]) == 1))
.map_err(|e| e.to_string())
})?
}
"Tabline" => {
ui.nvim()
.ok_or_else(|| "Nvim not initialized".to_owned())
.and_then(|mut nvim| {
nvim.set_option(UiOption::ExtTabline(try_uint!(args[1]) == 1))
.map_err(|e| e.to_string())
})?
}
opt => error!("Unknown option {}", opt),
}
}
_ => return Err(format!("Unsupported event {}({:?})", method, args)),
}
Ok(())
@ -232,15 +228,19 @@ pub fn call_gui_request(
}
};
let t = clipboard.wait_for_text().unwrap_or_else(|| String::new());
Ok(Value::Array(t.split("\n").map(|s| s.into()).collect::<Vec<Value>>()))
},
Ok(Value::Array(
t.split("\n").map(|s| s.into()).collect::<Vec<Value>>(),
))
}
opt => {
error!("Unknown option {}", opt);
Err(Value::Nil)
},
}
}
},
_ => Err(Value::String(format!("Unsupported request {}({:?})", method, args).into())),
}
_ => Err(Value::String(
format!("Unsupported request {}({:?})", method, args).into(),
)),
}
}
@ -273,11 +273,11 @@ pub fn call(
"busy_start" => ui.on_busy(true),
"busy_stop" => ui.on_busy(false),
"popupmenu_show" => {
let menu_items = map_array!(args[0], "Error get menu list array", |item| {
map_array!(item, "Error get menu item array", |col| {
col.as_str().ok_or("Error get menu column")
})
})?;
let menu_items = map_array!(args[0], "Error get menu list array", |item| map_array!(
item,
"Error get menu item array",
|col| col.as_str().ok_or("Error get menu column")
))?;
ui.popupmenu_show(
&CompleteItem::map(&menu_items),
@ -294,9 +294,9 @@ pub fn call(
.ok_or_else(|| "Error get map for tab".to_owned())
.and_then(|tab_map| tab_map.to_attrs_map())
.map(|tab_attrs| {
let name_attr = tab_attrs.get("name").and_then(
|n| n.as_str().map(|s| s.to_owned()),
);
let name_attr = tab_attrs
.get("name")
.and_then(|n| n.as_str().map(|s| s.to_owned()));
let tab_attr = tab_attrs
.get("tab")
.map(|&tab_id| Tabpage::new(tab_id.clone()))
@ -311,11 +311,9 @@ pub fn call(
let mode_info = map_array!(
args[1],
"Error get array key value for mode_info".to_owned(),
|mi| {
mi.as_map()
.ok_or_else(|| "Erro get map for mode_info".to_owned())
.and_then(|mi_map| ModeInfo::new(mi_map))
}
|mi| mi.as_map()
.ok_or_else(|| "Erro get map for mode_info".to_owned())
.and_then(|mi_map| ModeInfo::new(mi_map))
)?;
ui.mode_info_set(try_bool!(args[0]), mode_info)
}
@ -345,13 +343,11 @@ pub struct CompleteItem<'a> {
impl<'a> CompleteItem<'a> {
fn map(menu: &'a [Vec<&str>]) -> Vec<Self> {
menu.iter()
.map(|menu| {
CompleteItem {
word: menu[0],
kind: menu[1],
menu: menu[2],
info: menu[3],
}
.map(|menu| CompleteItem {
word: menu[0],
kind: menu[1],
menu: menu[2],
info: menu[3],
})
.collect()
}