Apply rustfmt
This commit is contained in:
parent
9967b4bdb4
commit
d30f65c45f
14
src/shell.rs
14
src/shell.rs
@ -33,7 +33,7 @@ use error;
|
|||||||
use mode;
|
use mode;
|
||||||
use render;
|
use render;
|
||||||
use render::CellMetrics;
|
use render::CellMetrics;
|
||||||
use subscriptions::{Subscriptions, SubscriptionHandle};
|
use subscriptions::{SubscriptionHandle, Subscriptions};
|
||||||
|
|
||||||
const DEFAULT_FONT_NAME: &str = "DejaVu Sans Mono 12";
|
const DEFAULT_FONT_NAME: &str = "DejaVu Sans Mono 12";
|
||||||
pub const MINIMUM_SUPPORTED_NVIM_VERSION: &str = "0.2.2";
|
pub const MINIMUM_SUPPORTED_NVIM_VERSION: &str = "0.2.2";
|
||||||
@ -338,11 +338,15 @@ impl State {
|
|||||||
where
|
where
|
||||||
F: Fn(Vec<String>) + 'static,
|
F: Fn(Vec<String>) + 'static,
|
||||||
{
|
{
|
||||||
self.subscriptions.borrow_mut().subscribe(event_name, args, cb)
|
self.subscriptions
|
||||||
|
.borrow_mut()
|
||||||
|
.subscribe(event_name, args, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_autocmds(&self) {
|
pub fn set_autocmds(&self) {
|
||||||
self.subscriptions.borrow().set_autocmds(&mut self.nvim().unwrap());
|
self.subscriptions
|
||||||
|
.borrow()
|
||||||
|
.set_autocmds(&mut self.nvim().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn notify(&self, params: Vec<Value>) -> Result<(), String> {
|
pub fn notify(&self, params: Vec<Value>) -> Result<(), String> {
|
||||||
@ -350,7 +354,9 @@ impl State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_now(&self, handle: &SubscriptionHandle) {
|
pub fn run_now(&self, handle: &SubscriptionHandle) {
|
||||||
self.subscriptions.borrow().run_now(handle, &mut self.nvim().unwrap());
|
self.subscriptions
|
||||||
|
.borrow()
|
||||||
|
.run_now(handle, &mut self.nvim().unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,15 +89,13 @@ impl Subscriptions {
|
|||||||
pub fn set_autocmds(&self, nvim: &mut NeovimRef) {
|
pub fn set_autocmds(&self, nvim: &mut NeovimRef) {
|
||||||
for (event_name, subscriptions) in &self.0 {
|
for (event_name, subscriptions) in &self.0 {
|
||||||
for (i, subscription) in subscriptions.iter().enumerate() {
|
for (i, subscription) in subscriptions.iter().enumerate() {
|
||||||
let args = subscription.args
|
let args = subscription
|
||||||
|
.args
|
||||||
.iter()
|
.iter()
|
||||||
.fold("".to_owned(), |acc, arg| acc + ", " + &arg);
|
.fold("".to_owned(), |acc, arg| acc + ", " + &arg);
|
||||||
nvim.command(&format!(
|
nvim.command(&format!(
|
||||||
"au {} * call rpcnotify(1, 'subscription', '{}', {} {})",
|
"au {} * call rpcnotify(1, 'subscription', '{}', {} {})",
|
||||||
event_name,
|
event_name, event_name, i, args,
|
||||||
event_name,
|
|
||||||
i,
|
|
||||||
args,
|
|
||||||
)).expect("Could not set autocmd");
|
)).expect("Could not set autocmd");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,14 +137,13 @@ impl Subscriptions {
|
|||||||
/// This function is wrapped by `shell::State`.
|
/// This function is wrapped by `shell::State`.
|
||||||
pub fn run_now(&self, handle: &SubscriptionHandle, nvim: &mut NeovimRef) {
|
pub fn run_now(&self, handle: &SubscriptionHandle, nvim: &mut NeovimRef) {
|
||||||
let subscription = &self.0.get(&handle.event_name).unwrap()[handle.index];
|
let subscription = &self.0.get(&handle.event_name).unwrap()[handle.index];
|
||||||
let args = subscription.args
|
let args = subscription
|
||||||
|
.args
|
||||||
.iter()
|
.iter()
|
||||||
.map(|arg| nvim.eval(arg))
|
.map(|arg| nvim.eval(arg))
|
||||||
.map(|res| {
|
.map(|res| {
|
||||||
res.ok()
|
res.ok()
|
||||||
.and_then(|val| {
|
.and_then(|val| val.as_str().map(|s: &str| s.to_owned()))
|
||||||
val.as_str().map(|s: &str| s.to_owned())
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.collect::<Option<Vec<String>>>();
|
.collect::<Option<Vec<String>>>();
|
||||||
if let Some(args) = args {
|
if let Some(args) = args {
|
||||||
|
34
src/ui.rs
34
src/ui.rs
@ -61,7 +61,9 @@ impl Components {
|
|||||||
open_btn_box.pack_start(>k::Label::new("Open"), false, false, 3);
|
open_btn_box.pack_start(>k::Label::new("Open"), false, false, 3);
|
||||||
open_btn_box.pack_start(
|
open_btn_box.pack_start(
|
||||||
>k::Image::new_from_icon_name("pan-down-symbolic", gtk::IconSize::Menu.into()),
|
>k::Image::new_from_icon_name("pan-down-symbolic", gtk::IconSize::Menu.into()),
|
||||||
false, false, 3
|
false,
|
||||||
|
false,
|
||||||
|
3,
|
||||||
);
|
);
|
||||||
open_btn.add(&open_btn_box);
|
open_btn.add(&open_btn_box);
|
||||||
open_btn.set_can_focus(false);
|
open_btn.set_can_focus(false);
|
||||||
@ -184,8 +186,10 @@ impl Ui {
|
|||||||
window.show_all();
|
window.show_all();
|
||||||
|
|
||||||
let comps_ref = self.comps.clone();
|
let comps_ref = self.comps.clone();
|
||||||
let update_title = shell.state.borrow()
|
let update_title = shell.state.borrow().subscribe(
|
||||||
.subscribe("BufEnter,DirChanged", &["expand('%:p')", "getcwd()"], move |args| {
|
"BufEnter,DirChanged",
|
||||||
|
&["expand('%:p')", "getcwd()"],
|
||||||
|
move |args| {
|
||||||
let comps = comps_ref.borrow();
|
let comps = comps_ref.borrow();
|
||||||
let window = comps.window.as_ref().unwrap();
|
let window = comps.window.as_ref().unwrap();
|
||||||
let file_path = &args[0];
|
let file_path = &args[0];
|
||||||
@ -202,7 +206,8 @@ impl Ui {
|
|||||||
&file_path
|
&file_path
|
||||||
};
|
};
|
||||||
window.set_title(filename);
|
window.set_title(filename);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
let comps_ref = self.comps.clone();
|
let comps_ref = self.comps.clone();
|
||||||
let shell_ref = self.shell.clone();
|
let shell_ref = self.shell.clone();
|
||||||
@ -245,19 +250,15 @@ impl Ui {
|
|||||||
.open_btn
|
.open_btn
|
||||||
.connect_clicked(move |_| projects.borrow_mut().show());
|
.connect_clicked(move |_| projects.borrow_mut().show());
|
||||||
|
|
||||||
let new_tab_btn = Button::new_from_icon_name(
|
let new_tab_btn =
|
||||||
"tab-new-symbolic",
|
Button::new_from_icon_name("tab-new-symbolic", gtk::IconSize::SmallToolbar.into());
|
||||||
gtk::IconSize::SmallToolbar.into(),
|
|
||||||
);
|
|
||||||
let shell_ref = Rc::clone(&self.shell);
|
let shell_ref = Rc::clone(&self.shell);
|
||||||
new_tab_btn.connect_clicked(move |_| shell_ref.borrow_mut().new_tab());
|
new_tab_btn.connect_clicked(move |_| shell_ref.borrow_mut().new_tab());
|
||||||
new_tab_btn.set_can_focus(false);
|
new_tab_btn.set_can_focus(false);
|
||||||
header_bar.pack_start(&new_tab_btn);
|
header_bar.pack_start(&new_tab_btn);
|
||||||
|
|
||||||
let paste_btn = Button::new_from_icon_name(
|
let paste_btn =
|
||||||
"edit-paste",
|
Button::new_from_icon_name("edit-paste", gtk::IconSize::SmallToolbar.into());
|
||||||
gtk::IconSize::SmallToolbar.into(),
|
|
||||||
);
|
|
||||||
let shell = self.shell.clone();
|
let shell = self.shell.clone();
|
||||||
paste_btn.connect_clicked(move |_| shell.borrow_mut().edit_paste());
|
paste_btn.connect_clicked(move |_| shell.borrow_mut().edit_paste());
|
||||||
paste_btn.set_can_focus(false);
|
paste_btn.set_can_focus(false);
|
||||||
@ -274,10 +275,13 @@ impl Ui {
|
|||||||
window.set_titlebar(Some(&header_bar));
|
window.set_titlebar(Some(&header_bar));
|
||||||
|
|
||||||
let shell = self.shell.borrow();
|
let shell = self.shell.borrow();
|
||||||
let update_subtitle = shell.state.borrow()
|
let update_subtitle = shell.state.borrow().subscribe(
|
||||||
.subscribe("DirChanged", &["getcwd()"], move |args| {
|
"DirChanged",
|
||||||
|
&["getcwd()"],
|
||||||
|
move |args| {
|
||||||
header_bar.set_subtitle(&*args[0]);
|
header_bar.set_subtitle(&*args[0]);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
update_subtitle
|
update_subtitle
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user