From 2b331c2862e1d297fee170471e6814f34a03b91a Mon Sep 17 00:00:00 2001 From: graelo Date: Sun, 21 Mar 2021 09:20:34 +0100 Subject: [PATCH] refactor: CaptureRegion -> config/tmux_bridge.rs --- src/comm/tmux.rs | 34 +++------------------------------- src/config/tmux_bridge.rs | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/comm/tmux.rs b/src/comm/tmux.rs index 1649af1..1cc1fce 100644 --- a/src/comm/tmux.rs +++ b/src/comm/tmux.rs @@ -1,9 +1,9 @@ -use clap::Clap; use regex::Regex; use std::collections::HashMap; use std::fmt; use std::str::FromStr; +use crate::config::tmux_bridge::CaptureRegion; use crate::error::ParseError; #[derive(Debug, PartialEq)] @@ -108,34 +108,6 @@ impl fmt::Display for PaneId { } } -#[derive(Clap, Debug)] -pub enum CaptureRegion { - /// The entire history. - /// - /// This will end up sending `-S - -E -` to `tmux capture-pane`. - EntireHistory, - /// The visible area. - VisibleArea, - ///// Region from start line to end line - ///// - ///// This works as defined in tmux's docs (order does not matter). - //Region(i32, i32), -} - -impl FromStr for CaptureRegion { - type Err = ParseError; - - fn from_str(s: &str) -> Result { - match s { - "leading" => Ok(CaptureRegion::EntireHistory), - "trailing" => Ok(CaptureRegion::VisibleArea), - _ => Err(ParseError::ExpectedString(String::from( - "entire-history or visible-area", - ))), - } - } -} - /// Returns a list of `Pane` from the current tmux session. pub fn list_panes() -> Result, ParseError> { let args = vec![ @@ -187,8 +159,8 @@ pub fn get_options(prefix: &str) -> Result, ParseError> /// Returns the entire Pane content as a `String`. /// -/// `CaptureRegion` specifies if the visible area is captured, or the entire -/// history. +/// The provided `region` specifies if the visible area is captured, or the +/// entire history. /// /// # TODO /// diff --git a/src/config/tmux_bridge.rs b/src/config/tmux_bridge.rs index 3b6b8d6..d4e329f 100644 --- a/src/config/tmux_bridge.rs +++ b/src/config/tmux_bridge.rs @@ -29,7 +29,7 @@ pub struct Config { /// Capture visible area or entire pane history. #[clap(long, arg_enum, default_value = "visible-area")] - pub capture_region: tmux::CaptureRegion, + pub capture_region: CaptureRegion, /// Name of the copy-to-clipboard executable. /// @@ -64,7 +64,7 @@ impl Config { ) -> Result<(), error::ParseError> { for (name, value) in options { if let "@copyrat-capture" = name.as_ref() { - self.capture_region = tmux::CaptureRegion::from_str(&value)?; + self.capture_region = CaptureRegion::from_str(&value)?; } } @@ -74,3 +74,31 @@ impl Config { Ok(()) } } + +#[derive(Clap, Debug)] +pub enum CaptureRegion { + /// The entire history. + /// + /// This will end up sending `-S - -E -` to `tmux capture-pane`. + EntireHistory, + /// The visible area. + VisibleArea, + ///// Region from start line to end line + ///// + ///// This works as defined in tmux's docs (order does not matter). + //Region(i32, i32), +} + +impl FromStr for CaptureRegion { + type Err = error::ParseError; + + fn from_str(s: &str) -> Result { + match s { + "leading" => Ok(CaptureRegion::EntireHistory), + "trailing" => Ok(CaptureRegion::VisibleArea), + _ => Err(error::ParseError::ExpectedString(String::from( + "entire-history or visible-area", + ))), + } + } +}