nvim_gtk/
error.rs

1use std::ops::Deref;
2
3use htmlescape::encode_minimal;
4
5use gtk;
6use gtk::prelude::*;
7
8use crate::shell;
9
10pub struct ErrorArea {
11    base: gtk::Box,
12    label: gtk::Label,
13}
14
15impl ErrorArea {
16    pub fn new() -> Self {
17        let base = gtk::Box::new(gtk::Orientation::Horizontal, 0);
18
19        let label = gtk::Label::new(None);
20        label.set_line_wrap(true);
21        let error_image = gtk::Image::new_from_icon_name(Some("dialog-error"), gtk::IconSize::Dialog);
22        base.pack_start(&error_image, false, true, 10);
23        base.pack_start(&label, true, true, 1);
24
25        ErrorArea { base, label }
26    }
27
28    pub fn show_nvim_init_error(&self, err: &str) {
29        error!("Can't initialize nvim: {}", err);
30        self.label.set_markup(&format!(
31            "<big>Can't initialize nvim:</big>\n\
32             <span foreground=\"red\"><i>{}</i></span>\n\n\
33             <big>Possible error reasons:</big>\n\
34             &#9679; Not supported nvim version (minimum supported version is <b>{}</b>)\n\
35             &#9679; Error in configuration file (init.vim or ginit.vim)",
36            encode_minimal(err),
37            shell::MINIMUM_SUPPORTED_NVIM_VERSION
38        ));
39        self.base.show_all();
40    }
41
42    pub fn show_nvim_start_error(&self, err: &str, cmd: &str) {
43        error!("Can't start nvim: {}\nCommand line: {}", err, cmd);
44        self.label.set_markup(&format!(
45            "<big>Can't start nvim instance:</big>\n\
46             <i>{}</i>\n\
47             <span foreground=\"red\"><i>{}</i></span>\n\n\
48             <big>Possible error reasons:</big>\n\
49             &#9679; Not supported nvim version (minimum supported version is <b>{}</b>)\n\
50             &#9679; Error in configuration file (init.vim or ginit.vim)\n\
51             &#9679; Wrong nvim binary path \
52             (right path can be passed with <i>--nvim-bin-path=path_here</i>)",
53            encode_minimal(cmd),
54            encode_minimal(err),
55            shell::MINIMUM_SUPPORTED_NVIM_VERSION
56        ));
57        self.base.show_all();
58    }
59}
60
61impl Deref for ErrorArea {
62    type Target = gtk::Box;
63
64    fn deref(&self) -> &gtk::Box {
65        &self.base
66    }
67}