Fixed command line parsing. Added error reporting on wrong setting data type

macos-click-through
Jon Valdés 5 years ago
parent 0a726c2f77
commit 28128b56b2

@ -17,8 +17,14 @@ struct RedrawSettings {
pub fn initialize_settings() { pub fn initialize_settings() {
let buffer_frames = if SETTINGS.neovim_arguments.contains(&String::from("--extraBufferFrames")) {
60
}else{
1
};
SETTINGS.set(&RedrawSettings { SETTINGS.set(&RedrawSettings {
extra_buffer_frames: 60, extra_buffer_frames: buffer_frames,
}); });
register_nvim_setting!("extra_buffer_frames", RedrawSettings::extra_buffer_frames); register_nvim_setting!("extra_buffer_frames", RedrawSettings::extra_buffer_frames);

@ -8,7 +8,7 @@ use nvim_rs::compat::tokio::Compat;
use flexi_logger::{Logger, Criterion, Naming, Cleanup}; use flexi_logger::{Logger, Criterion, Naming, Cleanup};
use tokio::process::ChildStdin; use tokio::process::ChildStdin;
use parking_lot::RwLock; use parking_lot::RwLock;
use log::warn; use log::{error,warn};
use crate::error_handling::ResultPanicExplanation; use crate::error_handling::ResultPanicExplanation;
@ -22,46 +22,54 @@ pub trait FromValue {
impl FromValue for f32 { impl FromValue for f32 {
fn from_value(&mut self, value: Value) { fn from_value(&mut self, value: Value) {
// TODO -- Warn when incorrect type
if value.is_f32() { if value.is_f32() {
*self = value.as_f64().unwrap() as f32; *self = value.as_f64().unwrap() as f32;
}else{
error!("Setting expected an f32, but received {:?}", value);
} }
} }
} }
impl FromValue for u64 { impl FromValue for u64 {
fn from_value(&mut self, value: Value) { fn from_value(&mut self, value: Value) {
// TODO -- Warn when incorrect type
if value.is_u64() { if value.is_u64() {
*self = value.as_u64().unwrap(); *self = value.as_u64().unwrap();
}else{
error!("Setting expected a u64, but received {:?}", value);
} }
} }
} }
impl FromValue for u32 { impl FromValue for u32 {
fn from_value(&mut self, value: Value) { fn from_value(&mut self, value: Value) {
// TODO -- Warn when incorrect type
if value.is_u64() { if value.is_u64() {
*self = value.as_u64().unwrap() as u32; *self = value.as_u64().unwrap() as u32;
}else{
error!("Setting expected a u32, but received {:?}", value);
} }
} }
} }
impl FromValue for i32 { impl FromValue for i32 {
fn from_value(&mut self, value: Value) { fn from_value(&mut self, value: Value) {
// TODO -- Warn when incorrect type
if value.is_i64() { if value.is_i64() {
*self = value.as_i64().unwrap() as i32; *self = value.as_i64().unwrap() as i32;
}else{
error!("Setting expected an i32, but received {:?}", value);
} }
} }
} }
impl FromValue for String { impl FromValue for String {
fn from_value(&mut self, value: Value) { fn from_value(&mut self, value: Value) {
// TODO -- Warn when incorrect type
if value.is_str() { if value.is_str() {
*self = String::from(value.as_str().unwrap()); *self = String::from(value.as_str().unwrap());
}else{
error!("Setting expected a string, but received {:?}", value);
} }
} }
} }
@ -88,7 +96,7 @@ macro_rules! register_nvim_setting {
s.$field_name.into() s.$field_name.into()
} }
SETTINGS.add_handlers($vim_setting_name, update_func, reader_func); SETTINGS.set_setting_handlers($vim_setting_name, update_func, reader_func);
}}; }};
} }
@ -110,11 +118,6 @@ impl Settings {
fn new() -> Settings { fn new() -> Settings {
let mut no_idle = false;
let mut buffer_frames = 1;
// TODO -- Make command line parsing work again
let neovim_arguments = std::env::args().filter(|arg| { let neovim_arguments = std::env::args().filter(|arg| {
if arg == "--log" { if arg == "--log" {
Logger::with_str("neovide") Logger::with_str("neovide")
@ -123,18 +126,11 @@ impl Settings {
.start() .start()
.expect("Could not start logger"); .expect("Could not start logger");
false false
} else if arg == "--noIdle" {
no_idle = true;
false
} else if arg == "--extraBufferFrames" {
buffer_frames = 60;
false
} else { } else {
true true
} }
}).collect::<Vec<String>>(); }).collect::<Vec<String>>();
Settings{ Settings{
neovim_arguments, neovim_arguments,
settings: RwLock::new(HashMap::new()), settings: RwLock::new(HashMap::new()),
@ -143,7 +139,7 @@ impl Settings {
} }
} }
pub fn add_handlers(&self, property_name: &str, update_func: UpdateHandlerFunc, reader_func: ReaderFunc) { pub fn set_setting_handlers(&self, property_name: &str, update_func: UpdateHandlerFunc, reader_func: ReaderFunc) {
self.listeners.write().insert(String::from(property_name), update_func); self.listeners.write().insert(String::from(property_name), update_func);
self.readers.write().insert(String::from(property_name), reader_func); self.readers.write().insert(String::from(property_name), reader_func);
} }

@ -258,9 +258,12 @@ struct WindowSettings {
} }
pub fn initialize_settings() { pub fn initialize_settings() {
let no_idle = SETTINGS.neovim_arguments.contains(&String::from("--noIdle"));
SETTINGS.set(&WindowSettings { SETTINGS.set(&WindowSettings {
refresh_rate: 60, refresh_rate: 60,
no_idle: false, no_idle,
}); });
register_nvim_setting!("refresh_rate", WindowSettings::refresh_rate); register_nvim_setting!("refresh_rate", WindowSettings::refresh_rate);

Loading…
Cancel
Save