mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-12 16:10:07 +01:00
refactor: refactor config
This commit is contained in:
parent
0ee29303c6
commit
d598d5962e
2 changed files with 17 additions and 15 deletions
|
|
@ -1,6 +1,3 @@
|
|||
use clap::Clap;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use copyrat::{
|
||||
comm::{tmux, OutputDestination},
|
||||
config::tmux_bridge::Config,
|
||||
|
|
@ -10,14 +7,7 @@ use copyrat::{
|
|||
|
||||
///
|
||||
fn main() -> Result<(), error::ParseError> {
|
||||
let mut config = Config::parse();
|
||||
|
||||
if !config.ignore_options_from_tmux {
|
||||
let tmux_options: HashMap<String, String> = tmux::get_options("@copyrat-")?;
|
||||
|
||||
// Override default values with those coming from tmux.
|
||||
config.merge_map(&tmux_options)?;
|
||||
}
|
||||
let config = Config::initialize()?;
|
||||
|
||||
// Identify active pane and capture its content.
|
||||
let panes: Vec<tmux::Pane> = tmux::list_panes()?;
|
||||
|
|
@ -35,7 +25,7 @@ fn main() -> Result<(), error::ParseError> {
|
|||
let temp_pane_spec = format!("{}.0", config.window_name);
|
||||
tmux::swap_pane_with(&temp_pane_spec)?;
|
||||
|
||||
let selection = copyrat::run(buffer, &config.cli_options);
|
||||
let selection = copyrat::run(buffer, &config.basic_config);
|
||||
|
||||
tmux::swap_pane_with(&temp_pane_spec)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -38,12 +38,24 @@ pub struct Config {
|
|||
#[clap(long, default_value = "pbcopy")]
|
||||
pub clipboard_exe: String,
|
||||
|
||||
// Include CLI Options
|
||||
// Include fields from the basic config
|
||||
#[clap(flatten)]
|
||||
pub cli_options: basic::Config,
|
||||
pub basic_config: basic::Config,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn initialize() -> Result<Config, error::ParseError> {
|
||||
let mut config = Config::parse();
|
||||
|
||||
if !config.ignore_options_from_tmux {
|
||||
let tmux_options: HashMap<String, String> = tmux::get_options("@copyrat-")?;
|
||||
|
||||
// Override default values with those coming from tmux.
|
||||
config.merge_map(&tmux_options)?;
|
||||
}
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
/// Try parsing provided options, and update self with the valid values.
|
||||
/// Unknown options are simply ignored.
|
||||
pub fn merge_map(
|
||||
|
|
@ -57,7 +69,7 @@ impl Config {
|
|||
}
|
||||
|
||||
// Pass the call to cli_options.
|
||||
self.cli_options.merge_map(options)?;
|
||||
self.basic_config.merge_map(options)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue