From d4fb6c417be11dcd8436c4503c4bdec54b8d0ccb Mon Sep 17 00:00:00 2001 From: graelo Date: Sun, 21 Mar 2021 11:49:17 +0100 Subject: [PATCH] refactor: OutputDestination -> config/tmux_bridge.rs --- src/bin/tmux_copyrat.rs | 5 ++--- src/comm/mod.rs | 4 ---- src/comm/output_destination.rs | 30 ------------------------------ src/config/tmux_bridge.rs | 33 +++++++++++++++++++++++++++++++-- src/lib.rs | 4 ++-- src/{comm => }/tmux.rs | 5 +++++ src/ui/selection.rs | 2 +- src/ui/vc.rs | 2 +- 8 files changed, 42 insertions(+), 43 deletions(-) delete mode 100644 src/comm/mod.rs delete mode 100644 src/comm/output_destination.rs rename src/{comm => }/tmux.rs (98%) diff --git a/src/bin/tmux_copyrat.rs b/src/bin/tmux_copyrat.rs index caf1200..f0cf8da 100644 --- a/src/bin/tmux_copyrat.rs +++ b/src/bin/tmux_copyrat.rs @@ -1,7 +1,6 @@ use copyrat::{ - comm::{tmux, OutputDestination}, - config::tmux_bridge::Config, - error, + config::tmux_bridge::{Config, OutputDestination}, + error, tmux, ui::Selection, }; diff --git a/src/comm/mod.rs b/src/comm/mod.rs deleted file mode 100644 index 288979e..0000000 --- a/src/comm/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod output_destination; -pub mod tmux; - -pub use output_destination::OutputDestination; diff --git a/src/comm/output_destination.rs b/src/comm/output_destination.rs deleted file mode 100644 index 4bbd858..0000000 --- a/src/comm/output_destination.rs +++ /dev/null @@ -1,30 +0,0 @@ -use std::fmt; - -/// Describes the type of buffer the selected should be copied to: either a -/// tmux buffer or the system clipboard. -#[derive(Clone)] -pub enum OutputDestination { - /// The selection will be copied to the tmux buffer. - Tmux, - /// The selection will be copied to the system clipboard. - Clipboard, -} - -impl OutputDestination { - /// Toggle between the variants of `OutputDestination`. - pub fn toggle(&mut self) { - match *self { - Self::Tmux => *self = Self::Clipboard, - Self::Clipboard => *self = Self::Tmux, - } - } -} - -impl fmt::Display for OutputDestination { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::Tmux => write!(f, "tmux buffer"), - Self::Clipboard => write!(f, "clipboard"), - } - } -} diff --git a/src/config/tmux_bridge.rs b/src/config/tmux_bridge.rs index de9cb01..61c5ca1 100644 --- a/src/config/tmux_bridge.rs +++ b/src/config/tmux_bridge.rs @@ -1,13 +1,13 @@ use clap::Clap; use std::collections::HashMap; +use std::fmt; use std::str::FromStr; use super::basic; use crate::{ - comm::tmux, error, textbuf::{alphabet, regexes}, - ui, + tmux, ui, }; /// Main configuration, parsed from command line. @@ -135,3 +135,32 @@ impl FromStr for CaptureRegion { } } } + +/// Describes the type of buffer the selected should be copied to: either a +/// tmux buffer or the system clipboard. +#[derive(Clone)] +pub enum OutputDestination { + /// The selection will be copied to the tmux buffer. + Tmux, + /// The selection will be copied to the system clipboard. + Clipboard, +} + +impl OutputDestination { + /// Toggle between the variants of `OutputDestination`. + pub fn toggle(&mut self) { + match *self { + Self::Tmux => *self = Self::Clipboard, + Self::Clipboard => *self = Self::Tmux, + } + } +} + +impl fmt::Display for OutputDestination { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Tmux => write!(f, "tmux buffer"), + Self::Clipboard => write!(f, "clipboard"), + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 9089912..6f2f041 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ -pub mod comm; pub mod config; pub mod error; pub mod textbuf; +pub mod tmux; pub mod ui; /// Run copyrat on an input string `buffer`, configured by `Opt`. @@ -32,7 +32,7 @@ pub fn run(buffer: String, opt: &config::basic::Config) -> Option }, }; - let default_output_destination = comm::OutputDestination::Tmux; + let default_output_destination = config::tmux_bridge::OutputDestination::Tmux; let selection: Option = { let mut ui = ui::ViewController::new( diff --git a/src/comm/tmux.rs b/src/tmux.rs similarity index 98% rename from src/comm/tmux.rs rename to src/tmux.rs index 1cc1fce..4c96bad 100644 --- a/src/comm/tmux.rs +++ b/src/tmux.rs @@ -1,3 +1,8 @@ +//! This module provides types and functions to use Tmux. +//! +//! The main use cases are running Tmux commands & parsing Tmux panes +//! information. + use regex::Regex; use std::collections::HashMap; use std::fmt; diff --git a/src/ui/selection.rs b/src/ui/selection.rs index efa8ed8..55491b3 100644 --- a/src/ui/selection.rs +++ b/src/ui/selection.rs @@ -1,4 +1,4 @@ -use crate::comm::OutputDestination; +use crate::config::tmux_bridge::OutputDestination; /// Represents the text selected by the user, along with if it was uppercased /// and the output destination (Tmux buffer or Clipboard). diff --git a/src/ui/vc.rs b/src/ui/vc.rs index 8966701..07693c9 100644 --- a/src/ui/vc.rs +++ b/src/ui/vc.rs @@ -8,7 +8,7 @@ use termion::{self, color, cursor, event, style}; use super::colors::UiColors; use super::Selection; use super::{HintAlignment, HintStyle}; -use crate::{comm::OutputDestination, textbuf}; +use crate::{config::tmux_bridge::OutputDestination, textbuf}; pub struct ViewController<'a> { model: &'a mut textbuf::Model<'a>,