Add option to enable external cmdline
This commit is contained in:
parent
fb9d51c928
commit
7b59a2c1eb
@ -24,8 +24,6 @@ pub struct Level {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Level {
|
impl Level {
|
||||||
//TODO: im
|
|
||||||
|
|
||||||
pub fn insert(&mut self, c: &str, shift: bool, render_state: &shell::RenderState) {
|
pub fn insert(&mut self, c: &str, shift: bool, render_state: &shell::RenderState) {
|
||||||
self.model_layout.insert_char(c, shift);
|
self.model_layout.insert_char(c, shift);
|
||||||
self.update_preferred_size(render_state);
|
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 {
|
if let Some(level) = level {
|
||||||
//TODO: limit model to row filled
|
|
||||||
render::render(
|
render::render(
|
||||||
ctx,
|
ctx,
|
||||||
state.cursor.as_ref().unwrap(),
|
state.cursor.as_ref().unwrap(),
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
mod client;
|
mod client;
|
||||||
mod handler;
|
mod handler;
|
||||||
mod mode_info;
|
mod mode_info;
|
||||||
@ -6,16 +5,16 @@ mod redraw_handler;
|
|||||||
mod repaint_mode;
|
mod repaint_mode;
|
||||||
mod ext;
|
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::repaint_mode::RepaintMode;
|
||||||
pub use self::client::{NeovimClient, NeovimClientAsync, NeovimRef};
|
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;
|
pub use self::ext::ErrorReport;
|
||||||
|
|
||||||
use std::error;
|
use std::error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::process::{Stdio, Command};
|
use std::process::{Command, Stdio};
|
||||||
use std::result;
|
use std::result;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@ -85,7 +84,6 @@ fn set_windows_creation_flags(cmd: &mut Command) {
|
|||||||
cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
|
cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn start(
|
pub fn start(
|
||||||
shell: Arc<UiMutex<shell::State>>,
|
shell: Arc<UiMutex<shell::State>>,
|
||||||
nvim_bin_path: Option<&String>,
|
nvim_bin_path: Option<&String>,
|
||||||
@ -111,14 +109,11 @@ pub fn start(
|
|||||||
set_windows_creation_flags(&mut cmd);
|
set_windows_creation_flags(&mut cmd);
|
||||||
|
|
||||||
if let Ok(runtime_path) = env::var("NVIM_GTK_RUNTIME_PATH") {
|
if let Ok(runtime_path) = env::var("NVIM_GTK_RUNTIME_PATH") {
|
||||||
cmd.arg("--cmd").arg(
|
cmd.arg("--cmd")
|
||||||
format!("let &rtp.=',{}'", runtime_path),
|
.arg(format!("let &rtp.=',{}'", runtime_path));
|
||||||
);
|
|
||||||
} else if let Some(prefix) = option_env!("PREFIX") {
|
} else if let Some(prefix) = option_env!("PREFIX") {
|
||||||
cmd.arg("--cmd").arg(format!(
|
cmd.arg("--cmd")
|
||||||
"let &rtp.=',{}/share/nvim-gtk/runtime'",
|
.arg(format!("let &rtp.=',{}/share/nvim-gtk/runtime'", prefix));
|
||||||
prefix
|
|
||||||
));
|
|
||||||
} else {
|
} else {
|
||||||
cmd.arg("--cmd").arg("let &rtp.=',runtime'");
|
cmd.arg("--cmd").arg("let &rtp.=',runtime'");
|
||||||
}
|
}
|
||||||
@ -140,9 +135,8 @@ pub fn start(
|
|||||||
|
|
||||||
let mut nvim = Neovim::new(session);
|
let mut nvim = Neovim::new(session);
|
||||||
|
|
||||||
nvim.session.start_event_loop_handler(
|
nvim.session
|
||||||
handler::NvimHandler::new(shell),
|
.start_event_loop_handler(handler::NvimHandler::new(shell));
|
||||||
);
|
|
||||||
|
|
||||||
Ok(nvim)
|
Ok(nvim)
|
||||||
}
|
}
|
||||||
@ -160,8 +154,7 @@ pub fn post_start_init(
|
|||||||
rows,
|
rows,
|
||||||
UiAttachOptions::new()
|
UiAttachOptions::new()
|
||||||
.set_popupmenu_external(true)
|
.set_popupmenu_external(true)
|
||||||
.set_tabline_external(true)
|
.set_tabline_external(true),
|
||||||
.set_cmdline_external(true),
|
|
||||||
)
|
)
|
||||||
.map_err(NvimInitError::new_post_init)?;
|
.map_err(NvimInitError::new_post_init)?;
|
||||||
|
|
||||||
@ -186,4 +179,3 @@ pub fn post_start_init(
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ use std::result;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use neovim_lib::{Value, UiOption};
|
use neovim_lib::{UiOption, Value};
|
||||||
use neovim_lib::neovim_api::Tabpage;
|
use neovim_lib::neovim_api::Tabpage;
|
||||||
|
|
||||||
use ui::UiMutex;
|
use ui::UiMutex;
|
||||||
@ -175,38 +175,34 @@ pub fn call_gui_event(
|
|||||||
) -> result::Result<(), String> {
|
) -> result::Result<(), String> {
|
||||||
match method {
|
match method {
|
||||||
"Font" => ui.set_font(try_str!(args[0])),
|
"Font" => ui.set_font(try_str!(args[0])),
|
||||||
"Clipboard" => {
|
"Clipboard" => match try_str!(args[0]) {
|
||||||
match try_str!(args[0]) {
|
"Set" => match try_str!(args[1]) {
|
||||||
"Set" => {
|
|
||||||
match try_str!(args[1]) {
|
|
||||||
"*" => ui.clipboard_primary_set(try_str!(args[2])),
|
"*" => ui.clipboard_primary_set(try_str!(args[2])),
|
||||||
_ => ui.clipboard_clipboard_set(try_str!(args[2])),
|
_ => ui.clipboard_clipboard_set(try_str!(args[2])),
|
||||||
}
|
|
||||||
},
|
},
|
||||||
opt => error!("Unknown option {}", opt),
|
opt => error!("Unknown option {}", opt),
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"Option" => {
|
"Option" => match try_str!(args[0]) {
|
||||||
match try_str!(args[0]) {
|
"Popupmenu" => ui.nvim()
|
||||||
"Popupmenu" => {
|
|
||||||
ui.nvim()
|
|
||||||
.ok_or_else(|| "Nvim not initialized".to_owned())
|
.ok_or_else(|| "Nvim not initialized".to_owned())
|
||||||
.and_then(|mut nvim| {
|
.and_then(|mut nvim| {
|
||||||
nvim.set_option(UiOption::ExtPopupmenu(try_uint!(args[1]) == 1))
|
nvim.set_option(UiOption::ExtPopupmenu(try_uint!(args[1]) == 1))
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
})?
|
})?,
|
||||||
}
|
"Tabline" => ui.nvim()
|
||||||
"Tabline" => {
|
|
||||||
ui.nvim()
|
|
||||||
.ok_or_else(|| "Nvim not initialized".to_owned())
|
.ok_or_else(|| "Nvim not initialized".to_owned())
|
||||||
.and_then(|mut nvim| {
|
.and_then(|mut nvim| {
|
||||||
nvim.set_option(UiOption::ExtTabline(try_uint!(args[1]) == 1))
|
nvim.set_option(UiOption::ExtTabline(try_uint!(args[1]) == 1))
|
||||||
.map_err(|e| e.to_string())
|
.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),
|
opt => error!("Unknown option {}", opt),
|
||||||
}
|
},
|
||||||
}
|
|
||||||
_ => return Err(format!("Unsupported event {}({:?})", method, args)),
|
_ => return Err(format!("Unsupported event {}({:?})", method, args)),
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -232,15 +228,19 @@ pub fn call_gui_request(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
let t = clipboard.wait_for_text().unwrap_or_else(|| String::new());
|
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 => {
|
opt => {
|
||||||
error!("Unknown option {}", opt);
|
error!("Unknown option {}", opt);
|
||||||
Err(Value::Nil)
|
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_start" => ui.on_busy(true),
|
||||||
"busy_stop" => ui.on_busy(false),
|
"busy_stop" => ui.on_busy(false),
|
||||||
"popupmenu_show" => {
|
"popupmenu_show" => {
|
||||||
let menu_items = map_array!(args[0], "Error get menu list array", |item| {
|
let menu_items = map_array!(args[0], "Error get menu list array", |item| map_array!(
|
||||||
map_array!(item, "Error get menu item array", |col| {
|
item,
|
||||||
col.as_str().ok_or("Error get menu column")
|
"Error get menu item array",
|
||||||
})
|
|col| col.as_str().ok_or("Error get menu column")
|
||||||
})?;
|
))?;
|
||||||
|
|
||||||
ui.popupmenu_show(
|
ui.popupmenu_show(
|
||||||
&CompleteItem::map(&menu_items),
|
&CompleteItem::map(&menu_items),
|
||||||
@ -294,9 +294,9 @@ pub fn call(
|
|||||||
.ok_or_else(|| "Error get map for tab".to_owned())
|
.ok_or_else(|| "Error get map for tab".to_owned())
|
||||||
.and_then(|tab_map| tab_map.to_attrs_map())
|
.and_then(|tab_map| tab_map.to_attrs_map())
|
||||||
.map(|tab_attrs| {
|
.map(|tab_attrs| {
|
||||||
let name_attr = tab_attrs.get("name").and_then(
|
let name_attr = tab_attrs
|
||||||
|n| n.as_str().map(|s| s.to_owned()),
|
.get("name")
|
||||||
);
|
.and_then(|n| n.as_str().map(|s| s.to_owned()));
|
||||||
let tab_attr = tab_attrs
|
let tab_attr = tab_attrs
|
||||||
.get("tab")
|
.get("tab")
|
||||||
.map(|&tab_id| Tabpage::new(tab_id.clone()))
|
.map(|&tab_id| Tabpage::new(tab_id.clone()))
|
||||||
@ -311,11 +311,9 @@ pub fn call(
|
|||||||
let mode_info = map_array!(
|
let mode_info = map_array!(
|
||||||
args[1],
|
args[1],
|
||||||
"Error get array key value for mode_info".to_owned(),
|
"Error get array key value for mode_info".to_owned(),
|
||||||
|mi| {
|
|mi| mi.as_map()
|
||||||
mi.as_map()
|
|
||||||
.ok_or_else(|| "Erro get map for mode_info".to_owned())
|
.ok_or_else(|| "Erro get map for mode_info".to_owned())
|
||||||
.and_then(|mi_map| ModeInfo::new(mi_map))
|
.and_then(|mi_map| ModeInfo::new(mi_map))
|
||||||
}
|
|
||||||
)?;
|
)?;
|
||||||
ui.mode_info_set(try_bool!(args[0]), mode_info)
|
ui.mode_info_set(try_bool!(args[0]), mode_info)
|
||||||
}
|
}
|
||||||
@ -345,13 +343,11 @@ pub struct CompleteItem<'a> {
|
|||||||
impl<'a> CompleteItem<'a> {
|
impl<'a> CompleteItem<'a> {
|
||||||
fn map(menu: &'a [Vec<&str>]) -> Vec<Self> {
|
fn map(menu: &'a [Vec<&str>]) -> Vec<Self> {
|
||||||
menu.iter()
|
menu.iter()
|
||||||
.map(|menu| {
|
.map(|menu| CompleteItem {
|
||||||
CompleteItem {
|
|
||||||
word: menu[0],
|
word: menu[0],
|
||||||
kind: menu[1],
|
kind: menu[1],
|
||||||
menu: menu[2],
|
menu: menu[2],
|
||||||
info: menu[3],
|
info: menu[3],
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user