diff --git a/src/color.rs b/src/color.rs index 6fd5a0e..13587cb 100644 --- a/src/color.rs +++ b/src/color.rs @@ -30,7 +30,6 @@ pub const HIGHLIGHT: ThemeColor = 8; /// Highlight color for inactive views (not in focus). pub const HIGHLIGHT_INACTIVE: ThemeColor = 9; - fn load_hex(s: &str) -> i16 { let mut sum = 0; for c in s.chars() { diff --git a/src/printer.rs b/src/printer.rs index b7744ec..2dfa51f 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -69,15 +69,23 @@ impl Printer { /// printer.print((0,0), "This text is highlighted!"); /// }); /// ``` - pub fn with_style<'a, F>(&'a self, style: color::ThemeColor, f: F) + pub fn with_color<'a, F>(&'a self, c: color::ThemeColor, f: F) where F: Fn(&Printer) { - ncurses::attron(ncurses::COLOR_PAIR(style)); + ncurses::attron(ncurses::COLOR_PAIR(c)); f(self); - ncurses::attroff(ncurses::COLOR_PAIR(style)); + ncurses::attroff(ncurses::COLOR_PAIR(c)); ncurses::attron(ncurses::COLOR_PAIR(color::PRIMARY)); } + pub fn with_style<'a, F>(&'a self, style: ncurses::attr_t, f: F) + where F: Fn(&Printer) + { + ncurses::attron(style); + f(self); + ncurses::attroff(style); + } + /// Prints a rectangular box. /// /// # Examples diff --git a/src/view/button.rs b/src/view/button.rs index e5656a3..fbb08c6 100644 --- a/src/view/button.rs +++ b/src/view/button.rs @@ -32,7 +32,7 @@ impl View for Button { let style = if !focused { color::PRIMARY } else { color::HIGHLIGHT }; let x = printer.size.x - 1; - printer.with_style(style, |printer| { + printer.with_color(style, |printer| { printer.print((1,0), &self.label); printer.print((0,0), "<"); printer.print((x,0), ">"); diff --git a/src/view/dialog.rs b/src/view/dialog.rs index 3d135fb..f3fd588 100644 --- a/src/view/dialog.rs +++ b/src/view/dialog.rs @@ -114,7 +114,7 @@ impl View for Dialog { printer.print((x-2,0), "┤ "); printer.print((x+self.title.len(),0), " ├"); - printer.with_style(color::TITLE_PRIMARY, |p| p.print((x,0), &self.title)); + printer.with_color(color::TITLE_PRIMARY, |p| p.print((x,0), &self.title)); } } diff --git a/src/view/edit_view.rs b/src/view/edit_view.rs index f588141..ce03c44 100644 --- a/src/view/edit_view.rs +++ b/src/view/edit_view.rs @@ -59,9 +59,12 @@ fn read_char(ch: i32) -> Option { impl View for EditView { fn draw(&mut self, printer: &Printer, focused: bool) { - let style = if focused { color::HIGHLIGHT } else { color::HIGHLIGHT_INACTIVE }; - printer.with_style(style, |printer| { - printer.print((0,0), &self.content); + // let style = if focused { color::HIGHLIGHT } else { color::HIGHLIGHT_INACTIVE }; + printer.with_color(color::SECONDARY, |printer| { + printer.with_style(ncurses::A_REVERSE(), |printer| { + printer.print((0,0), &self.content); + printer.print_hline((self.content.len(),0), printer.size.x-self.content.len(), '_' as u64); + }); }); } diff --git a/src/view/shadow_view.rs b/src/view/shadow_view.rs index 9b928d9..2599602 100644 --- a/src/view/shadow_view.rs +++ b/src/view/shadow_view.rs @@ -33,7 +33,7 @@ impl ViewWrapper for ShadowView { fn wrap_draw(&mut self, printer: &Printer, focused: bool) { - printer.with_style(color::PRIMARY, |printer| { + printer.with_color(color::PRIMARY, |printer| { // Draw the view background for y in 1..printer.size.y-1 { printer.print_hline((1,y), printer.size.x-2, ' ' as u64); @@ -46,7 +46,7 @@ impl ViewWrapper for ShadowView { let h = printer.size.y-1; let w = printer.size.x-1; - printer.with_style(color::SHADOW, |printer| { + printer.with_color(color::SHADOW, |printer| { printer.print_hline((2,h), w-1, ' ' as u64); printer.print_vline((w,2), h-1, ' ' as u64); }); diff --git a/src/view/text_view.rs b/src/view/text_view.rs index efb8d8b..cf6ad66 100644 --- a/src/view/text_view.rs +++ b/src/view/text_view.rs @@ -186,7 +186,7 @@ impl View for TextView { // Where ratio is ({start or end} / content.height) let start = self.view_height * self.start_line / self.rows.len(); let end = self.view_height * (self.start_line + self.view_height) / self.rows.len(); - printer.with_style( + printer.with_color( if focused { color::HIGHLIGHT } else { color::HIGHLIGHT_INACTIVE }, |printer| { printer.print_vline((printer.size.x-1, start), end-start, ' ' as u64);