refactor: OutputDestination -> config/tmux_bridge.rs

This commit is contained in:
graelo 2021-03-21 11:49:17 +01:00
parent a26a4a56d8
commit d4fb6c417b
8 changed files with 42 additions and 43 deletions

View file

@ -1,7 +1,6 @@
use copyrat::{ use copyrat::{
comm::{tmux, OutputDestination}, config::tmux_bridge::{Config, OutputDestination},
config::tmux_bridge::Config, error, tmux,
error,
ui::Selection, ui::Selection,
}; };

View file

@ -1,4 +0,0 @@
mod output_destination;
pub mod tmux;
pub use output_destination::OutputDestination;

View file

@ -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"),
}
}
}

View file

@ -1,13 +1,13 @@
use clap::Clap; use clap::Clap;
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt;
use std::str::FromStr; use std::str::FromStr;
use super::basic; use super::basic;
use crate::{ use crate::{
comm::tmux,
error, error,
textbuf::{alphabet, regexes}, textbuf::{alphabet, regexes},
ui, tmux, ui,
}; };
/// Main configuration, parsed from command line. /// 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"),
}
}
}

View file

@ -1,7 +1,7 @@
pub mod comm;
pub mod config; pub mod config;
pub mod error; pub mod error;
pub mod textbuf; pub mod textbuf;
pub mod tmux;
pub mod ui; pub mod ui;
/// Run copyrat on an input string `buffer`, configured by `Opt`. /// Run copyrat on an input string `buffer`, configured by `Opt`.
@ -32,7 +32,7 @@ pub fn run(buffer: String, opt: &config::basic::Config) -> Option<ui::Selection>
}, },
}; };
let default_output_destination = comm::OutputDestination::Tmux; let default_output_destination = config::tmux_bridge::OutputDestination::Tmux;
let selection: Option<ui::Selection> = { let selection: Option<ui::Selection> = {
let mut ui = ui::ViewController::new( let mut ui = ui::ViewController::new(

View file

@ -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 regex::Regex;
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt; use std::fmt;

View file

@ -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 /// Represents the text selected by the user, along with if it was uppercased
/// and the output destination (Tmux buffer or Clipboard). /// and the output destination (Tmux buffer or Clipboard).

View file

@ -8,7 +8,7 @@ use termion::{self, color, cursor, event, style};
use super::colors::UiColors; use super::colors::UiColors;
use super::Selection; use super::Selection;
use super::{HintAlignment, HintStyle}; use super::{HintAlignment, HintStyle};
use crate::{comm::OutputDestination, textbuf}; use crate::{config::tmux_bridge::OutputDestination, textbuf};
pub struct ViewController<'a> { pub struct ViewController<'a> {
model: &'a mut textbuf::Model<'a>, model: &'a mut textbuf::Model<'a>,