diff --git a/src/bin/copyrat.rs b/src/bin/copyrat.rs index 592f19b..011e336 100644 --- a/src/bin/copyrat.rs +++ b/src/bin/copyrat.rs @@ -3,10 +3,10 @@ use std::fs::OpenOptions; use std::io::prelude::*; use std::io::{self, Read}; -use copyrat::{config::CliOpt, run, ui::Selection}; +use copyrat::{config::basic, run, ui::Selection}; fn main() { - let opt = CliOpt::parse(); + let opt = basic::Config::parse(); // Copy the pane contents (piped in via stdin) into a buffer, and split lines. let stdin = io::stdin(); diff --git a/src/bin/tmux_copyrat.rs b/src/bin/tmux_copyrat.rs index 22bc01e..01583f6 100644 --- a/src/bin/tmux_copyrat.rs +++ b/src/bin/tmux_copyrat.rs @@ -3,20 +3,20 @@ use std::collections::HashMap; use copyrat::{ comm::{tmux, OutputDestination}, - config::BridgeOpt, + config::tmux_bridge::Config, error, ui::Selection, }; /// fn main() -> Result<(), error::ParseError> { - let mut opt = BridgeOpt::parse(); + let mut config = Config::parse(); - if !opt.ignore_options_from_tmux { + if !config.ignore_options_from_tmux { let tmux_options: HashMap = tmux::get_options("@copyrat-")?; // Override default values with those coming from tmux. - opt.merge_map(&tmux_options)?; + config.merge_map(&tmux_options)?; } // Identify active pane and capture its content. @@ -27,15 +27,15 @@ fn main() -> Result<(), error::ParseError> { .find(|p| p.is_active) .expect("Exactly one tmux pane should be active in the current window."); - let buffer = tmux::capture_pane(&active_pane, &opt.capture_region)?; + let buffer = tmux::capture_pane(&active_pane, &config.capture_region)?; // We have to dance a little with Panes, because this process' i/o streams // are connected to the pane in the window newly created for us, instead // of the active current pane. - let temp_pane_spec = format!("{}.0", opt.window_name); + let temp_pane_spec = format!("{}.0", config.window_name); tmux::swap_pane_with(&temp_pane_spec)?; - let selection = copyrat::run(buffer, &opt.cli_options); + let selection = copyrat::run(buffer, &config.cli_options); tmux::swap_pane_with(&temp_pane_spec)?; @@ -59,7 +59,7 @@ fn main() -> Result<(), error::ParseError> { } OutputDestination::Clipboard => { duct::cmd!("echo", "-n", &text) - .pipe(duct::cmd!(opt.clipboard_exe)) + .pipe(duct::cmd!(config.clipboard_exe)) .read()?; } } diff --git a/src/config/basic.rs b/src/config/basic.rs index 7f94e4c..c42a117 100644 --- a/src/config/basic.rs +++ b/src/config/basic.rs @@ -12,7 +12,7 @@ use crate::{ /// Main configuration, parsed from command line. #[derive(Clap, Debug)] #[clap(author, about, version)] -pub struct CliOpt { +pub struct Config { /// Alphabet to draw hints from. /// /// Possible values are "{A}", "{A}-homerow", "{A}-left-hand", @@ -108,7 +108,7 @@ fn parse_chars(src: &str) -> Result<(char, char), error::ParseError> { Ok((chars[0], chars[1])) } -impl CliOpt { +impl Config { /// Try parsing provided options, and update self with the valid values. pub fn merge_map( &mut self, diff --git a/src/config/mod.rs b/src/config/mod.rs index eeacadc..774706f 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,5 +1,2 @@ -mod basic; -mod bridge; - -pub use self::basic::{CliOpt, HintStyleArg}; -pub use self::bridge::BridgeOpt; +pub mod basic; +pub mod tmux_bridge; diff --git a/src/config/bridge.rs b/src/config/tmux_bridge.rs similarity index 95% rename from src/config/bridge.rs rename to src/config/tmux_bridge.rs index 80a9561..f07bbe7 100644 --- a/src/config/bridge.rs +++ b/src/config/tmux_bridge.rs @@ -2,14 +2,14 @@ use clap::Clap; use std::collections::HashMap; use std::str::FromStr; -use super::CliOpt; +use super::basic; use crate::comm::tmux; use crate::error; /// Main configuration, parsed from command line. #[derive(Clap, Debug)] #[clap(author, about, version)] -pub struct BridgeOpt { +pub struct Config { /// Don't read options from Tmux. /// /// By default, options formatted like `copyrat-*` are read from tmux. @@ -40,10 +40,10 @@ pub struct BridgeOpt { // Include CLI Options #[clap(flatten)] - pub cli_options: CliOpt, + pub cli_options: basic::Config, } -impl BridgeOpt { +impl Config { /// Try parsing provided options, and update self with the valid values. /// Unknown options are simply ignored. pub fn merge_map( diff --git a/src/lib.rs b/src/lib.rs index 944a499..9089912 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ pub mod ui; /// # Note /// /// Maybe the decision to take ownership of the buffer is a bit bold. -pub fn run(buffer: String, opt: &config::CliOpt) -> Option { +pub fn run(buffer: String, opt: &config::basic::Config) -> Option { let mut model = textbuf::Model::new( &buffer, &opt.alphabet, @@ -22,10 +22,10 @@ pub fn run(buffer: String, opt: &config::CliOpt) -> Option { let hint_style = match &opt.hint_style { None => None, Some(style) => match style { - config::HintStyleArg::Bold => Some(ui::HintStyle::Bold), - config::HintStyleArg::Italic => Some(ui::HintStyle::Italic), - config::HintStyleArg::Underline => Some(ui::HintStyle::Underline), - config::HintStyleArg::Surround => { + config::basic::HintStyleArg::Bold => Some(ui::HintStyle::Bold), + config::basic::HintStyleArg::Italic => Some(ui::HintStyle::Italic), + config::basic::HintStyleArg::Underline => Some(ui::HintStyle::Underline), + config::basic::HintStyleArg::Surround => { let (open, close) = opt.hint_surroundings; Some(ui::HintStyle::Surround(open, close)) }