use super::tmux_interface::*;
use super::tmux_interface_error::TmuxInterfaceError;
use std::process::Output;
#[derive(Default)]
pub struct BreakPane<'a> {
pub detached: Option<bool>,
pub print: Option<bool>,
pub format: Option<&'a str>,
pub window_name: Option<&'a str>,
pub src_pane: Option<&'a str>,
pub dst_window: Option<&'a str>,
}
impl<'a> BreakPane<'a> {
pub fn new() -> BreakPane<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct CapturePane<'a> {
pub alternate_screen: Option<bool>,
pub escape_sequences: Option<bool>,
pub stdout: Option<bool>,
pub pane: Option<bool>,
pub quite: Option<bool>,
pub escape_non_printable: Option<bool>,
pub join: Option<bool>,
pub buffer_name: Option<&'a str>,
pub end_line: Option<&'a str>,
pub start_line: Option<&'a str>,
}
impl<'a> CapturePane<'a> {
pub fn new() -> CapturePane<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct ChooseClient<'a> {
pub without_preview: Option<bool>,
pub zoom: Option<bool>,
pub format: Option<&'a str>,
pub filter: Option<&'a str>,
pub sort_order: Option<&'a str>,
pub target_pane: Option<&'a str>,
pub template: Option<&'a str>,
}
impl<'a> ChooseClient<'a> {
pub fn new() -> ChooseClient<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct ChooseTree<'a> {
pub all: Option<bool>,
pub without_preview: Option<bool>,
pub collapsed_sessions: Option<bool>,
pub collapsed_windows: Option<bool>,
pub zoom: Option<bool>,
pub format: Option<&'a str>,
pub filter: Option<&'a str>,
pub sort_order: Option<&'a str>,
pub target_pane: Option<&'a str>,
pub template: Option<&'a str>,
}
impl<'a> ChooseTree<'a> {
pub fn new() -> ChooseTree<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct FindWindow<'a> {
pub only_visible: Option<bool>,
pub only_name: Option<bool>,
pub only_title: Option<bool>,
pub zoom: Option<bool>,
pub target_pane: Option<&'a str>,
pub match_string: &'a str,
}
impl<'a> FindWindow<'a> {
pub fn new() -> FindWindow<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct JoinPane<'a> {
pub left_above: Option<bool>,
pub detached: Option<bool>,
pub horizontal: Option<bool>,
pub vertical: Option<bool>,
pub size: Option<usize>,
pub percentage: Option<usize>,
pub src_pane: Option<&'a str>,
pub dst_pane: Option<&'a str>,
}
impl<'a> JoinPane<'a> {
pub fn new() -> JoinPane<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct LinkWindow<'a> {
pub add: Option<bool>,
pub detached: Option<bool>,
pub kill: Option<bool>,
pub src_window: Option<&'a str>,
pub dst_window: Option<&'a str>,
}
impl<'a> LinkWindow<'a> {
pub fn new() -> LinkWindow<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct MovePane<'a> {
pub left_above: Option<bool>,
pub detached: Option<bool>,
pub horizontal: Option<bool>,
pub vertical: Option<bool>,
pub size: Option<usize>,
pub percentage: Option<usize>,
pub src_pane: Option<&'a str>,
pub dst_pane: Option<&'a str>,
}
impl<'a> MovePane<'a> {
pub fn new() -> JoinPane<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct MoveWindow<'a> {
pub add: Option<bool>,
pub renumber: Option<bool>,
pub detached: Option<bool>,
pub kill: Option<bool>,
pub src_window: Option<&'a str>,
pub dst_window: Option<&'a str>,
}
impl<'a> MoveWindow<'a> {
pub fn new() -> MoveWindow<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct NewWindow<'a> {
pub add: Option<bool>,
pub detached: Option<bool>,
pub kill: Option<bool>,
pub print: Option<bool>,
pub cwd: Option<&'a str>,
pub format: Option<&'a str>,
pub window_name: Option<&'a str>,
pub target_window: Option<&'a str>,
pub shell_command: Option<&'a str>,
}
impl<'a> NewWindow<'a> {
pub fn new() -> NewWindow<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct ResizePane<'a> {
pub down: Option<bool>,
pub left: Option<bool>,
pub mouse: Option<bool>,
pub right: Option<bool>,
pub up: Option<bool>,
pub zoom: Option<bool>,
pub target_pane: Option<&'a str>,
pub width: Option<usize>,
pub height: Option<usize>,
pub adjustment: Option<&'a str>,
}
impl<'a> ResizePane<'a> {
pub fn new() -> ResizePane<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct ResizeWindow<'a> {
pub smallest: Option<bool>,
pub largest: Option<bool>,
pub down: Option<bool>,
pub left: Option<bool>,
pub right: Option<bool>,
pub up: Option<bool>,
pub target_window: Option<&'a str>,
pub width: Option<usize>,
pub height: Option<usize>,
pub adjustment: Option<&'a str>,
}
impl<'a> ResizeWindow<'a> {
pub fn new() -> ResizeWindow<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct RespawnPane<'a> {
pub kill: Option<bool>,
pub start_directory: Option<&'a str>,
pub environment: Option<&'a str>,
pub target_pane: Option<&'a str>,
pub shell_command: Option<&'a str>,
}
impl<'a> RespawnPane<'a> {
pub fn new() -> RespawnPane<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct RespawnWindow<'a> {
pub kill: Option<bool>,
pub start_directory: Option<&'a str>,
pub environment: Option<&'a str>,
pub target_window: Option<&'a str>,
pub shell_command: Option<&'a str>,
}
impl<'a> RespawnWindow<'a> {
pub fn new() -> RespawnWindow<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct PipePane<'a> {
pub stdout: Option<bool>,
pub stdin: Option<bool>,
pub open: Option<bool>,
pub target_pane: Option<&'a str>,
pub shell_command: Option<&'a str>,
}
impl<'a> PipePane<'a> {
pub fn new() -> PipePane<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct SelectLayot<'a> {
pub spread: Option<bool>,
pub next: Option<bool>,
pub last: Option<bool>,
pub previous: Option<bool>,
pub target_pane: Option<&'a str>,
pub layout_name: Option<&'a str>,
}
impl<'a> SelectLayot<'a> {
pub fn new() -> SelectLayot<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct SelectPane<'a> {
pub down: Option<bool>,
pub disable: Option<bool>,
pub enable: Option<bool>,
pub show_style: Option<bool>,
pub left: Option<bool>,
pub last: Option<bool>,
pub set_marked: Option<bool>,
pub clear_marked: Option<bool>,
pub right: Option<bool>,
pub up: Option<bool>,
pub style: Option<&'a str>,
pub title: Option<&'a str>,
pub target_pane: Option<&'a str>,
}
impl<'a> SelectPane<'a> {
pub fn new() -> SelectPane<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct SelectWindow<'a> {
pub last: Option<bool>,
pub next: Option<bool>,
pub previous: Option<bool>,
pub switch: Option<bool>,
pub target_window: Option<&'a str>
}
impl<'a> SelectWindow<'a> {
pub fn new() -> SelectWindow<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct SplitWindow<'a> {
pub before: Option<bool>,
pub detached: Option<bool>,
pub full: Option<bool>,
pub horizontal: Option<bool>,
pub vertical: Option<bool>,
pub print: Option<bool>,
pub cwd: Option<&'a str>,
pub size: Option<usize>,
pub percentage: Option<usize>,
pub target_pane: Option<&'a str>,
pub shell_command: Option<&'a str>,
pub format: Option<&'a str>,
}
impl<'a> SplitWindow<'a> {
pub fn new() -> SplitWindow<'a> {
Default::default()
}
}
#[derive(Default)]
pub struct SwapPane<'a> {
pub detached: Option<bool>,
pub previous: Option<&'a str>,
pub next: Option<&'a str>,
pub src_pane: Option<&'a str>,
pub dst_pane: Option<&'a str>,
}
impl<'a> SwapPane<'a> {
pub fn new() -> SwapPane<'a> {
Default::default()
}
}
impl<'a> TmuxInterface<'a> {
const COPY_MODE: &'static str = "copy-mode";
const BREAK_PANE: &'static str = "break-pane";
const CAPTURE_PANE: &'static str = "capture-pane";
const CHOOSE_CLIENT: &'static str = "choose-client";
const CHOOSE_TREE: &'static str = "choose-tree";
const DISPLAY_PANES: &'static str = "display-panes";
const FIND_WINDOW: &'static str = "find-window";
const JOIN_PANE: &'static str = "join-pane";
const KILL_PANE: &'static str = "kill-pane";
const KILL_WINDOW: &'static str = "kill-window";
const LAST_PANE: &'static str = "last-pane";
const LAST_WINDOW: &'static str = "last-window";
const LINK_WINDOW: &'static str = "link-window";
const LIST_PANES: &'static str = "list-panes";
const LIST_WINDOWS: &'static str = "list-windows";
const MOVE_PANE: &'static str = "move-pane";
const MOVE_WINDOW: &'static str = "move-window";
const NEW_WINDOW: &'static str = "new-window";
const NEXT_LAYOUT: &'static str = "next-layout";
const NEXT_WINDOW: &'static str = "next-window";
const PIPE_PANE: &'static str = "pipe-pane";
const PREVIOUS_LAYOUT: &'static str = "previous-layout";
const PREVIOUS_WINDOW: &'static str = "previous-window";
const RENAME_WINDOW: &'static str = "rename-window";
const RESIZE_PANE: &'static str = "resize-pane";
const RESIZE_WINDOW: &'static str = "resize-window";
const RESPAWN_PANE: &'static str = "respawn-pane";
const RESPAWN_WINDOW: &'static str = "respawn-window";
const ROTATE_WINDOW: &'static str = "rotate-window";
const SELECT_LAYOUT: &'static str = "select-layout";
const SELECT_PANE: &'static str = "select-pane";
const SELECT_WINDOW: &'static str = "select-window";
const SPLIT_WINDOW: &'static str = "split-window";
const SWAP_PANE: &'static str = "swap-pane";
const SWAP_WINDOW: &'static str = "swap-window";
const UNLINK_WINDOW: &'static str = "unlink-window";
pub fn copy_mode(&self,
mouse_drag: Option<bool>,
bottom_exit: Option<bool>,
page_up: Option<bool>,
target_pane: Option<&str>
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if mouse_drag.unwrap_or(false) { args.push(M_KEY); }
if bottom_exit.unwrap_or(false) { args.push(e_KEY); }
if page_up.unwrap_or(false) { args.push(u_KEY); }
target_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::COPY_MODE, &args)?;
Ok(output)
}
pub fn break_pane(&self, break_pane: &BreakPane) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if break_pane.detached.unwrap_or(false) { args.push(d_KEY); }
if break_pane.print.unwrap_or(false) { args.push(P_KEY); }
break_pane.format.and_then(|s| Some(args.extend_from_slice(&[F_KEY, &s])));
break_pane.window_name.and_then(|s| Some(args.extend_from_slice(&[n_KEY, &s])));
break_pane.src_pane.and_then(|s| Some(args.extend_from_slice(&[s_KEY, &s])));
break_pane.dst_window.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::BREAK_PANE, &args)?;
Ok(output)
}
pub fn capture_pane(&self, capture_pane: &CapturePane) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if capture_pane.alternate_screen.unwrap_or(false) { args.push(a_KEY); }
if capture_pane.escape_sequences.unwrap_or(false) { args.push(e_KEY); }
if capture_pane.stdout.unwrap_or(false) { args.push(p_KEY); }
if capture_pane.pane.unwrap_or(false) { args.push(P_KEY); }
if capture_pane.quite.unwrap_or(false) { args.push(q_KEY); }
if capture_pane.escape_non_printable.unwrap_or(false) { args.push(C_KEY); }
if capture_pane.join.unwrap_or(false) { args.push(J_KEY); }
capture_pane.buffer_name.and_then(|s| Some(args.extend_from_slice(&[b_KEY, &s])));
capture_pane.end_line.and_then(|s| Some(args.extend_from_slice(&[E_KEY, &s])));
capture_pane.start_line.and_then(|s| Some(args.extend_from_slice(&[S_KEY, &s])));
let output = self.subcommand(TmuxInterface::CAPTURE_PANE, &args)?;
Ok(output)
}
pub fn choose_client(&self,
choose_client: &ChooseClient
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if choose_client.without_preview.unwrap_or(false) { args.push(N_KEY); }
if choose_client.zoom.unwrap_or(false) { args.push(Z_KEY); }
choose_client.format.and_then(|s| Some(args.extend_from_slice(&[F_KEY, &s])));
choose_client.filter.and_then(|s| Some(args.extend_from_slice(&[f_KEY, &s])));
choose_client.sort_order.and_then(|s| Some(args.extend_from_slice(&[O_KEY, &s])));
choose_client.target_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
choose_client.template.and_then(|s| Some(args.push(&s)));
let output = self.subcommand(TmuxInterface::CHOOSE_CLIENT, &args)?;
Ok(output)
}
pub fn choose_tree(&self, choose_tree: &ChooseTree) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if choose_tree.all.unwrap_or(false) { args.push(G_KEY); }
if choose_tree.without_preview.unwrap_or(false) { args.push(N_KEY); }
if choose_tree.collapsed_sessions.unwrap_or(false) { args.push(s_KEY); }
if choose_tree.collapsed_windows.unwrap_or(false) { args.push(w_KEY); }
if choose_tree.zoom.unwrap_or(false) { args.push(Z_KEY); }
choose_tree.format.and_then(|s| Some(args.extend_from_slice(&[F_KEY, &s])));
choose_tree.filter.and_then(|s| Some(args.extend_from_slice(&[f_KEY, &s])));
choose_tree.sort_order.and_then(|s| Some(args.extend_from_slice(&[O_KEY, &s])));
choose_tree.target_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
choose_tree.template.and_then(|s| Some(args.push(&s)));
let output = self.subcommand(TmuxInterface::CHOOSE_TREE, &args)?;
Ok(output)
}
pub fn display_panes(&self,
not_block: Option<bool>,
duration: Option<&str>,
target_client: Option<&str>,
template: Option<&str>
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if not_block.unwrap_or(false) { args.push(b_KEY); }
duration.and_then(|s| Some(args.extend_from_slice(&[d_KEY, &s])));
target_client.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
template.and_then(|s| Some(args.push(&s)));
let output = self.subcommand(TmuxInterface::DISPLAY_PANES, &args)?;
Ok(output)
}
pub fn find_window(&self, find_window: &FindWindow) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if find_window.only_visible.unwrap_or(false) { args.push(C_KEY); }
if find_window.only_name.unwrap_or(false) { args.push(N_KEY); }
if find_window.only_title.unwrap_or(false) { args.push(T_KEY); }
if find_window.zoom.unwrap_or(false) { args.push(Z_KEY); }
find_window.target_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
args.push(find_window.match_string);
let output = self.subcommand(TmuxInterface::FIND_WINDOW, &args)?;
Ok(output)
}
pub fn join_pane(&self, join_pane: &JoinPane) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if join_pane.left_above.unwrap_or(false) { args.push(b_KEY); }
if join_pane.detached.unwrap_or(false) { args.push(d_KEY); }
if join_pane.horizontal.unwrap_or(false) { args.push(h_KEY); }
if join_pane.vertical.unwrap_or(false) { args.push(v_KEY); }
let s;
if let Some(size) = join_pane.size {
s = size.to_string();
args.extend_from_slice(&[l_KEY, &s]);
}
let p;
if let Some(percentage) = join_pane.percentage {
p = percentage.to_string();
args.extend_from_slice(&[p_KEY, &p]);
}
join_pane.src_pane.and_then(|s| Some(args.extend_from_slice(&[s_KEY, &s])));
join_pane.dst_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::JOIN_PANE, &args)?;
Ok(output)
}
pub fn kill_pane(&self,
all: Option<bool>,
target_pane: Option<&str>
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if all.unwrap_or(false) { args.push(a_KEY); }
target_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::KILL_PANE, &args)?;
Ok(output)
}
pub fn kill_window(&self,
all: Option<bool>,
target_window: Option<&str>
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if all.unwrap_or(false) { args.push(a_KEY); }
target_window.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::KILL_WINDOW, &args)?;
Ok(output)
}
pub fn last_pane(&self,
disable: Option<bool>,
enable: Option<bool>,
target_window: Option<&str>
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if disable.unwrap_or(false) { args.push(d_KEY); }
if enable.unwrap_or(false) { args.push(e_KEY); }
target_window.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::LAST_PANE, &args)?;
Ok(output)
}
pub fn last_window(&self, target_session: Option<&str>) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
target_session.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::LAST_WINDOW, &args)?;
Ok(output)
}
pub fn link_window(&self, link_window: &LinkWindow) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if link_window.add.unwrap_or(false) { args.push(a_KEY); }
if link_window.detached.unwrap_or(false) { args.push(d_KEY); }
if link_window.kill.unwrap_or(false) { args.push(k_KEY); }
link_window.src_window.and_then(|s| Some(args.extend_from_slice(&[s_KEY, &s])));
link_window.dst_window.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::LINK_WINDOW, &args)?;
Ok(output)
}
pub fn list_panes(&self,
all: bool,
session: bool,
format: Option<&str>,
target: Option<&str>
) -> Result<String, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if all { args.push(a_KEY); }
if session { args.push(s_KEY); }
format.and_then(|s| Some(args.extend_from_slice(&[F_KEY, &s])));
target.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::LIST_PANES, &args)?;
let stdout = String::from_utf8_lossy(&output.stdout.as_slice());
Ok(stdout.to_string())
}
pub fn list_windows(&self,
all: bool,
format: Option<&str>,
target_session: Option<&str>
) -> Result<String, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if all { args.push(a_KEY); }
format.and_then(|s| Some(args.extend_from_slice(&[F_KEY, s])));
target_session.and_then(|s| Some(args.extend_from_slice(&[t_KEY, s])));
let output = self.subcommand(TmuxInterface::LIST_WINDOWS, &args)?;
let stdout = String::from_utf8_lossy(&output.stdout.as_slice());
Ok(stdout.to_string())
}
pub fn move_pane(&self, move_pane: &MovePane) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if move_pane.left_above.unwrap_or(false) { args.push(b_KEY); }
if move_pane.detached.unwrap_or(false) { args.push(d_KEY); }
if move_pane.horizontal.unwrap_or(false) { args.push(h_KEY); }
if move_pane.vertical.unwrap_or(false) { args.push(v_KEY); }
let s;
if let Some(size) = move_pane.size {
s = size.to_string();
args.extend_from_slice(&[l_KEY, &s]);
}
let p;
if let Some(percentage) = move_pane.percentage {
p = percentage.to_string();
args.extend_from_slice(&[p_KEY, &p]);
}
move_pane.src_pane.and_then(|s| Some(args.extend_from_slice(&[s_KEY, &s])));
move_pane.dst_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::MOVE_PANE, &args)?;
Ok(output)
}
pub fn move_window(&self, move_window: &MoveWindow) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if move_window.add.unwrap_or(false) { args.push(a_KEY); }
if move_window.renumber.unwrap_or(false) { args.push(r_KEY); }
if move_window.detached.unwrap_or(false) { args.push(d_KEY); }
if move_window.kill.unwrap_or(false) { args.push(k_KEY); }
move_window.src_window.and_then(|s| Some(args.extend_from_slice(&[s_KEY, &s])));
move_window.dst_window.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::MOVE_WINDOW, &args)?;
Ok(output)
}
pub fn new_window(&self, new_window: NewWindow) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if new_window.add.unwrap_or(false) { args.push(a_KEY); }
if new_window.detached.unwrap_or(false) { args.push(d_KEY); }
if new_window.kill.unwrap_or(false) { args.push(k_KEY); }
if new_window.print.unwrap_or(false) { args.push(P_KEY); }
new_window.cwd.and_then(|s| Some(args.extend_from_slice(&[c_KEY, &s])));
new_window.window_name.and_then(|s| Some(args.extend_from_slice(&[n_KEY, &s])));
new_window.format.and_then(|s| Some(args.extend_from_slice(&[F_KEY, &s])));
new_window.target_window.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
new_window.shell_command.and_then(|s| Some(args.push(&s)));
let output = self.subcommand(TmuxInterface::NEW_WINDOW, &args)?;
Ok(output)
}
pub fn next_layout(&self, target_window: Option<&str>) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
target_window.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::NEXT_LAYOUT, &args)?;
Ok(output)
}
pub fn next_window(&self,
alert: Option<bool>,
target_session: Option<&str>
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if alert.unwrap_or(false) { args.push(a_KEY); }
target_session.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::NEXT_WINDOW, &args)?;
Ok(output)
}
pub fn pipe_pane(&self, pipe_pane: &PipePane) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if pipe_pane.stdout.unwrap_or(false) { args.push(I_KEY); }
if pipe_pane.stdin.unwrap_or(false) { args.push(O_KEY); }
if pipe_pane.open.unwrap_or(false) { args.push(o_KEY); }
pipe_pane.target_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
pipe_pane.shell_command.and_then(|s| Some(args.push(&s)));
let output = self.subcommand(TmuxInterface::PIPE_PANE, &args)?;
Ok(output)
}
pub fn previous_layout(&self,
target_window: Option<&str>
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
target_window.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::PREVIOUS_LAYOUT, &args)?;
Ok(output)
}
pub fn previous_window(&self,
alert: Option<bool>,
target_session: Option<&str>
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if alert.unwrap_or(false) { args.push(a_KEY); }
target_session.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::PREVIOUS_WINDOW, &args)?;
Ok(output)
}
pub fn rename_window(&self,
target_window: Option<&str>,
new_name: &str
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
target_window.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
args.push(new_name);
let output = self.subcommand(TmuxInterface::RENAME_WINDOW, &args)?;
Ok(output)
}
pub fn resize_pane(&self, resize_pane: &ResizePane) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if resize_pane.down.unwrap_or(false) { args.push(D_KEY); }
if resize_pane.left.unwrap_or(false) { args.push(L_KEY); }
if resize_pane.mouse.unwrap_or(false) { args.push(M_KEY); }
if resize_pane.right.unwrap_or(false) { args.push(R_KEY); }
if resize_pane.up.unwrap_or(false) { args.push(U_KEY); }
if resize_pane.zoom.unwrap_or(false) { args.push(Z_KEY); }
resize_pane.target_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let x;
if let Some(width) = resize_pane.width {
x = width.to_string();
args.extend_from_slice(&[x_KEY, &x]);
}
let y;
if let Some(height) = resize_pane.height {
y = height.to_string();
args.extend_from_slice(&[y_KEY, &y]);
}
resize_pane.adjustment.and_then(|s| Some(args.push(s)));
let output = self.subcommand(TmuxInterface::RESIZE_PANE, &args)?;
Ok(output)
}
pub fn resize_window(&self,
resize_window: &ResizeWindow
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if resize_window.smallest.unwrap_or(false) { args.push(a_KEY); }
if resize_window.largest.unwrap_or(false) { args.push(A_KEY); }
if resize_window.down.unwrap_or(false) { args.push(D_KEY); }
if resize_window.left.unwrap_or(false) { args.push(L_KEY); }
if resize_window.right.unwrap_or(false) { args.push(R_KEY); }
if resize_window.up.unwrap_or(false) { args.push(U_KEY); }
resize_window.target_window.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let x;
if let Some(width) = resize_window.width {
x = width.to_string();
args.extend_from_slice(&[x_KEY, &x]);
}
let y;
if let Some(height) = resize_window.height {
y = height.to_string();
args.extend_from_slice(&[y_KEY, &y]);
}
resize_window.adjustment.and_then(|s| Some(args.push(s)));
let output = self.subcommand(TmuxInterface::RESIZE_WINDOW, &args)?;
Ok(output)
}
pub fn respawn_pane(&self, respawn_pane: &RespawnPane) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if respawn_pane.kill.unwrap_or(false) { args.push(k_KEY); }
respawn_pane.start_directory.and_then(|s| Some(args.extend_from_slice(&[c_KEY, &s])));
respawn_pane.environment.and_then(|s| Some(args.extend_from_slice(&[e_KEY, &s])));
respawn_pane.target_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
respawn_pane.shell_command.and_then(|s| Some(args.push(s)));
let output = self.subcommand(TmuxInterface::RESPAWN_PANE, &args)?;
Ok(output)
}
pub fn respawn_window(&self,
respawn_window: &RespawnWindow
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if respawn_window.kill.unwrap_or(false) { args.push(k_KEY); }
respawn_window.start_directory.and_then(|s| Some(args.extend_from_slice(&[c_KEY, &s])));
respawn_window.environment.and_then(|s| Some(args.extend_from_slice(&[e_KEY, &s])));
respawn_window.target_window.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
respawn_window.shell_command.and_then(|s| Some(args.push(s)));
let output = self.subcommand(TmuxInterface::RESPAWN_WINDOW, &args)?;
Ok(output)
}
pub fn rotate_window(&self,
down: Option<bool>,
up: Option<bool>,
target_window: Option<&str>
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if down.unwrap_or(false) { args.push(D_KEY); }
if up.unwrap_or(false) { args.push(U_KEY); }
target_window.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::ROTATE_WINDOW, &args)?;
Ok(output)
}
pub fn select_layout(&self,
select_layout: &SelectLayot
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if select_layout.spread.unwrap_or(false) { args.push(E_KEY); }
if select_layout.next.unwrap_or(false) { args.push(n_KEY); }
if select_layout.last.unwrap_or(false) { args.push(o_KEY); }
if select_layout.previous.unwrap_or(false) { args.push(p_KEY); }
select_layout.target_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
select_layout.layout_name.and_then(|s| Some(args.push(&s)));
let output = self.subcommand(TmuxInterface::SELECT_LAYOUT, &args)?;
Ok(output)
}
pub fn select_pane(&self, select_pane: &SelectPane) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if select_pane.down.unwrap_or(false) { args.push(D_KEY); }
if select_pane.disable.unwrap_or(false) { args.push(d_KEY); }
if select_pane.enable.unwrap_or(false) { args.push(e_KEY); }
if select_pane.show_style.unwrap_or(false) { args.push(g_KEY); }
if select_pane.left.unwrap_or(false) { args.push(L_KEY); }
if select_pane.last.unwrap_or(false) { args.push(l_KEY); }
if select_pane.set_marked.unwrap_or(false) { args.push(M_KEY); }
if select_pane.clear_marked.unwrap_or(false) { args.push(m_KEY); }
if select_pane.right.unwrap_or(false) { args.push(R_KEY); }
if select_pane.up.unwrap_or(false) { args.push(U_KEY); }
select_pane.style.and_then(|s| Some(args.extend_from_slice(&[P_KEY, s])));
select_pane.title.and_then(|s| Some(args.extend_from_slice(&[T_KEY, s])));
select_pane.target_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, s])));
let output = self.subcommand(TmuxInterface::SELECT_PANE, &args)?;
Ok(output)
}
pub fn select_window(&self,
select_window: &SelectWindow
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if select_window.last.unwrap_or(false) { args.push(l_KEY); }
if select_window.next.unwrap_or(false) { args.push(n_KEY); }
if select_window.previous.unwrap_or(false) { args.push(p_KEY); }
if select_window.switch.unwrap_or(false) { args.push(T_KEY); }
select_window.target_window.and_then(|s| Some(args.extend_from_slice(&[t_KEY, s])));
let output = self.subcommand(TmuxInterface::SELECT_WINDOW, &args)?;
Ok(output)
}
pub fn split_window(&self, split_window: &SplitWindow) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if split_window.before.unwrap_or(false) { args.push(b_KEY); }
if split_window.detached.unwrap_or(false) { args.push(d_KEY); }
if split_window.full.unwrap_or(false) { args.push(f_KEY); }
if split_window.horizontal.unwrap_or(false) { args.push(h_KEY); }
if split_window.vertical.unwrap_or(false) { args.push(v_KEY); }
if split_window.print.unwrap_or(false) { args.push(P_KEY); }
split_window.cwd.and_then(|s| Some(args.extend_from_slice(&[c_KEY, &s])));
let s;
if let Some(size) = split_window.size {
s = size.to_string();
args.extend_from_slice(&[l_KEY, &s]);
}
let p;
if let Some(percentage) = split_window.percentage {
p = percentage.to_string();
args.extend_from_slice(&[p_KEY, &p]);
}
split_window.target_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
split_window.shell_command.and_then(|s| Some(args.push(&s)));
split_window.format.and_then(|s| Some(args.extend_from_slice(&[F_KEY, &s])));
let output = self.subcommand(TmuxInterface::SPLIT_WINDOW, &args)?;
Ok(output)
}
pub fn swap_pane(&self, swap_pane: &SwapPane) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if swap_pane.detached.unwrap_or(false) { args.push(d_KEY); }
if swap_pane.detached.unwrap_or(false) { args.push(D_KEY); }
if swap_pane.detached.unwrap_or(false) { args.push(U_KEY); }
swap_pane.src_pane.and_then(|s| Some(args.extend_from_slice(&[s_KEY, &s])));
swap_pane.dst_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::SWAP_PANE, &args)?;
Ok(output)
}
pub fn swap_window(&self,
detached: Option<bool>,
src_window: Option<&str>,
dst_window: Option<&str>
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if detached.unwrap_or(false) { args.push(d_KEY); }
src_window.and_then(|s| Some(args.extend_from_slice(&[s_KEY, &s])));
dst_window.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::SWAP_WINDOW, &args)?;
Ok(output)
}
pub fn unlink_window(&self,
k: Option<bool>,
target_window: Option<&str>
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if k.unwrap_or(false) { args.push(k_KEY); }
target_window.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::UNLINK_WINDOW, &args)?;
Ok(output)
}
}