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 crate::pane::{ForEachPaneLogicalLine, WithPaneLines};
use rangeset::RangeSet;
use std::ops::Range;
use termwiz::surface::SequenceNo;
use wezterm_term::{Line, StableRowIndex, Terminal};
// Moved to thinkterm-proto together with their lua conversions (which the
// orphan rule ties to the defining crate; mux enables proto's `lua` feature
// to keep them).
pub use thinkterm_proto::{RenderableDimensions, StableCursorPosition};
/// Implements Pane::get_cursor_position for Terminal
pub fn terminal_get_cursor_position(term: &mut Terminal) -> StableCursorPosition {
let pos = term.cursor_pos();
StableCursorPosition {
x: pos.x,
y: term.screen().visible_row_to_stable_row(pos.y),
shape: pos.shape,
visibility: pos.visibility,
}
}
/// Implements Pane::get_dirty_lines for Terminal
pub fn terminal_get_dirty_lines(
term: &mut Terminal,
lines: Range<StableRowIndex>,
seqno: SequenceNo,
) -> RangeSet<StableRowIndex> {
let screen = term.screen();
let lines = screen.get_changed_stable_rows(lines, seqno);
let mut set = RangeSet::new();
for line in lines {
set.add(line);
}
set
}
pub fn terminal_for_each_logical_line_in_stable_range_mut(
term: &mut Terminal,
lines: Range<StableRowIndex>,
for_line: &mut dyn ForEachPaneLogicalLine,
) {
let screen = term.screen_mut();
screen.for_each_logical_line_in_stable_range_mut(lines, |stable_range, lines| {
for_line.with_logical_line_mut(stable_range, lines)
});
}
/// Implements Pane::with_lines for Terminal
pub fn terminal_with_lines<F>(term: &mut Terminal, lines: Range<StableRowIndex>, mut func: F)
where
F: FnMut(StableRowIndex, &[&Line]),
{
let screen = term.screen_mut();
let phys_range = screen.stable_range(&lines);
let first = screen.phys_to_stable_row_index(phys_range.start);
screen.with_phys_lines(phys_range, |lines| func(first, lines));
}
/// Implements Pane::with_lines_mut for Terminal
pub fn terminal_with_lines_mut(
term: &mut Terminal,
lines: Range<StableRowIndex>,
with_lines: &mut dyn WithPaneLines,
) {
let screen = term.screen_mut();
let phys_range = screen.stable_range(&lines);
let first = screen.phys_to_stable_row_index(phys_range.start);
screen.with_phys_lines_mut(phys_range, |lines| with_lines.with_lines_mut(first, lines));
}
/// Implements Pane::get_lines for Terminal
pub fn terminal_get_lines(
term: &mut Terminal,
lines: Range<StableRowIndex>,
) -> (StableRowIndex, Vec<Line>) {
let screen = term.screen_mut();
let phys_range = screen.stable_range(&lines);
let first = screen.phys_to_stable_row_index(phys_range.start);
let lines = screen.lines_in_phys_range(phys_range);
(first, lines)
}
/// Implements Pane::get_screen_lines for Terminal: the screen's bounds and
/// its rows, read in the one hold the caller has of it.
pub fn terminal_get_screen_lines(
term: &mut Terminal,
lines: Range<StableRowIndex>,
) -> (StableRowIndex, Vec<Line>) {
let lines = crate::pane::on_screen(&terminal_get_dimensions(term), lines);
// Not asked: a screen can answer an empty range with a row.
if lines.is_empty() {
return (lines.start, vec![]);
}
terminal_get_lines(term, lines)
}
/// Implements Pane::get_dimensions for Terminal
pub fn terminal_get_dimensions(term: &mut Terminal) -> RenderableDimensions {
let size = term.get_size();
let screen = term.screen();
RenderableDimensions {
cols: screen.physical_cols,
viewport_rows: screen.physical_rows,
scrollback_rows: screen.scrollback_rows(),
physical_top: screen.visible_row_to_stable_row(0),
scrollback_top: screen.phys_to_stable_row_index(0),
dpi: screen.dpi,
pixel_width: size.pixel_width,
pixel_height: size.pixel_height,
reverse_video: term.get_reverse_video(),
}
}