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
thinkterm-web: size the canvas and the panes for a phone
RoversX52289dde8fe7
diff --git a/thinkterm-web/src/app.rs b/thinkterm-web/src/app.rsindex 7d74d8a7..98243df0 100644--- a/thinkterm-web/src/app.rs+++ b/thinkterm-web/src/app.rs@@ -280,6 +280,9 @@ pub struct Inner {/// The tab the page last claimed on its own, on showing it; see/// `show`. A tab is claimed once per showing, not on every listing.auto_claimed: Option<TabId>,+ /// The page is in its phone shape (`body[data-mobile]`), read at each+ /// resize: the grid is padded differently there.+ mobile: bool,/// The page's display layer, told once per animation frame that/// something it shows changed; it reads the views it wants.on_change: Option<js_sys::Function>,@@ -530,6 +533,7 @@ impl App {tab_layout: None,following: true,auto_claimed: None,+ mobile: false,on_change: None,notify_pending: Rc::new(Cell::new(false)),toast: RefCell::new(None),@@ -2247,18 +2251,44 @@ impl App {crate::navbar::nav_css(cell_css, Self::desktop_cell_css(inner))}+ /// The bar's height as the grid pays for it: whole rows. The bar's+ /// own height is a fraction of a row, and the pane gives up the+ /// rounded-up count; drawing the content a fraction below the bar+ /// left the difference as a blank strip under the last row, on top of+ /// the half-cell pad -- a row and a half of nothing at the bottom of+ /// every pane. The bar is drawn to the rounded height (`nav_views`), so+ /// bar and content meet.fn nav_dev(inner: &Inner) -> f32 {- (Self::nav_css(inner) * inner.dpr) as f32+ Self::nav_rows(inner) as f32 * inner.glyphs.metrics.cell_size.height as f32}/// Where the grid starts in the canvas, in device px: the desktop's/// window padding of a cell left and right and half a cell top and/// bottom.fn pad(inner: &Inner) -> (f32, f32) {- (- inner.glyphs.metrics.cell_size.width as f32,- inner.glyphs.metrics.cell_size.height as f32 / 2.0,- )+ let cw = inner.glyphs.metrics.cell_size.width as f32;+ let ch = inner.glyphs.metrics.cell_size.height as f32;+ if inner.mobile {+ // A phone has no room to give the grid a margin above and+ // below, and a gap under the last row reads as a cut-off+ // prompt: the rows sit flush with the bottom of the canvas,+ // and whatever part of a row the height cannot fit is the gap+ // under the tab row instead, where it reads as a margin.+ let rows = (inner.canvas.height() as f32 / ch.max(1.0)).floor();+ return (cw, inner.canvas.height() as f32 - rows * ch);+ }+ (cw, ch / 2.0)+ }++ /// What the grid's rows cannot use of the canvas's height: the pad+ /// above and below on a desktop, nothing on a phone (the leftover is+ /// the pad there, see `pad`).+ fn pad_y_total(inner: &Inner) -> u32 {+ if inner.mobile {+ 0+ } else {+ (2.0 * Self::pad(inner).1) as u32+ }}/// Rows of a frame the bar takes from the pane.@@ -2281,7 +2311,8 @@ impl App {let pad = Self::pad(inner);let pad_css = (pad.0 as f64 / dpr, pad.1 as f64 / dpr);let width_css = inner.canvas.width() as f64 / dpr;- for (rect, place) in crate::navbar::rects(layout, cell_css, Self::nav_css(inner), pad_css, width_css)+ let nav_rows_css = Self::nav_rows(inner) as f64 * cell_css.1;+ for (rect, place) in crate::navbar::rects(layout, cell_css, nav_rows_css, pad_css, width_css).into_iter().zip(&layout.panes){@@ -4373,10 +4404,14 @@ impl App {inner.glyphs.metrics.cell_size.width as u32,inner.glyphs.metrics.cell_size.height as u32,);+ inner.mobile = web_sys::window()+ .and_then(|w| w.document())+ .and_then(|d| d.body())+ .is_some_and(|body| body.has_attribute("data-mobile"));let pad = Self::pad(&inner);let Some((cols, rows)) = grid_for(dev_w.saturating_sub(2 * pad.0 as u32),- dev_h.saturating_sub(2 * pad.1 as u32),+ dev_h.saturating_sub(Self::pad_y_total(&inner)),cw,ch,) else {diff --git a/thinkterm-web/src/layout.rs b/thinkterm-web/src/layout.rsindex 1eb620b5..633eff65 100644--- a/thinkterm-web/src/layout.rs+++ b/thinkterm-web/src/layout.rs@@ -186,10 +186,29 @@ pub fn with_divider_moved(layout: &TabLayout, idx: usize, cells: isize, nav_rows/// server requires. Near enough to claim pane by pane. `None` when a/// pane would be left without a cell: padding one out would break the/// composition, and the server would refuse the lot.+/// The least a pane keeps when a layout is scaled down to this page: a+/// prompt's worth of columns and a few rows. Scaled in proportion alone, a+/// desktop's 70/46 split lands on a phone as 33 columns beside 21, and a+/// narrower one leaves the smaller pane a strip a few cells wide -- its+/// content unreadable, its bar's buttons pushed off the end. A divider is+/// moved as far as it has to be to give both sides this much, when the+/// grid has it to give.+const MIN_COLS: usize = 20;+const MIN_ROWS: usize = 4;+pub fn scaled(layout: &TabLayout, size: TerminalSize) -> Option<TabLayout> {let (cols, rows) = (size.cols, size.rows);let sx = |c: usize| (c * cols + layout.cols / 2) / layout.cols;let sy = |r: usize| (r * rows + layout.rows / 2) / layout.rows;+ // Dividers, unlike edges, are held away from the grid's ends.+ let sxd = |c: usize| {+ let c = sx(c);+ if cols > 2 * MIN_COLS + 1 { c.clamp(MIN_COLS, cols - 1 - MIN_COLS) } else { c }+ };+ let syd = |r: usize| {+ let r = sy(r);+ if rows > 2 * MIN_ROWS + 1 { r.clamp(MIN_ROWS, rows - 1 - MIN_ROWS) } else { r }+ };let mut scaled = layout.clone();scaled.cols = cols;scaled.rows = rows;@@ -203,18 +222,18 @@ pub fn scaled(layout: &TabLayout, size: TerminalSize) -> Option<TabLayout> {match *d {Divider::Col { col, top, rows: n } if old.top < top + n && old.top + old.rows > top => {if old.left + old.cols == col {- r = sx(col);+ r = sxd(col);}if old.left == col + 1 {- l = sx(col) + 1;+ l = sxd(col) + 1;}}Divider::Row { row, left, cols: n } if old.left < left + n && old.left + old.cols > left => {if old.top + old.rows == row {- b = sy(row);+ b = syd(row);}if old.top == row + 1 {- t = sy(row) + 1;+ t = syd(row) + 1;}}_ => {}@@ -229,13 +248,13 @@ pub fn scaled(layout: &TabLayout, size: TerminalSize) -> Option<TabLayout> {match d {Divider::Col { col, top, rows: n } => {let (t, b) = (sy(*top), sy(*top + *n));- *col = sx(*col);+ *col = sxd(*col);*top = t;*n = b.saturating_sub(t).max(1);}Divider::Row { row, left, cols: n } => {let (l, r) = (sx(*left), sx(*left + *n));- *row = sy(*row);+ *row = syd(*row);*left = l;*n = r.saturating_sub(l).max(1);}diff --git a/thinkterm-web/ui/src/tokens.css b/thinkterm-web/ui/src/tokens.cssindex aaf51f74..abeb1ac3 100644--- a/thinkterm-web/ui/src/tokens.css+++ b/thinkterm-web/ui/src/tokens.css@@ -238,7 +238,10 @@ body[data-side=off]:not([data-mobile]) #side .list { top: var(--tabs); }.nav .cap { display: inline-flex; align-items: center; flex: 0 0 auto; width: 128px; height: 30px; box-sizing: border-box; padding: 0 9px; border-radius: 999px; border: 1px solid transparent; background: var(--wash); color: var(--text2); cursor: default; }.nav .cap.current { background: var(--ctl); border-color: var(--ctl-border); box-shadow: var(--shadow); color: inherit; }.nav .cap:hover:not(.current) { background: var(--ctl-hover); }+/* The buttons are what a narrow pane keeps: the capsules give way first+ (min-width: 0 on .caps), and the bar never lets these shrink or clip. */.nav .acts { display: flex; gap: 2px; margin-left: auto; flex: none; }+.nav .cap { min-width: 0; max-width: 128px; flex: 1 1 auto; }.nav .act svg { width: 13px; height: 13px; }.spin { display: inline-flex; animation: spin .96s steps(12) infinite; }@keyframes spin { to { transform: rotate(360deg); } }@@ -411,7 +414,12 @@ body[data-mobile] #panes {/* Clear of the notch and the rounded corners in landscape, as the tabrow and the drawers already are. */inset: var(--tabs) var(--safe-r) auto var(--safe-l);- width: auto;+ /* Spelled out rather than `auto`: a canvas is a replaced element, and+ for those `width: auto` is the intrinsic width -- the backing store's+ pixel count, which resize() sets from this very box at the device+ pixel ratio. The box then fed itself: 2x too wide on a phone, and+ once the window shrank, whatever width the store had last been. */+ width: calc(100% - var(--safe-l) - var(--safe-r));height: calc(var(--vvh, 100%) - var(--tabs) - var(--keybar));}/* The browser must not pan or zoom the page: every finger on the canvas is