refactor: alphabets.rs -> textbuf/alphabet.rs

This commit is contained in:
graelo 2021-03-20 07:46:43 +01:00
parent 7d4d9a8824
commit 2c3c7a5456
5 changed files with 16 additions and 14 deletions

View file

@ -1,9 +1,3 @@
use clap::Clap;
use std::collections::HashMap;
use std::path;
use std::str::FromStr;
pub mod alphabets;
pub mod error;
pub mod output_destination;
pub mod regexes;
@ -11,6 +5,13 @@ pub mod textbuf;
pub mod tmux;
pub mod ui;
use clap::Clap;
use std::collections::HashMap;
use std::path;
use std::str::FromStr;
use crate::textbuf::alphabet;
/// Run copyrat on an input string `buffer`, configured by `Opt`.
///
/// # Note
@ -72,8 +73,8 @@ pub struct CliOpt {
///
/// "qwerty", "dvorak-homerow", "azerty-right-hand".
#[clap(short = 'k', long, default_value = "dvorak",
parse(try_from_str = alphabets::parse_alphabet))]
alphabet: alphabets::Alphabet,
parse(try_from_str = alphabet::parse_alphabet))]
alphabet: alphabet::Alphabet,
/// Use all available regex patterns.
#[clap(short = 'A', long = "--all-patterns")]
@ -172,7 +173,7 @@ impl CliOpt {
for (name, value) in options {
match name.as_ref() {
"@copyrat-alphabet" => {
self.alphabet = alphabets::parse_alphabet(value)?;
self.alphabet = alphabet::parse_alphabet(value)?;
}
"@copyrat-pattern-name" => {
self.named_patterns = vec![regexes::parse_pattern_name(value)?]

View file

@ -1,3 +1,4 @@
pub(crate) mod alphabet;
mod matches;
mod model;
mod raw_match;

View file

@ -3,9 +3,9 @@ use std::collections;
use regex::Regex;
use sequence_trie::SequenceTrie;
use super::alphabet::Alphabet;
use super::matches::Match;
use super::raw_match::RawMatch;
use crate::alphabets::Alphabet;
use crate::regexes::{NamedPattern, EXCLUDE_PATTERNS, PATTERNS};
/// Holds data for the `Ui`.
@ -232,7 +232,7 @@ impl<'a> Model<'a> {
#[cfg(test)]
mod tests {
use super::*;
use crate::alphabets::Alphabet;
use crate::textbuf::alphabet::Alphabet;
#[test]
fn match_reverse() {

View file

@ -656,7 +656,7 @@ enum Event {
#[cfg(test)]
mod tests {
use super::*;
use crate::alphabets;
use crate::textbuf::alphabet;
#[test]
fn test_render_all_lines() {
@ -909,7 +909,7 @@ Barcelona https://en.wikipedia.org/wiki/Barcelona - ";
let use_all_patterns = true;
let named_pat = vec![];
let custom_patterns = vec![];
let alphabet = alphabets::Alphabet("abcd".to_string());
let alphabet = alphabet::Alphabet("abcd".to_string());
let reverse = false;
let mut model = textbuf::Model::new(
content,
@ -984,7 +984,7 @@ Barcelona https://en.wikipedia.org/wiki/Barcelona - ";
let use_all_patterns = true;
let named_pat = vec![];
let custom_patterns = vec![];
let alphabet = alphabets::Alphabet("abcd".to_string());
let alphabet = alphabet::Alphabet("abcd".to_string());
let reverse = true;
let mut model = textbuf::Model::new(
content,