A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
use serde::{Deserialize, Serialize};
use wezterm_term::TerminalSize;
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
pub enum SplitDirection {
Horizontal,
Vertical,
}
/// The size is of the (first, second) child of the split
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
pub struct SplitDirectionAndSize {
pub direction: SplitDirection,
pub first: TerminalSize,
pub second: TerminalSize,
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
pub enum SplitSize {
Cells(usize),
Percent(u8),
}
impl Default for SplitSize {
fn default() -> Self {
Self::Percent(50)
}
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
pub struct SplitRequest {
pub direction: SplitDirection,
/// Whether the newly created item will be in the second part
/// of the split (right/bottom)
pub target_is_second: bool,
/// Split across the top of the tab rather than the active pane
pub top_level: bool,
/// The size of the new item
pub size: SplitSize,
}
impl Default for SplitRequest {
fn default() -> Self {
Self {
direction: SplitDirection::Horizontal,
target_is_second: true,
top_level: false,
size: SplitSize::default(),
}
}
}
impl SplitDirectionAndSize {
// top_of_second and left_of_second were private when this lived in
// mux::tab; they are pub only because mux still calls them from another
// crate now.
pub fn top_of_second(&self) -> usize {
match self.direction {
SplitDirection::Horizontal => 0,
SplitDirection::Vertical => self.first.rows as usize + 1,
}
}
pub fn left_of_second(&self) -> usize {
match self.direction {
SplitDirection::Horizontal => self.first.cols as usize + 1,
SplitDirection::Vertical => 0,
}
}
pub fn width(&self) -> usize {
if self.direction == SplitDirection::Horizontal {
self.first.cols + self.second.cols + 1
} else {
self.first.cols
}
}
pub fn height(&self) -> usize {
if self.direction == SplitDirection::Vertical {
self.first.rows + self.second.rows + 1
} else {
self.first.rows
}
}
pub fn size(&self) -> TerminalSize {
let cell_width = self.first.pixel_width / self.first.cols;
let cell_height = self.first.pixel_height / self.first.rows;
let rows = self.height();
let cols = self.width();
TerminalSize {
rows,
cols,
pixel_height: cell_height * rows,
pixel_width: cell_width * cols,
dpi: self.first.dpi,
}
}
}