mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-12 16:10:07 +01:00
refactor: model.rs -> textbuf/model.rs
This commit is contained in:
parent
a5e3ed263c
commit
9afdcf3db2
4 changed files with 14 additions and 11 deletions
|
|
@ -5,9 +5,9 @@ use std::str::FromStr;
|
||||||
|
|
||||||
pub mod alphabets;
|
pub mod alphabets;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod model;
|
|
||||||
pub mod output_destination;
|
pub mod output_destination;
|
||||||
pub mod regexes;
|
pub mod regexes;
|
||||||
|
pub mod textbuf;
|
||||||
pub mod tmux;
|
pub mod tmux;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ pub mod ui;
|
||||||
///
|
///
|
||||||
/// Maybe the decision to take ownership of the buffer is a bit bold.
|
/// Maybe the decision to take ownership of the buffer is a bit bold.
|
||||||
pub fn run(buffer: String, opt: &CliOpt) -> Option<ui::Selection> {
|
pub fn run(buffer: String, opt: &CliOpt) -> Option<ui::Selection> {
|
||||||
let mut model = model::Model::new(
|
let mut model = textbuf::Model::new(
|
||||||
&buffer,
|
&buffer,
|
||||||
&opt.alphabet,
|
&opt.alphabet,
|
||||||
opt.use_all_patterns,
|
opt.use_all_patterns,
|
||||||
|
|
|
||||||
3
src/textbuf/mod.rs
Normal file
3
src/textbuf/mod.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
mod model;
|
||||||
|
|
||||||
|
pub use model::{Match, Model};
|
||||||
18
src/ui/vc.rs
18
src/ui/vc.rs
|
|
@ -10,13 +10,13 @@ use termion::{self, color, cursor, event, style};
|
||||||
use super::colors::UiColors;
|
use super::colors::UiColors;
|
||||||
use super::Selection;
|
use super::Selection;
|
||||||
use crate::error::ParseError;
|
use crate::error::ParseError;
|
||||||
use crate::{model, output_destination::OutputDestination};
|
use crate::{output_destination::OutputDestination, textbuf};
|
||||||
|
|
||||||
pub struct ViewController<'a> {
|
pub struct ViewController<'a> {
|
||||||
model: &'a mut model::Model<'a>,
|
model: &'a mut textbuf::Model<'a>,
|
||||||
term_width: u16,
|
term_width: u16,
|
||||||
line_offsets: Vec<usize>,
|
line_offsets: Vec<usize>,
|
||||||
matches: Vec<model::Match<'a>>,
|
matches: Vec<textbuf::Match<'a>>,
|
||||||
lookup_trie: SequenceTrie<char, usize>,
|
lookup_trie: SequenceTrie<char, usize>,
|
||||||
focus_index: usize,
|
focus_index: usize,
|
||||||
focus_wrap_around: bool,
|
focus_wrap_around: bool,
|
||||||
|
|
@ -28,7 +28,7 @@ pub struct ViewController<'a> {
|
||||||
|
|
||||||
impl<'a> ViewController<'a> {
|
impl<'a> ViewController<'a> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
model: &'a mut model::Model<'a>,
|
model: &'a mut textbuf::Model<'a>,
|
||||||
unique_hint: bool,
|
unique_hint: bool,
|
||||||
focus_wrap_around: bool,
|
focus_wrap_around: bool,
|
||||||
default_output_destination: OutputDestination,
|
default_output_destination: OutputDestination,
|
||||||
|
|
@ -37,7 +37,7 @@ impl<'a> ViewController<'a> {
|
||||||
hint_style: Option<HintStyle>,
|
hint_style: Option<HintStyle>,
|
||||||
) -> ViewController<'a> {
|
) -> ViewController<'a> {
|
||||||
let matches = model.matches(unique_hint);
|
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 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.");
|
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
|
/// their compouding takes less space on screen when printed: for
|
||||||
/// instance ´ + e = é. Consequently the hint offset has to be adjusted
|
/// instance ´ + e = é. Consequently the hint offset has to be adjusted
|
||||||
/// to the left.
|
/// 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 offset_x = {
|
||||||
let line = &self.model.lines[mat.y as usize];
|
let line = &self.model.lines[mat.y as usize];
|
||||||
let prefix = &line[0..mat.x 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,
|
/// Convenience function that renders both the matched text and its hint,
|
||||||
/// if focused.
|
/// 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 text = mat.text;
|
||||||
|
|
||||||
let (offset_x, offset_y) = self.match_offsets(mat);
|
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 custom_patterns = vec![];
|
||||||
let alphabet = alphabets::Alphabet("abcd".to_string());
|
let alphabet = alphabets::Alphabet("abcd".to_string());
|
||||||
let reverse = false;
|
let reverse = false;
|
||||||
let mut model = model::Model::new(
|
let mut model = textbuf::Model::new(
|
||||||
content,
|
content,
|
||||||
&alphabet,
|
&alphabet,
|
||||||
use_all_patterns,
|
use_all_patterns,
|
||||||
|
|
@ -986,7 +986,7 @@ Barcelona https://en.wikipedia.org/wiki/Barcelona - ";
|
||||||
let custom_patterns = vec![];
|
let custom_patterns = vec![];
|
||||||
let alphabet = alphabets::Alphabet("abcd".to_string());
|
let alphabet = alphabets::Alphabet("abcd".to_string());
|
||||||
let reverse = true;
|
let reverse = true;
|
||||||
let mut model = model::Model::new(
|
let mut model = textbuf::Model::new(
|
||||||
content,
|
content,
|
||||||
&alphabet,
|
&alphabet,
|
||||||
use_all_patterns,
|
use_all_patterns,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue