From 863cd2e082aeff5ae6edfdfccc2c4d3daa0b0b31 Mon Sep 17 00:00:00 2001 From: graelo Date: Sun, 21 Mar 2021 15:50:58 +0100 Subject: [PATCH] refactor: tmux_bridge -> extended --- src/bin/tmux_copyrat.rs | 4 ++-- src/config/{tmux_bridge.rs => extended.rs} | 22 +++++++++++++--------- src/config/mod.rs | 2 +- src/lib.rs | 2 +- src/tmux.rs | 2 +- src/ui/selection.rs | 2 +- src/ui/vc.rs | 2 +- 7 files changed, 20 insertions(+), 16 deletions(-) rename src/config/{tmux_bridge.rs => extended.rs} (89%) diff --git a/src/bin/tmux_copyrat.rs b/src/bin/tmux_copyrat.rs index f0cf8da..2c3375d 100644 --- a/src/bin/tmux_copyrat.rs +++ b/src/bin/tmux_copyrat.rs @@ -1,12 +1,12 @@ use copyrat::{ - config::tmux_bridge::{Config, OutputDestination}, + config::extended::{ConfigExt, OutputDestination}, error, tmux, ui::Selection, }; /// fn main() -> Result<(), error::ParseError> { - let config = Config::initialize()?; + let config = ConfigExt::initialize()?; // Identify active pane and capture its content. let panes: Vec = tmux::list_panes()?; diff --git a/src/config/tmux_bridge.rs b/src/config/extended.rs similarity index 89% rename from src/config/tmux_bridge.rs rename to src/config/extended.rs index 61c5ca1..52f077a 100644 --- a/src/config/tmux_bridge.rs +++ b/src/config/extended.rs @@ -10,10 +10,12 @@ use crate::{ tmux, ui, }; -/// Main configuration, parsed from command line. +/// Extended configuration for handling Tmux-specific configuration (options +/// and outputs). This is only used by `tmux-copyrat` and parsed from command +/// line.. #[derive(Clap, Debug)] #[clap(author, about, version)] -pub struct Config { +pub struct ConfigExt { /// Don't read options from Tmux. /// /// By default, options formatted like `copyrat-*` are read from tmux. @@ -47,19 +49,21 @@ pub struct Config { pub basic_config: basic::Config, } -impl Config { - pub fn initialize() -> Result { - let mut config = Config::parse(); +impl ConfigExt { + pub fn initialize() -> Result { + let mut config_ext = ConfigExt::parse(); - if !config.ignore_tmux_options { + if !config_ext.ignore_tmux_options { let tmux_options: HashMap = tmux::get_options("@copyrat-")?; // Override default values with those coming from tmux. - let wrapped = &mut config.basic_config; + let wrapped = &mut config_ext.basic_config; for (name, value) in &tmux_options { match name.as_ref() { - "@copyrat-capture" => config.capture_region = CaptureRegion::from_str(&value)?, + "@copyrat-capture" => { + config_ext.capture_region = CaptureRegion::from_str(&value)? + } "@copyrat-alphabet" => { wrapped.alphabet = alphabet::parse_alphabet(value)?; } @@ -104,7 +108,7 @@ impl Config { } } - Ok(config) + Ok(config_ext) } } diff --git a/src/config/mod.rs b/src/config/mod.rs index 774706f..26919fd 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,2 +1,2 @@ pub mod basic; -pub mod tmux_bridge; +pub mod extended; diff --git a/src/lib.rs b/src/lib.rs index 6f2f041..d7ac72f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,7 @@ pub fn run(buffer: String, opt: &config::basic::Config) -> Option }, }; - let default_output_destination = config::tmux_bridge::OutputDestination::Tmux; + let default_output_destination = config::extended::OutputDestination::Tmux; let selection: Option = { let mut ui = ui::ViewController::new( diff --git a/src/tmux.rs b/src/tmux.rs index 4c96bad..b87375a 100644 --- a/src/tmux.rs +++ b/src/tmux.rs @@ -8,7 +8,7 @@ use std::collections::HashMap; use std::fmt; use std::str::FromStr; -use crate::config::tmux_bridge::CaptureRegion; +use crate::config::extended::CaptureRegion; use crate::error::ParseError; #[derive(Debug, PartialEq)] diff --git a/src/ui/selection.rs b/src/ui/selection.rs index 55491b3..042016a 100644 --- a/src/ui/selection.rs +++ b/src/ui/selection.rs @@ -1,4 +1,4 @@ -use crate::config::tmux_bridge::OutputDestination; +use crate::config::extended::OutputDestination; /// Represents the text selected by the user, along with if it was uppercased /// and the output destination (Tmux buffer or Clipboard). diff --git a/src/ui/vc.rs b/src/ui/vc.rs index 07693c9..1e944fa 100644 --- a/src/ui/vc.rs +++ b/src/ui/vc.rs @@ -8,7 +8,7 @@ use termion::{self, color, cursor, event, style}; use super::colors::UiColors; use super::Selection; use super::{HintAlignment, HintStyle}; -use crate::{config::tmux_bridge::OutputDestination, textbuf}; +use crate::{config::extended::OutputDestination, textbuf}; pub struct ViewController<'a> { model: &'a mut textbuf::Model<'a>,