Crate tmux_interface[−][src]
Expand description
tmux_interface
is a library for communication with TMUX via
CLI.
Description
Main purpose of the tmux_interface
library is to implement simple sending and recieving data
mechanisms for intercommunication with TMUX
only via standard streams (stdin
, stdout
,
stderr
).
Project Structure
This goal can be reached by splitting it into two separate tasks:
-
Providing wrapper functions for tmux subcommands (which is sending data). Wrapper functions are structured like in tmux manual in few next categories:
- Clients and Sessions (
clients_and_sessions
) - Windows and Panes (
windows_and_panes
) - Key Bindings (
key_bindings
) - Options (
options
) - Hooks (
hooks
) - Global and Session Environment (
global_and_session_environment
) - Status Line (
status_line
) - Buffers (
buffers
) - Miscellaneous (
miscellaneous
)
- Clients and Sessions (
Main structure is TmuxCommand
wich has all these wrapper functions implementations.
-
Parsing functions for tmux output as rust structures (which is recieving data). Parsing function are structured by objects they operate with:
Conventions
Library Functions: - Function names and their grouping are inherited from tmux manual
Examples
use crate::tmux_interface::{AttachSession, NewSession, KillSession, TmuxCommand}; // 1. TmuxCommand let tmux = TmuxCommand::new(); tmux.new_session().detached().session_name("new_session_name1").output().unwrap(); tmux.attach_session().target_session("new_session_name1").output().unwrap(); tmux.kill_session().target_session("new_session_name1").output().unwrap(); // 2.a. One-liner NewSession::new().detached().session_name("new_session_name2a").output().unwrap(); AttachSession::new().target_session("new_session_name2a").output().unwrap(); KillSession::new().target_session("new_session_name2a").output().unwrap(); // 2.b. Multi-Liner let mut new_session = NewSession::new(); new_session.detached(); new_session.session_name("new_session_name2b"); new_session.output().unwrap(); let mut attach_session = AttachSession::new(); attach_session.target_session("new_session_name2b"); attach_session.output().unwrap(); let mut kill_session = KillSession::new(); kill_session.target_session("new_session_name2b").output().unwrap();
Examples
Parsing examples:
use crate::tmux_interface::{Sessions, Session, Windows, Window, Pane, Panes, TargetSession, TargetWindowExt}; use crate::tmux_interface::variables::session::session::SESSION_ALL; use crate::tmux_interface::variables::window::window::WINDOW_ALL; use crate::tmux_interface::variables::pane::pane::PANE_ALL; let sessions = Sessions::get(SESSION_ALL).unwrap(); let windows = Windows::get(&TargetSession::Raw("0"), WINDOW_ALL).unwrap(); let panes = Panes::get(&TargetWindowExt::raw("0:1"), PANE_ALL).unwrap();
Examples
Change tmux command line flags, options
use crate::tmux_interface::{TmuxCommand, NewSession, KillSession}; let mut tmux = TmuxCommand::new(); tmux.bin("tmux"); NewSession::from(&tmux).detached().session_name("new_session_name3").output(); KillSession::from(&tmux).target_session("new_session_name3").output();
New session
Examples
Create a new tmux session without any additional parameters (alternative to: tmux new-session
)
use crate::tmux_interface::TmuxCommand; let mut tmux = TmuxCommand::new(); tmux.new_session().output().unwrap();
Examples
Create a new tmux session with some additional parameters (alternative to: tmux new -d -s new_session
)
using builder pattern:
use crate::tmux_interface::{TmuxCommand, TargetSession}; let mut tmux = TmuxCommand::new(); tmux.new_session().detached().session_name("new_session_default").output(); tmux.kill_session().target_session("new_session_default").output();
using std::default::Default
trait:
use crate::tmux_interface::{TmuxCommand, NewSession, TargetSession}; let mut tmux = TmuxCommand::new(); let new_session = tmux.new_session().detached().session_name("new_session_default").output(); tmux.kill_session().target_session("new_session_default").output();
using direct structure modification:
use crate::tmux_interface::{TmuxCommand, NewSession, TargetSession}; let mut tmux = TmuxCommand::new(); let mut new_session = NewSession::new(); new_session.detached(); new_session.session_name("new_session_direct"); new_session.output(); tmux.kill_session().target_session("new_session_direct").output();
Usage
-
Add a dependency in your
Cargo.toml
. Versions below0.1.0
are mostly for development and testing purposes (further versions may have different ABI, use them in your projects on your own risk).[dependencies] tmux_interface = "^0.1.0"
You can also add
features
to your dependencies entry inCargo.toml
, if you want to specify the version of tmux you want to use. Different tmux versions may have incompatible CLI changes. Followingfeatures
are currently supported:tmux_X_X
- tmux latest, default (based on tmux master branch)tmux_2_6
- tmux 2.6 (included in Ubuntu 18.04 LTS Bionic Beaver)
[dependencies] tmux_interface = { version = "^0.1.0", features = ["tmux_2_6"] }
by default
tmux_X_X
is used. It can be removed with--no-default-features
cargo command line option or withdefault-features = false
option inCargo.toml
[dependencies] tmux_interface = { version = "^0.1.0", default-features = false, features = ["tmux_2_6"] }
-
Add extern crate and use in your source file.
extern crate tmux_interface;
-
Use it’s functions
use crate::tmux_interface::{AttachSession, NewSession, TargetPane, TargetSession, TmuxCommand}; let target_session = TargetSession::Raw("session_name").to_string(); let mut tmux = TmuxCommand::new(); let new_session = NewSession::new().detached().session_name("session_name").output(); let attach_session = AttachSession::new().target_session(&target_session).output(); tmux.send_keys().key("exit").key("C-m").output(); tmux.kill_session().target_session(&target_session).output();
Re-exports
pub use crate::options::StatusKeys;
pub use crate::options::Switch;
pub use crate::options::server_options::ServerOptions;
pub use crate::options::server_options::ServerOptionsBuilder;
pub use crate::options::server_options::SetClipboard;
pub use crate::options::server_options::BUFFER_LIMIT;
pub use crate::options::server_options::COMMAND_ALIAS;
pub use crate::options::server_options::DEFAULT_TERMINAL;
pub use crate::options::server_options::ESCAPE_TIME;
pub use crate::options::server_options::EXIT_EMPTY;
pub use crate::options::server_options::EXIT_UNATTACHED;
pub use crate::options::server_options::FOCUS_EVENTS;
pub use crate::options::server_options::HISTORY_FILE;
pub use crate::options::server_options::MESSAGE_LIMIT;
pub use crate::options::server_options::SET_CLIPBOARD;
pub use crate::options::server_options::TERMINAL_OVERRIDES;
pub use crate::options::server_options::SERVER_OPTIONS_ALL;
pub use crate::options::server_options::SERVER_OPTIONS_NONE;
pub use crate::options::session_options::SessionOptions;
pub use crate::options::session_options::SessionOptionsBuilder;
pub use crate::options::session_options::Action;
pub use crate::options::session_options::Activity;
pub use crate::options::session_options::Status;
pub use crate::options::session_options::StatusJustify;
pub use crate::options::session_options::StatusPosition;
pub use crate::options::session_options::ACTIVITY_ACTION;
pub use crate::options::session_options::ASSUME_PASTE_TIME;
pub use crate::options::session_options::BASE_INDEX;
pub use crate::options::session_options::BELL_ACTION;
pub use crate::options::session_options::DEFAULT_COMMAND;
pub use crate::options::session_options::DEFAULT_SHELL;
pub use crate::options::session_options::DESTROY_UNATTACHED;
pub use crate::options::session_options::DETACH_ON_DESTROY;
pub use crate::options::session_options::DISPLAY_PANES_ACTIVE_COLOUR;
pub use crate::options::session_options::DISPLAY_PANES_COLOUR;
pub use crate::options::session_options::DISPLAY_PANES_TIME;
pub use crate::options::session_options::DISPLAY_TIME;
pub use crate::options::session_options::HISTORY_LIMIT;
pub use crate::options::session_options::KEY_TABLE;
pub use crate::options::session_options::LOCK_AFTER_TIME;
pub use crate::options::session_options::LOCK_COMMAND;
pub use crate::options::session_options::MESSAGE_COMMAND_STYLE;
pub use crate::options::session_options::MESSAGE_STYLE;
pub use crate::options::session_options::MOUSE;
pub use crate::options::session_options::PREFIX;
pub use crate::options::session_options::PREFIX2;
pub use crate::options::session_options::RENUMBER_WINDOWS;
pub use crate::options::session_options::REPEAT_TIME;
pub use crate::options::session_options::SET_TITLES;
pub use crate::options::session_options::SET_TITLES_STRING;
pub use crate::options::session_options::SILENCE_ACTION;
pub use crate::options::session_options::STATUS;
pub use crate::options::session_options::STATUS_INTERVAL;
pub use crate::options::session_options::STATUS_JUSTIFY;
pub use crate::options::session_options::STATUS_KEYS;
pub use crate::options::session_options::STATUS_LEFT;
pub use crate::options::session_options::STATUS_LEFT_LENGTH;
pub use crate::options::session_options::STATUS_LEFT_STYLE;
pub use crate::options::session_options::STATUS_POSITION;
pub use crate::options::session_options::STATUS_RIGHT;
pub use crate::options::session_options::STATUS_RIGHT_LENGTH;
pub use crate::options::session_options::STATUS_RIGHT_STYLE;
pub use crate::options::session_options::STATUS_STYLE;
pub use crate::options::session_options::UPDATE_ENVIRONMENT;
pub use crate::options::session_options::USER_KEYS;
pub use crate::options::session_options::VISUAL_ACTIVITY;
pub use crate::options::session_options::VISUAL_BELL;
pub use crate::options::session_options::VISUAL_SILENCE;
pub use crate::options::session_options::WORD_SEPARATORS;
pub use crate::options::session_options::SESSION_OPTIONS_ALL;
pub use crate::options::session_options::SESSION_OPTIONS_NONE;
pub use crate::options::window_options::WindowOptions;
pub use crate::options::window_options::WindowOptionsBuilder;
pub use crate::options::window_options::ClockModeStyle;
pub use crate::options::window_options::PaneBorderStatus;
pub use crate::options::window_options::AGGRESIVE_RESIZE;
pub use crate::options::window_options::ALLOW_RENAME;
pub use crate::options::window_options::ALTERNAME_SCREEN;
pub use crate::options::window_options::AUTOMATIC_RENAME;
pub use crate::options::window_options::AUTOMATIC_RENAME_FORMAT;
pub use crate::options::window_options::CLOCK_MODE_COLOUR;
pub use crate::options::window_options::CLOCK_MODE_STYLE;
pub use crate::options::window_options::FORCE_HEIGHT;
pub use crate::options::window_options::FORCE_WIDTH;
pub use crate::options::window_options::MAIN_PANE_HEIGHT;
pub use crate::options::window_options::MAIN_PANE_WIDTH;
pub use crate::options::window_options::MODE_KEYS;
pub use crate::options::window_options::MODE_STYLE;
pub use crate::options::window_options::MONITOR_ACTIVITY;
pub use crate::options::window_options::MONITOR_BELL;
pub use crate::options::window_options::MONITOR_SILENCE;
pub use crate::options::window_options::OTHER_PANE_HEIGHT;
pub use crate::options::window_options::OTHER_PANE_WIDTH;
pub use crate::options::window_options::PANE_ACTIVE_BORDER_STYLE;
pub use crate::options::window_options::PANE_BASE_INDEX;
pub use crate::options::window_options::PANE_BORDER_FORMAT;
pub use crate::options::window_options::PANE_BORDER_STATUS;
pub use crate::options::window_options::PANE_BORDER_STYLE;
pub use crate::options::window_options::REMAIN_ON_EXIT;
pub use crate::options::window_options::SYNCHRONIZE_PANES;
pub use crate::options::window_options::WINDOW_ACTIVE_STYLE;
pub use crate::options::window_options::WINDOW_STATUS_ACTIVITY_STYLE;
pub use crate::options::window_options::WINDOW_STATUS_BELL_STYLE;
pub use crate::options::window_options::WINDOW_STATUS_CURRENT_FORMAT;
pub use crate::options::window_options::WINDOW_STATUS_CURRENT_STYLE;
pub use crate::options::window_options::WINDOW_STATUS_FORMAT;
pub use crate::options::window_options::WINDOW_STATUS_LAST_STYLE;
pub use crate::options::window_options::WINDOW_STATUS_SEPARATOR;
pub use crate::options::window_options::WINDOW_STATUS_STYLE;
pub use crate::options::window_options::WINDOW_STYLE;
pub use crate::options::window_options::WRAP_SEARCH;
pub use crate::options::window_options::XTERM_KEYS;
pub use crate::options::window_options::WINDOW_OPTIONS_ALL;
pub use crate::options::window_options::WINDOW_OPTIONS_NONE;
pub use self::commands::tmux_command::TmuxCommand;
pub use self::commands::tmux_output::TmuxOutput;
pub use self::commands::buffers::choose_buffer::ChooseBuffer;
pub use self::commands::buffers::clear_history::ClearHistory;
pub use self::commands::buffers::delete_buffer::DeleteBuffer;
pub use self::commands::buffers::list_buffers::ListBuffers;
pub use self::commands::buffers::load_buffer::LoadBuffer;
pub use self::commands::buffers::paste_buffer::PasteBuffer;
pub use self::commands::buffers::save_buffer::SaveBuffer;
pub use self::commands::buffers::set_buffer::SetBuffer;
pub use self::commands::buffers::show_buffer::ShowBuffer;
pub use self::commands::clients_and_sessions::attach_session::AttachSession;
pub use self::commands::clients_and_sessions::detach_client::DetachClient;
pub use self::commands::clients_and_sessions::has_session::HasSession;
pub use self::commands::clients_and_sessions::kill_server::KillServer;
pub use self::commands::clients_and_sessions::kill_session::KillSession;
pub use self::commands::clients_and_sessions::list_clients::ListClients;
pub use self::commands::clients_and_sessions::list_commands::ListCommands;
pub use self::commands::clients_and_sessions::list_sessions::ListSessions;
pub use self::commands::clients_and_sessions::lock_client::LockClient;
pub use self::commands::clients_and_sessions::lock_session::LockSession;
pub use self::commands::clients_and_sessions::new_session::NewSession;
pub use self::commands::clients_and_sessions::refresh_client::RefreshClient;
pub use self::commands::clients_and_sessions::rename_session::RenameSession;
pub use self::commands::clients_and_sessions::show_messages::ShowMessages;
pub use self::commands::clients_and_sessions::source_file::SourceFile;
pub use self::commands::clients_and_sessions::start_server::StartServer;
pub use self::commands::clients_and_sessions::suspend_client::SuspendClient;
pub use self::commands::clients_and_sessions::switch_client::SwitchClient;
pub use self::commands::global_and_session_environment::set_environment::SetEnvironment;
pub use self::commands::global_and_session_environment::show_environment::ShowEnvironment;
pub use self::commands::hooks::set_hook::SetHook;
pub use self::commands::hooks::show_hooks::ShowHooks;
pub use self::commands::key_bindings::bind_key::BindKey;
pub use self::commands::key_bindings::list_keys::ListKeys;
pub use self::commands::key_bindings::send_keys::SendKeys;
pub use self::commands::key_bindings::send_prefix::SendPrefix;
pub use self::commands::key_bindings::unbind_key::UnbindKey;
pub use self::commands::miscellaneous::clock_mode::ClockMode;
pub use self::commands::miscellaneous::if_shell::IfShell;
pub use self::commands::miscellaneous::lock_server::LockServer;
pub use self::commands::miscellaneous::run_shell::RunShell;
pub use self::commands::miscellaneous::wait_for::WaitFor;
pub use self::commands::options::set_option::SetOption;
pub use self::commands::options::set_window_option::SetWindowOption;
pub use self::commands::options::show_options::ShowOptions;
pub use self::commands::options::show_window_options::ShowWindowOptions;
pub use self::commands::status_line::command_prompt::CommandPrompt;
pub use self::commands::status_line::confirm_before::ConfirmBefore;
pub use self::commands::status_line::display_message::DisplayMessage;
pub use self::commands::windows_and_panes::break_pane::BreakPane;
pub use self::commands::windows_and_panes::capture_pane::CapturePane;
pub use self::commands::windows_and_panes::choose_client::ChooseClient;
pub use self::commands::windows_and_panes::choose_tree::ChooseTree;
pub use self::commands::windows_and_panes::copy_mode::CopyMode;
pub use self::commands::windows_and_panes::display_panes::DisplayPanes;
pub use self::commands::windows_and_panes::find_window::FindWindow;
pub use self::commands::windows_and_panes::join_pane::JoinPane;
pub use self::commands::windows_and_panes::kill_pane::KillPane;
pub use self::commands::windows_and_panes::kill_window::KillWindow;
pub use self::commands::windows_and_panes::last_pane::LastPane;
pub use self::commands::windows_and_panes::last_window::LastWindow;
pub use self::commands::windows_and_panes::link_window::LinkWindow;
pub use self::commands::windows_and_panes::list_panes::ListPanes;
pub use self::commands::windows_and_panes::list_windows::ListWindows;
pub use self::commands::windows_and_panes::move_pane::MovePane;
pub use self::commands::windows_and_panes::move_window::MoveWindow;
pub use self::commands::windows_and_panes::new_window::NewWindow;
pub use self::commands::windows_and_panes::next_layout::NextLayout;
pub use self::commands::windows_and_panes::next_window::NextWindow;
pub use self::commands::windows_and_panes::pipe_pane::PipePane;
pub use self::commands::windows_and_panes::previous_layout::PreviousLayout;
pub use self::commands::windows_and_panes::previous_window::PreviousWindow;
pub use self::commands::windows_and_panes::rename_window::RenameWindow;
pub use self::commands::windows_and_panes::resize_pane::ResizePane;
pub use self::commands::windows_and_panes::respawn_pane::RespawnPane;
pub use self::commands::windows_and_panes::respawn_window::RespawnWindow;
pub use self::commands::windows_and_panes::rotate_window::RotateWindow;
pub use self::commands::windows_and_panes::select_layout::SelectLayot;
pub use self::commands::windows_and_panes::select_pane::SelectPane;
pub use self::commands::windows_and_panes::select_window::SelectWindow;
pub use self::commands::windows_and_panes::split_window::SplitWindow;
pub use self::commands::windows_and_panes::swap_pane::SwapPane;
pub use self::commands::windows_and_panes::swap_window::SwapWindow;
pub use self::commands::windows_and_panes::unlink_window::UnlinkWindow;
pub use crate::commands::PaneSize;
pub use crate::target::target_pane::TargetPane;
pub use crate::target::target_pane::TargetPaneExt;
pub use crate::target::target_pane::TargetPaneToken;
pub use crate::target::target_session::TargetSession;
pub use crate::target::target_window::TargetWindow;
pub use crate::target::target_window::TargetWindowExt;
pub use crate::target::target_window::TargetWindowToken;
pub use self::variables::layout::layout_cell::LayoutType;
pub use self::variables::layout::layout::Layout;
pub use self::variables::layout::layout_cell::LayoutCell;
pub use self::variables::layout::layout_checksum::LayoutChecksum;
pub use self::variables::pane::pane::Pane;
pub use self::variables::pane::pane_tabs::PaneTabs;
pub use self::variables::pane::panes::Panes;
pub use self::variables::session::session::Session;
pub use self::variables::session::session_stack::SessionStack;
pub use self::variables::session::sessions::Sessions;
pub use self::variables::window::window::Window;
pub use self::variables::window::window_flag::WindowFlag;
pub use self::variables::window::windows::Windows;
pub use self::version::Version;
pub use self::error::Error;
pub use crate::variables::session::session::SESSION_ACTIVITY;
pub use crate::variables::session::session::SESSION_ALERTS;
pub use crate::variables::session::session::SESSION_ATTACHED;
pub use crate::variables::session::session::SESSION_CREATED;
pub use crate::variables::session::session::SESSION_FORMAT;
pub use crate::variables::session::session::SESSION_GROUP;
pub use crate::variables::session::session::SESSION_GROUPED;
pub use crate::variables::session::session::SESSION_GROUP_LIST;
pub use crate::variables::session::session::SESSION_GROUP_SIZE;
pub use crate::variables::session::session::SESSION_HEIGHT;
pub use crate::variables::session::session::SESSION_ID;
pub use crate::variables::session::session::SESSION_LAST_ATTACHED;
pub use crate::variables::session::session::SESSION_MANY_ATTACHED;
pub use crate::variables::session::session::SESSION_NAME;
pub use crate::variables::session::session::SESSION_STACK;
pub use crate::variables::session::session::SESSION_WIDTH;
pub use crate::variables::session::session::SESSION_WINDOWS;
pub use crate::variables::session::session::SESSION_NONE;
pub use crate::variables::session::session::SESSION_ALL;
pub use crate::variables::window::window::WINDOW_ACTIVE;
pub use crate::variables::window::window::WINDOW_ACTIVITY;
pub use crate::variables::window::window::WINDOW_ACTIVITY_FLAG;
pub use crate::variables::window::window::WINDOW_BELL_FLAG;
pub use crate::variables::window::window::WINDOW_FLAGS;
pub use crate::variables::window::window::WINDOW_FORMAT;
pub use crate::variables::window::window::WINDOW_HEIGHT;
pub use crate::variables::window::window::WINDOW_ID;
pub use crate::variables::window::window::WINDOW_INDEX;
pub use crate::variables::window::window::WINDOW_LAST_FLAG;
pub use crate::variables::window::window::WINDOW_LAYOUT;
pub use crate::variables::window::window::WINDOW_LINKED;
pub use crate::variables::window::window::WINDOW_NAME;
pub use crate::variables::window::window::WINDOW_PANES;
pub use crate::variables::window::window::WINDOW_SILENCE_FLAG;
pub use crate::variables::window::window::WINDOW_STACK_INDEX;
pub use crate::variables::window::window::WINDOW_VISIBLE_LAYOUT;
pub use crate::variables::window::window::WINDOW_WIDTH;
pub use crate::variables::window::window::WINDOW_ZOOMED_FLAG;
pub use crate::variables::window::window::WINDOW_NONE;
pub use crate::variables::window::window::WINDOW_ALL;
pub use crate::variables::pane::pane::PANE_ACTIVE;
pub use crate::variables::pane::pane::PANE_AT_BOTTOM;
pub use crate::variables::pane::pane::PANE_AT_LEFT;
pub use crate::variables::pane::pane::PANE_AT_RIGHT;
pub use crate::variables::pane::pane::PANE_AT_TOP;
pub use crate::variables::pane::pane::PANE_BOTTOM;
pub use crate::variables::pane::pane::PANE_CURRENT_COMMAND;
pub use crate::variables::pane::pane::PANE_CURRENT_PATH;
pub use crate::variables::pane::pane::PANE_DEAD;
pub use crate::variables::pane::pane::PANE_DEAD_STATUS;
pub use crate::variables::pane::pane::PANE_FORMAT;
pub use crate::variables::pane::pane::PANE_HEIGHT;
pub use crate::variables::pane::pane::PANE_ID;
pub use crate::variables::pane::pane::PANE_INDEX;
pub use crate::variables::pane::pane::PANE_INPUT_OFF;
pub use crate::variables::pane::pane::PANE_IN_MODE;
pub use crate::variables::pane::pane::PANE_LEFT;
pub use crate::variables::pane::pane::PANE_MODE;
pub use crate::variables::pane::pane::PANE_PID;
pub use crate::variables::pane::pane::PANE_PIPE;
pub use crate::variables::pane::pane::PANE_RIGHT;
pub use crate::variables::pane::pane::PANE_SEARCH_STRING;
pub use crate::variables::pane::pane::PANE_START_COMMMAND;
pub use crate::variables::pane::pane::PANE_SYNCHRONIZED;
pub use crate::variables::pane::pane::PANE_TABS;
pub use crate::variables::pane::pane::PANE_TITLE;
pub use crate::variables::pane::pane::PANE_TOP;
pub use crate::variables::pane::pane::PANE_TTY;
pub use crate::variables::pane::pane::PANE_WIDTH;
pub use crate::variables::pane::pane::PANE_NONE;
pub use crate::variables::pane::pane::PANE_ALL;