Use colors for selected items, enable popup menu by default
This commit is contained in:
parent
3b9de543ae
commit
50603b4325
13
src/color.rs
13
src/color.rs
@ -36,6 +36,15 @@ impl Color {
|
||||
(std::u16::MAX as f64 * self.2) as u16,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn to_hex(&self) -> String {
|
||||
format!(
|
||||
"#{:X}{:X}{:X}",
|
||||
(self.0 * 255.0) as u8,
|
||||
(self.1 * 255.0) as u8,
|
||||
(self.2 * 255.0) as u8
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ColorModel {
|
||||
@ -93,7 +102,7 @@ impl ColorModel {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn actual_cell_bg<'a>(&'a self, cell: &'a Cell) -> &'a Color {
|
||||
pub fn actual_cell_bg<'a>(&'a self, cell: &'a Cell) -> &'a Color {
|
||||
if !cell.attrs.reverse {
|
||||
cell.attrs.background.as_ref().unwrap_or(&self.bg_color)
|
||||
} else {
|
||||
@ -102,7 +111,7 @@ impl ColorModel {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn actual_cell_sp<'a>(&'a self, cell: &'a Cell) -> &'a Color {
|
||||
pub fn actual_cell_sp<'a>(&'a self, cell: &'a Cell) -> &'a Color {
|
||||
cell.attrs.special.as_ref().unwrap_or(&self.sp_color)
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ pub fn post_start_init(
|
||||
rows: u64,
|
||||
) -> result::Result<(), NvimInitError> {
|
||||
let mut opts = UiAttachOptions::new();
|
||||
opts.set_popupmenu_external(false);
|
||||
opts.set_popupmenu_external(true);
|
||||
opts.set_tabline_external(true);
|
||||
nvim.borrow().unwrap().ui_attach(cols, rows, &opts).map_err(
|
||||
NvimInitError::new_post_init,
|
||||
|
@ -9,8 +9,8 @@ use gdk::{EventButton, EventType};
|
||||
|
||||
use neovim_lib::{Neovim, NeovimApi};
|
||||
|
||||
use nvim;
|
||||
use nvim::ErrorReport;
|
||||
use color::ColorModel;
|
||||
use nvim::{self, ErrorReport};
|
||||
use shell;
|
||||
use input;
|
||||
|
||||
@ -21,15 +21,23 @@ struct State {
|
||||
renderer: gtk::CellRendererText,
|
||||
tree: gtk::TreeView,
|
||||
scroll: gtk::ScrolledWindow,
|
||||
css_provider: gtk::CssProvider,
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub fn new() -> Self {
|
||||
let tree = gtk::TreeView::new();
|
||||
let css_provider = gtk::CssProvider::new();
|
||||
|
||||
let style_context = tree.get_style_context().unwrap();
|
||||
style_context.add_provider(&css_provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
|
||||
State {
|
||||
nvim: None,
|
||||
renderer: gtk::CellRendererText::new(),
|
||||
tree: gtk::TreeView::new(),
|
||||
tree,
|
||||
scroll: gtk::ScrolledWindow::new(None, None),
|
||||
css_provider,
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,6 +67,8 @@ impl State {
|
||||
Some(&color_model.pmenu_bg().into()),
|
||||
);
|
||||
|
||||
self.update_css(color_model);
|
||||
|
||||
let col_count = menu[0].len();
|
||||
let columns = self.tree.get_columns();
|
||||
|
||||
@ -84,6 +94,23 @@ impl State {
|
||||
self.tree.set_model(Some(&list_store));
|
||||
}
|
||||
|
||||
fn update_css(&self, color_model: &ColorModel) {
|
||||
let bg = color_model.pmenu_bg_sel();
|
||||
let fg = color_model.pmenu_fg_sel();
|
||||
|
||||
match gtk::CssProviderExtManual::load_from_data(
|
||||
&self.css_provider,
|
||||
&format!(
|
||||
".view {{ color: {}; background-color: {};}}",
|
||||
fg.to_hex(),
|
||||
bg.to_hex()
|
||||
),
|
||||
) {
|
||||
Err(e) => error!("Can't update css {}", e),
|
||||
Ok(_) => (),
|
||||
};
|
||||
}
|
||||
|
||||
fn append_column(&self, id: i32) {
|
||||
let renderer = &self.renderer;
|
||||
|
||||
|
@ -34,7 +34,7 @@ use render;
|
||||
use render::CellMetrics;
|
||||
|
||||
const DEFAULT_FONT_NAME: &str = "DejaVu Sans Mono 12";
|
||||
pub const MINIMUM_SUPPORTED_NVIM_VERSION: &str = "0.2";
|
||||
pub const MINIMUM_SUPPORTED_NVIM_VERSION: &str = "0.2.1";
|
||||
|
||||
macro_rules! idle_cb_call {
|
||||
($state:ident.$cb:ident($( $x:expr ),*)) => (
|
||||
|
Loading…
Reference in New Issue
Block a user