Skip to main content

Workspace

Struct Workspace 

Source
pub struct Workspace {
    pub session_name: String,
    pub start_directory: Option<PathBuf>,
    pub environment: Vec<(String, String)>,
    pub options: Vec<(String, String)>,
    pub global_options: Vec<(String, String)>,
    pub shell_command_before: Vec<ShellCommand>,
    pub suppress_history: bool,
    pub windows: Vec<WindowConfig>,
    pub unsupported_keys: Vec<String>,
}
Expand description

One workspace: a session and the windows it should contain.

Fields§

§session_name: String

The session name to create.

§start_directory: Option<PathBuf>

A working directory inherited by windows that do not set their own.

§environment: Vec<(String, String)>

Environment variables to set on the session.

§options: Vec<(String, String)>

Session options to apply once the session exists.

§global_options: Vec<(String, String)>

Global options to apply once the session exists.

§shell_command_before: Vec<ShellCommand>

Commands run in every pane before its own, in order.

§suppress_history: bool

Whether to keep pane commands out of the shell’s history.

A file that does not say reads as true, as in tmuxp.

§windows: Vec<WindowConfig>

The windows to create, in order.

§unsupported_keys: Vec<String>

Keys this parser recognized but does not act on.

Reported rather than dropped, so a caller can say what part of a file was ignored instead of leaving the difference to be discovered later.

Implementations§

Source§

impl Workspace

Source

pub fn to_yaml(&self) -> String

Render this workspace as tmuxp-style YAML.

Emits the keys this crate acts on and nothing else, so a document that came from Self::from_yaml and back may be shorter than it started: what is dropped is what unsupported_keys already named.

§Examples
use tmux_workspace::Workspace;

let workspace = Workspace::from_yaml(
    "
session_name: demo
windows:
  - window_name: editor
    panes: [htop]
",
)?;

// What it writes, it can read.
assert_eq!(Workspace::from_yaml(&workspace.to_yaml())?, workspace);
Source§

impl Workspace

Source

pub fn from_yaml(source: &str) -> Result<Self, ConfigError>

Parse one workspace from tmuxp-style YAML.

This accepts the shape tmuxp uses for the parts a builder needs. A key this parser does not act on is recorded rather than rejected, so a richer tmuxp file still loads; Self::from_yaml_strict refuses one instead.

As tmuxp does, it expands ~ and $NAME or ${NAME} from this process’s environment in names, start directories, and environment and option values, leaving an unset variable as written; commands are typed as written, for the pane’s shell to expand. A start directory that begins with . is relative to the one it inherits, or to the current directory at the top: Self::from_file uses the file’s directory instead.

§Errors

Returns an error when the document is not valid YAML, does not hold exactly one workspace, or is missing session_name. Every error except the document count names the line and column to look at.

§Examples
use tmux_workspace::Workspace;

let workspace = Workspace::from_yaml(
    "
session_name: demo
windows:
  - window_name: editor
    panes:
      - echo one
      - shell_command: echo two
",
)?;

assert_eq!(workspace.session_name, "demo");
assert_eq!(workspace.windows.len(), 1);
assert_eq!(workspace.windows[0].panes.len(), 2);
Source

pub fn from_yaml_strict(source: &str) -> Result<Self, ConfigError>

Parse as Self::from_yaml does, refusing a key that is neither this parser’s own vocabulary nor tmuxp’s, unless it starts with x-.

This is the policy the tmux-workspace command applies to every document it loads.

§Errors

What Self::from_yaml returns, and also an unrecognized key.

§Examples
use tmux_workspace::Workspace;

let error = Workspace::from_yaml_strict("session_name: demo\nwindows: []\nfrobnicate: 1\n")
    .expect_err("an unrecognized key is refused");
assert!(error.to_string().contains("frobnicate"));
Source

pub fn from_file(path: impl AsRef<Path>) -> Result<Self, ConfigError>

Read and parse one workspace file, as tmuxp load does.

Everything Self::from_yaml says holds, except that a start directory beginning with . and inheriting none is relative to the file’s directory. JSON is read too, as the YAML it is a subset of.

§Errors

Returns ConfigError::Read when the file cannot be read, and otherwise what Self::from_yaml returns.

§Examples
use tmux_workspace::Workspace;

let project = tempfile::tempdir()?;
let file = project.path().join(".tmuxp.yaml");
std::fs::write(&file, "session_name: project\nstart_directory: ./\nwindows: []\n")?;

let workspace = Workspace::from_file(&file)?;
assert_eq!(workspace.start_directory.as_deref(), Some(project.path()));
Source

pub fn from_file_strict(path: impl AsRef<Path>) -> Result<Self, ConfigError>

Read as Self::from_file does, under Self::from_yaml_strict’s policy.

§Errors

What Self::from_file returns, and also an unrecognized key.

Trait Implementations§

Source§

impl Clone for Workspace

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Workspace

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Workspace

Source§

impl PartialEq for Workspace

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Workspace

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.