From 9afdcf3db20f258753d905833fc3a9ce73f309b6 Mon Sep 17 00:00:00 2001 From: graelo Date: Fri, 19 Mar 2021 23:29:36 +0100 Subject: [PATCH] refactor: model.rs -> textbuf/model.rs --- src/lib.rs | 4 ++-- src/textbuf/mod.rs | 3 +++ src/{ => textbuf}/model.rs | 0 src/ui/vc.rs | 18 +++++++++--------- 4 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 src/textbuf/mod.rs rename src/{ => textbuf}/model.rs (100%) diff --git a/src/lib.rs b/src/lib.rs index c591c71..a08b072 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,9 +5,9 @@ use std::str::FromStr; pub mod alphabets; pub mod error; -pub mod model; pub mod output_destination; pub mod regexes; +pub mod textbuf; pub mod tmux; pub mod ui; @@ -17,7 +17,7 @@ pub mod ui; /// /// Maybe the decision to take ownership of the buffer is a bit bold. pub fn run(buffer: String, opt: &CliOpt) -> Option { - let mut model = model::Model::new( + let mut model = textbuf::Model::new( &buffer, &opt.alphabet, opt.use_all_patterns, diff --git a/src/textbuf/mod.rs b/src/textbuf/mod.rs new file mode 100644 index 0000000..4dfc15e --- /dev/null +++ b/src/textbuf/mod.rs @@ -0,0 +1,3 @@ +mod model; + +pub use model::{Match, Model}; diff --git a/src/model.rs b/src/textbuf/model.rs similarity index 100% rename from src/model.rs rename to src/textbuf/model.rs diff --git a/src/ui/vc.rs b/src/ui/vc.rs index cab1e37..acba916 100644 --- a/src/ui/vc.rs +++ b/src/ui/vc.rs @@ -10,13 +10,13 @@ use termion::{self, color, cursor, event, style}; use super::colors::UiColors; use super::Selection; use crate::error::ParseError; -use crate::{model, output_destination::OutputDestination}; +use crate::{output_destination::OutputDestination, textbuf}; pub struct ViewController<'a> { - model: &'a mut model::Model<'a>, + model: &'a mut textbuf::Model<'a>, term_width: u16, line_offsets: Vec, - matches: Vec>, + matches: Vec>, lookup_trie: SequenceTrie, focus_index: usize, focus_wrap_around: bool, @@ -28,7 +28,7 @@ pub struct ViewController<'a> { impl<'a> ViewController<'a> { pub fn new( - model: &'a mut model::Model<'a>, + model: &'a mut textbuf::Model<'a>, unique_hint: bool, focus_wrap_around: bool, default_output_destination: OutputDestination, @@ -37,7 +37,7 @@ impl<'a> ViewController<'a> { hint_style: Option, ) -> ViewController<'a> { let matches = model.matches(unique_hint); - let lookup_trie = model::Model::build_lookup_trie(&matches); + let lookup_trie = textbuf::Model::build_lookup_trie(&matches); let focus_index = if model.reverse { matches.len() - 1 } else { 0 }; let (term_width, _) = termion::terminal_size().unwrap_or((80u16, 30u16)); // .expect("Cannot read the terminal size."); @@ -117,7 +117,7 @@ impl<'a> ViewController<'a> { /// their compouding takes less space on screen when printed: for /// instance ´ + e = é. Consequently the hint offset has to be adjusted /// to the left. - fn match_offsets(&self, mat: &model::Match<'a>) -> (usize, usize) { + fn match_offsets(&self, mat: &textbuf::Match<'a>) -> (usize, usize) { let offset_x = { let line = &self.model.lines[mat.y as usize]; let prefix = &line[0..mat.x as usize]; @@ -315,7 +315,7 @@ impl<'a> ViewController<'a> { /// Convenience function that renders both the matched text and its hint, /// if focused. - fn render_match(&self, stdout: &mut dyn io::Write, mat: &model::Match<'a>, focused: bool) { + fn render_match(&self, stdout: &mut dyn io::Write, mat: &textbuf::Match<'a>, focused: bool) { let text = mat.text; let (offset_x, offset_y) = self.match_offsets(mat); @@ -911,7 +911,7 @@ Barcelona https://en.wikipedia.org/wiki/Barcelona - "; let custom_patterns = vec![]; let alphabet = alphabets::Alphabet("abcd".to_string()); let reverse = false; - let mut model = model::Model::new( + let mut model = textbuf::Model::new( content, &alphabet, use_all_patterns, @@ -986,7 +986,7 @@ Barcelona https://en.wikipedia.org/wiki/Barcelona - "; let custom_patterns = vec![]; let alphabet = alphabets::Alphabet("abcd".to_string()); let reverse = true; - let mut model = model::Model::new( + let mut model = textbuf::Model::new( content, &alphabet, use_all_patterns,