mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-12 08:00:08 +01:00
refactor: config names
This commit is contained in:
parent
d558c81183
commit
0ee29303c6
6 changed files with 23 additions and 26 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<String, String> = 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()?;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
10
src/lib.rs
10
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<ui::Selection> {
|
||||
pub fn run(buffer: String, opt: &config::basic::Config) -> Option<ui::Selection> {
|
||||
let mut model = textbuf::Model::new(
|
||||
&buffer,
|
||||
&opt.alphabet,
|
||||
|
|
@ -22,10 +22,10 @@ pub fn run(buffer: String, opt: &config::CliOpt) -> Option<ui::Selection> {
|
|||
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))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue