linux bug fixes and better error printing on linux (just panic with a message)

macos-click-through
keith 5 years ago
parent 2916f1337a
commit 2f619c5d17

@ -14,7 +14,6 @@ skulpin = "0.5"
derive-new = "0.5"
env_logger = "0.7.1"
rmpv = "0.4.2"
msgbox = "0.4.0"
rust-embed = { version = "5.2.0", features = ["debug-embed"] }
image = "0.22.3"
nvim-rs = { git = "https://github.com/KillTheMule/nvim-rs", branch = "futures", features = [ "use_tokio" ] }
@ -23,6 +22,9 @@ async-trait = "0.1.18"
lazy_static = "1.4.0"
unicode-segmentation = "1.6.0"
[target.'cfg(not(linux))'.dependencies]
msgbox = { version = "0.4.0"}
[build-dependencies]
winres = "0.1.11"

@ -223,7 +223,7 @@ fn parse_mode_info_set(mode_info_set_arguments: Vec<Value>) -> Result<RedrawEven
let mut cursor_modes = Vec::new();
for mode_info_value in mode_info_values {
let info_map = parse_map(&mode_info_value)?;
let mut mode_info = CursorMode::new();
let mut mode_info = CursorMode::default();
for (name, value) in info_map {
let name = parse_string(&name)?;
match name.as_ref() {

@ -1,13 +1,11 @@
use std::sync::{Arc, Mutex};
use rmpv::Value;
use nvim_rs::{Neovim, Handler, compat::tokio::Compat};
use async_trait::async_trait;
use tokio::process::ChildStdin;
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
use tokio::sync::mpsc::{unbounded_channel, UnboundedSender};
use crate::error_handling::ResultPanicExplanation;
use crate::editor::{EDITOR, Editor};
use crate::editor::EDITOR;
use super::events::{RedrawEvent, parse_neovim_event};
#[derive(Clone)]
@ -32,7 +30,10 @@ impl NeovimHandler {
}
pub fn handle_redraw_event(&self, event: RedrawEvent) {
self.sender.send(event);
self.sender.send(event)
.unwrap_or_explained_panic(
"Could not process neovim event.",
"The main thread for Neovide has closed the communication channel preventing a neovim event from being processed.");
}
}

@ -114,8 +114,7 @@ impl Bridge {
}
pub fn queue_command(&self, command: UiCommand) {
let mut sender = self.sender.clone();
sender.send(command)
self.sender.send(command)
.unwrap_or_explained_panic(
"Could Not Send UI Command",
"Could not send UI command from the window system to the neovim process.");

@ -21,19 +21,13 @@ impl CursorShape {
}
}
#[derive(new, Debug, Clone, PartialEq)]
#[derive(Default, Debug, Clone, PartialEq)]
pub struct CursorMode {
#[new(default)]
pub shape: Option<CursorShape>,
#[new(default)]
pub style_id: Option<u64>,
#[new(default)]
pub cell_percentage: Option<f32>,
#[new(default)]
pub blinkwait: Option<u64>,
#[new(default)]
pub blinkon: Option<u64>,
#[new(default)]
pub blinkoff: Option<u64>,
}

@ -1,5 +1,14 @@
use msgbox::IconType;
fn show_error(title: &str, explanation: &str) -> ! {
if cfg!(target_os = "linux") {
panic!("{}: {}", title, explanation);
} else {
msgbox::create(title, explanation, IconType::Error);
panic!(explanation.to_string());
}
}
pub trait ResultPanicExplanation<T, E: ToString> {
fn unwrap_or_explained_panic(self, title: &str, explanation: &str) -> T;
}
@ -9,8 +18,7 @@ impl<T, E: ToString> ResultPanicExplanation<T, E> for Result<T, E> {
match self {
Err(error) => {
let explanation = format!("{}: {}", explanation, error.to_string());
msgbox::create(title, &explanation, IconType::Error);
panic!(explanation);
show_error(title, &explanation);
},
Ok(content) => content
}
@ -25,8 +33,7 @@ impl<T> OptionPanicExplanation<T> for Option<T> {
fn unwrap_or_explained_panic(self, title: &str, explanation: &str) -> T {
match self {
None => {
msgbox::create(title, &explanation, IconType::Error);
panic!(explanation.to_string());
show_error(title, explanation);
},
Some(content) => content
}

@ -46,7 +46,7 @@ pub fn redraw_loop() {
}
}
if let Some(time_to_sleep) = Duration::from_secs_f32(1.0 / 60.0).checked_sub(Instant::now() - frame_start) {
if let Some(time_to_sleep) = Duration::from_secs_f32(1.0 / 60.0).checked_sub(frame_start.elapsed()) {
thread::sleep(time_to_sleep)
}
}

@ -1,28 +0,0 @@
use std::time::Instant;
pub struct FpsTracker {
last_record_time: Instant,
frame_count: usize,
pub fps: usize
}
impl FpsTracker {
pub fn new() -> FpsTracker {
FpsTracker {
fps: 0,
last_record_time: Instant::now(),
frame_count: 0
}
}
pub fn record_frame(&mut self) {
self.frame_count = self.frame_count + 1;
let now = Instant::now();
let time_since = (now - self.last_record_time).as_secs_f32();
if time_since > 1.0 {
self.fps = self.frame_count;
self.last_record_time = now;
self.frame_count = 0;
}
}
}
Loading…
Cancel
Save