From 44bf996941552c6caf2fe1298bfb458a3925be6b Mon Sep 17 00:00:00 2001 From: rhysd Date: Mon, 11 Jul 2022 02:48:33 +0900 Subject: [PATCH] separate implementation for highlighting to `src/highlight.rs` --- src/highlight.rs | 166 +++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 2 + src/textarea.rs | 145 ++++------------------------------------- src/util.rs | 8 +++ 4 files changed, 188 insertions(+), 133 deletions(-) create mode 100644 src/highlight.rs create mode 100644 src/util.rs diff --git a/src/highlight.rs b/src/highlight.rs new file mode 100644 index 0000000..8fac916 --- /dev/null +++ b/src/highlight.rs @@ -0,0 +1,166 @@ +use crate::util::{num_digits, spaces}; +use std::borrow::Cow; +use std::cmp::Ordering; +use tui::style::Style; +use tui::text::{Span, Spans}; + +enum Boundary { + Cursor(Style), + #[cfg(feature = "search")] + Search(Style), + End, +} + +impl Boundary { + fn cmp(&self, other: &Boundary) -> 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