diff --git a/src/textarea.rs b/src/textarea.rs index 38247a4..1983c66 100644 --- a/src/textarea.rs +++ b/src/textarea.rs @@ -5,10 +5,11 @@ use crate::word::{find_word_end_forward, find_word_start_backward}; #[cfg(feature = "search")] use regex::Regex; use std::borrow::Cow; +use std::cmp; use std::sync::atomic::{AtomicU16, Ordering}; use tui::buffer::Buffer; use tui::layout::Rect; -use tui::style::{Modifier, Style}; +use tui::style::{Color, Modifier, Style}; use tui::text::{Span, Spans, Text}; use tui::widgets::{Block, Paragraph, Widget}; @@ -17,6 +18,41 @@ fn spaces(size: u8) -> &'static str { &SPACES[..size as usize] } +fn num_digits(i: usize) -> u8 { + f64::log10(i as f64) as u8 + 1 +} + +// Highlight boundary in line +enum Boundary { + Cursor(Style), + #[cfg(feature = "search")] + Search(Style), + End, +} + +impl Boundary { + fn cmp(&self, other: &Boundary) -> cmp::Ordering { + fn rank(b: &Boundary) -> u8 { + match b { + Boundary::Cursor(_) => 2, + #[cfg(feature = "search")] + Boundary::Search(_) => 1, + Boundary::End => 0, + } + } + rank(self).cmp(&rank(other)) + } + + fn style(&self) -> Option