diff options
author | Tim Oram <dev@mitmaro.ca> | 2020-01-10 20:45:24 -0330 |
---|---|---|
committer | Tim Oram <dev@mitmaro.ca> | 2020-01-10 21:17:55 -0330 |
commit | 64b39f937759c1ce68e28466cee68feb2ff92d1d (patch) | |
tree | 7b1af00fc8d2916c8e585a41909d84cb20006591 | |
parent | f34eaf612cd1afd8d89817f98c06f583cc5fc0c6 (diff) |
Disable selected line in Terminal.app on MacOS
Colour pairs in Terminal.app cannot be overwritten, so it is not
possible to do selected line with that terminal. So in that application
the selected line functionality will be disabled.
-rw-r--r-- | src/display/curses.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/display/curses.rs b/src/display/curses.rs index 9ca4baa..c11220c 100644 --- a/src/display/curses.rs +++ b/src/display/curses.rs @@ -12,13 +12,14 @@ use pancurses::{ COLOR_YELLOW, }; use std::collections::HashMap; +use std::env::var; pub(crate) struct Curses { color_lookup: HashMap<(i16, i16, i16), i16>, color_index: i16, color_pair_index: i16, - number_of_colors: usize, window: pancurses::Window, + selected_line_enabled: bool, } impl Curses { @@ -38,12 +39,15 @@ impl Curses { // pair zero should always be default pancurses::init_pair(0, -1, -1); + let number_of_colors = pancurses::COLORS() as usize; + Self { window, - number_of_colors: pancurses::COLORS() as usize, color_lookup: HashMap::new(), color_index: 8, color_pair_index: 1, + // Terminal.app on MacOS doesn't not properly support the color pairs needed for selected line + selected_line_enabled: number_of_colors > 16 && var("TERM_PROGRAM").unwrap_or_default() != "Apple_Terminal", } } @@ -88,7 +92,7 @@ impl Curses { ) -> (chtype, chtype) { let standard_pair = self.init_color_pair(foreground, background); - if self.number_of_colors > 16 { + if self.selected_line_enabled { return (standard_pair, self.init_color_pair(foreground, selected_background)); } // when there is not enough color pairs to support selected |