refactor: tmux_bridge -> extended

This commit is contained in:
graelo 2021-03-21 15:50:58 +01:00
parent d4fb6c417b
commit 863cd2e082
7 changed files with 20 additions and 16 deletions

View file

@ -1,12 +1,12 @@
use copyrat::{ use copyrat::{
config::tmux_bridge::{Config, OutputDestination}, config::extended::{ConfigExt, OutputDestination},
error, tmux, error, tmux,
ui::Selection, ui::Selection,
}; };
/// ///
fn main() -> Result<(), error::ParseError> { fn main() -> Result<(), error::ParseError> {
let config = Config::initialize()?; let config = ConfigExt::initialize()?;
// Identify active pane and capture its content. // Identify active pane and capture its content.
let panes: Vec<tmux::Pane> = tmux::list_panes()?; let panes: Vec<tmux::Pane> = tmux::list_panes()?;

View file

@ -10,10 +10,12 @@ use crate::{
tmux, ui, 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)] #[derive(Clap, Debug)]
#[clap(author, about, version)] #[clap(author, about, version)]
pub struct Config { pub struct ConfigExt {
/// Don't read options from Tmux. /// Don't read options from Tmux.
/// ///
/// By default, options formatted like `copyrat-*` are read from tmux. /// By default, options formatted like `copyrat-*` are read from tmux.
@ -47,19 +49,21 @@ pub struct Config {
pub basic_config: basic::Config, pub basic_config: basic::Config,
} }
impl Config { impl ConfigExt {
pub fn initialize() -> Result<Config, error::ParseError> { pub fn initialize() -> Result<ConfigExt, error::ParseError> {
let mut config = Config::parse(); let mut config_ext = ConfigExt::parse();
if !config.ignore_tmux_options { if !config_ext.ignore_tmux_options {
let tmux_options: HashMap<String, String> = tmux::get_options("@copyrat-")?; let tmux_options: HashMap<String, String> = tmux::get_options("@copyrat-")?;
// Override default values with those coming from tmux. // 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 { for (name, value) in &tmux_options {
match name.as_ref() { 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" => { "@copyrat-alphabet" => {
wrapped.alphabet = alphabet::parse_alphabet(value)?; wrapped.alphabet = alphabet::parse_alphabet(value)?;
} }
@ -104,7 +108,7 @@ impl Config {
} }
} }
Ok(config) Ok(config_ext)
} }
} }

View file

@ -1,2 +1,2 @@
pub mod basic; pub mod basic;
pub mod tmux_bridge; pub mod extended;

View file

@ -32,7 +32,7 @@ pub fn run(buffer: String, opt: &config::basic::Config) -> Option<ui::Selection>
}, },
}; };
let default_output_destination = config::tmux_bridge::OutputDestination::Tmux; let default_output_destination = config::extended::OutputDestination::Tmux;
let selection: Option<ui::Selection> = { let selection: Option<ui::Selection> = {
let mut ui = ui::ViewController::new( let mut ui = ui::ViewController::new(

View file

@ -8,7 +8,7 @@ use std::collections::HashMap;
use std::fmt; use std::fmt;
use std::str::FromStr; use std::str::FromStr;
use crate::config::tmux_bridge::CaptureRegion; use crate::config::extended::CaptureRegion;
use crate::error::ParseError; use crate::error::ParseError;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]

View file

@ -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 /// Represents the text selected by the user, along with if it was uppercased
/// and the output destination (Tmux buffer or Clipboard). /// and the output destination (Tmux buffer or Clipboard).

View file

@ -8,7 +8,7 @@ use termion::{self, color, cursor, event, style};
use super::colors::UiColors; use super::colors::UiColors;
use super::Selection; use super::Selection;
use super::{HintAlignment, HintStyle}; use super::{HintAlignment, HintStyle};
use crate::{config::tmux_bridge::OutputDestination, textbuf}; use crate::{config::extended::OutputDestination, textbuf};
pub struct ViewController<'a> { pub struct ViewController<'a> {
model: &'a mut textbuf::Model<'a>, model: &'a mut textbuf::Model<'a>,