diff options
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 172 |
1 files changed, 78 insertions, 94 deletions
diff --git a/src/config.rs b/src/config.rs index 20bb3d9f..9664d5df 100644 --- a/src/config.rs +++ b/src/config.rs @@ -26,9 +26,7 @@ use glutin::ModifiersState; use cli::Options; use input::{Action, Binding, MouseBinding, KeyBinding}; use index::{Line, Column}; -use ansi::CursorStyle; - -use util::fmt::Yellow; +use ansi::{CursorStyle, NamedColor, Color}; const MAX_SCROLLBACK_LINES: u32 = 100_000; @@ -88,6 +86,8 @@ pub struct Mouse { #[serde(default, deserialize_with = "failure_default")] pub triple_click: ClickHandler, #[serde(default, deserialize_with = "failure_default")] + pub hide_when_typing: bool, + #[serde(default, deserialize_with = "failure_default")] pub url: Url, // TODO: DEPRECATED @@ -132,6 +132,7 @@ impl Default for Mouse { triple_click: ClickHandler { threshold: Duration::from_millis(300), }, + hide_when_typing: false, url: Url::default(), faux_scrollback_lines: None, } @@ -443,10 +444,6 @@ pub struct Config { #[serde(default, deserialize_with = "failure_default")] render_timer: bool, - /// Should use custom cursor colors - #[serde(default, deserialize_with = "failure_default")] - custom_cursor_colors: bool, - /// Should draw bold text with brighter colors instead of bold font #[serde(default="true_bool", deserialize_with = "default_true_bool")] draw_bold_text_with_bright_colors: bool, @@ -492,18 +489,6 @@ pub struct Config { #[serde(default="true_bool", deserialize_with = "default_true_bool")] dynamic_title: bool, - /// Hide cursor when typing - #[serde(default, deserialize_with = "failure_default")] - hide_cursor_when_typing: bool, - - /// Style of the cursor - #[serde(default, deserialize_with = "failure_default")] - cursor_style: CursorStyle, - - /// Use hollow block cursor when unfocused - #[serde(default="true_bool", deserialize_with = "default_true_bool")] - unfocused_hollow_cursor: bool, - /// Live config reload #[serde(default="true_bool", deserialize_with = "default_true_bool")] live_config_reload: bool, @@ -515,6 +500,26 @@ pub struct Config { /// How much scrolling history to keep #[serde(default, deserialize_with="failure_default")] scrolling: Scrolling, + + /// Cursor configuration + #[serde(default, deserialize_with="failure_default")] + cursor: Cursor, + + // TODO: DEPRECATED + #[serde(default, deserialize_with = "failure_default")] + custom_cursor_colors: Option<bool>, + + // TODO: DEPRECATED + #[serde(default, deserialize_with = "failure_default")] + hide_cursor_when_typing: Option<bool>, + + // TODO: DEPRECATED + #[serde(default, deserialize_with = "failure_default")] + cursor_style: Option<CursorStyle>, + + // TODO: DEPRECATED + #[serde(default, deserialize_with = "failure_default")] + unfocused_hollow_cursor: Option<bool>, } fn failure_default_vec<'a, D, T>(deserializer: D) -> ::std::result::Result<Vec<T>, D::Error> @@ -1166,7 +1171,7 @@ pub enum Error { pub struct Colors { #[serde(default, deserialize_with = "failure_default")] pub primary: PrimaryColors, - #[serde(default, deserialize_with = "deserialize_cursor_colors")] + #[serde(default, deserialize_with = "failure_default")] pub cursor: CursorColors, pub normal: AnsiColors, pub bright: AnsiColors, @@ -1212,71 +1217,20 @@ fn deserialize_color_index<'a, D>(deserializer: D) -> ::std::result::Result<u8, } } -#[derive(Deserialize)] -#[serde(untagged)] -pub enum CursorOrPrimaryColors { - Cursor { - #[serde(deserialize_with = "rgb_from_hex")] - text: Rgb, - #[serde(deserialize_with = "rgb_from_hex")] - cursor: Rgb, - }, - Primary { - #[serde(deserialize_with = "rgb_from_hex")] - foreground: Rgb, - #[serde(deserialize_with = "rgb_from_hex")] - background: Rgb, - } -} - -impl CursorOrPrimaryColors { - fn into_cursor_colors(self) -> CursorColors { - match self { - CursorOrPrimaryColors::Cursor { text, cursor } => CursorColors { - text, - cursor, - }, - CursorOrPrimaryColors::Primary { foreground, background } => { - // Must print in config since logger isn't setup yet. - eprintln!("{}", - Yellow("Config `colors.cursor.foreground` and `colors.cursor.background` \ - are deprecated. Please use `colors.cursor.text` and \ - `colors.cursor.cursor` instead.") - ); - CursorColors { - text: foreground, - cursor: background - } - } - } - } +#[derive(Copy, Clone, Debug, Default, Deserialize)] +pub struct Cursor { + #[serde(default, deserialize_with = "failure_default")] + pub style: CursorStyle, + #[serde(default="true_bool", deserialize_with = "default_true_bool")] + pub unfocused_hollow: bool, } -#[derive(Debug)] +#[derive(Debug, Copy, Clone, Default, Deserialize)] pub struct CursorColors { - pub text: Rgb, - pub cursor: Rgb, -} - -impl Default for CursorColors { - fn default() -> Self { - CursorColors { - text: Rgb { r: 0, g: 0, b: 0 }, - cursor: Rgb { r: 0xff, g: 0xff, b: 0xff }, - } - } -} - -fn deserialize_cursor_colors<'a, D>(deserializer: D) -> ::std::result::Result<CursorColors, D::Error> - where D: de::Deserializer<'a> -{ - match CursorOrPrimaryColors::deserialize(deserializer) { - Ok(either) => Ok(either.into_cursor_colors()), - Err(err) => { - eprintln!("problem with config: {}; Using default value", err); - Ok(CursorColors::default()) - }, - } + #[serde(default, deserialize_with = "deserialize_optional_color")] + pub text: Option<Rgb>, + #[serde(default, deserialize_with = "deserialize_optional_color")] + pub cursor: Option<Rgb>, } #[derive(Debug, Deserialize)] @@ -1644,12 +1598,6 @@ impl Config { self.font.use_thin_strokes } - /// show cursor as inverted - #[inline] - pub fn custom_cursor_colors(&self) -> bool { - self.custom_cursor_colors - } - pub fn path(&self) -> Option<&Path> { self.config_path .as_ref() @@ -1664,22 +1612,22 @@ impl Config { &self.env } - /// Should hide cursor when typing + /// Should hide mouse cursor when typing #[inline] - pub fn hide_cursor_when_typing(&self) -> bool { - self.hide_cursor_when_typing + pub fn hide_mouse_when_typing(&self) -> bool { + self.hide_cursor_when_typing.unwrap_or(self.mouse.hide_when_typing) } /// Style of the cursor #[inline] pub fn cursor_style(&self) -> CursorStyle { - self.cursor_style + self.cursor_style.unwrap_or(self.cursor.style) } /// Use hollow block cursor when unfocused #[inline] pub fn unfocused_hollow_cursor(&self) -> bool { - self.unfocused_hollow_cursor + self.unfocused_hollow_cursor.unwrap_or(self.cursor.unfocused_hollow) } /// Live config reload @@ -1699,6 +1647,18 @@ impl Config { self.scrolling } + /// Cursor foreground color + #[inline] + pub fn cursor_text_color(&self) -> Option<Color> { + self.colors.cursor.text.map(|_| Color::Named(NamedColor::CursorText)) + } + + /// Cursor background color + #[inline] + pub fn cursor_cursor_color(&self) -> Option<Color> { + self.colors.cursor.cursor.map(|_| Color::Named(NamedColor::Cursor)) + } + // Update the history size, used in ref tests pub fn set_history(&mut self, history: u32) { self.scrolling.history = history; @@ -1733,7 +1693,7 @@ impl Config { Ok(contents) } - fn print_deprecation_warnings(&self) { + fn print_deprecation_warnings(&mut self) { use ::util::fmt; if self.dimensions.is_some() { eprintln!("{}", fmt::Yellow("Config `dimensions` is deprecated. \ @@ -1749,6 +1709,30 @@ impl Config { println!("{}", fmt::Yellow("Config `mouse.faux_scrollback_lines` is deprecated. \ Please use `mouse.faux_scrolling_lines` instead.")); } + + if let Some(custom_cursor_colors) = self.custom_cursor_colors { + eprintln!("{}", fmt::Yellow("Config `custom_cursor_colors` is deprecated.")); + + if !custom_cursor_colors { + self.colors.cursor.cursor = None; + self.colors.cursor.text = None; + } + } + + if self.cursor_style.is_some() { + eprintln!("{}", fmt::Yellow("Config `cursor_style` is deprecated. \ + Please use `cursor.style` instead.")); + } + + if self.hide_cursor_when_typing.is_some() { + eprintln!("{}", fmt::Yellow("Config `hide_cursor_when_typing` is deprecated. \ + Please use `mouse.hide_when_typing` instead.")); + } + + if self.unfocused_hollow_cursor.is_some() { + eprintln!("{}", fmt::Yellow("Config `unfocused_hollow_cursor` is deprecated. \ + Please use `cursor.unfocused_hollow` instead.")); + } } } |