mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-12 08:00:08 +01:00
refactor: tmux_bridge -> extended
This commit is contained in:
parent
d4fb6c417b
commit
863cd2e082
7 changed files with 20 additions and 16 deletions
|
|
@ -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::Pane> = tmux::list_panes()?;
|
||||
|
|
|
|||
|
|
@ -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<Config, error::ParseError> {
|
||||
let mut config = Config::parse();
|
||||
impl ConfigExt {
|
||||
pub fn initialize() -> Result<ConfigExt, error::ParseError> {
|
||||
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-")?;
|
||||
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
pub mod basic;
|
||||
pub mod tmux_bridge;
|
||||
pub mod extended;
|
||||
|
|
|
|||
|
|
@ -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 mut ui = ui::ViewController::new(
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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).
|
||||
|
|
|
|||
|
|
@ -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>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue