Skip to content

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.

mobile: the last of the review's medium findings

RoversX9926a90632fd
diff --git a/android/.gitignore b/android/.gitignore
index 901dd2f1..5d022135 100644
--- a/android/.gitignore
+++ b/android/.gitignore
@@ -2,7 +2,7 @@
app/src/main/java/com/roversx/thinkterm/core/
app/src/main/jniLibs/
app/src/main/assets/*.ttf
-app/src/main/assets/probe_key
+app/src/debug/assets/probe_key
app/src/main/assets/schemes.json
app/src/main/assets/strings.json
.gradle/
diff --git a/android/app/src/main/java/com/roversx/thinkterm/HostsScreen.kt b/android/app/src/main/java/com/roversx/thinkterm/HostsScreen.kt
index 50fb805c..db3b554a 100644
--- a/android/app/src/main/java/com/roversx/thinkterm/HostsScreen.kt
+++ b/android/app/src/main/java/com/roversx/thinkterm/HostsScreen.kt
@@ -85,6 +85,9 @@ fun HostsScreen(store: HostStore, showProbe: Boolean, onOpen: (Host) -> Unit) {
// secret; an empty field on an edit keeps the stored one.
if (secret.isNotEmpty() || store.secret(host.id).isEmpty()) {
store.putSecret(host.id, secret, passphrase)
+ } else if (passphrase != store.passphrase(host.id)) {
+ // Only the passphrase changed: kept with the key it unlocks.
+ store.putSecret(host.id, store.secret(host.id), passphrase)
}
store.upsert(host)
editing = null
diff --git a/android/app/src/main/java/com/roversx/thinkterm/TerminalModel.kt b/android/app/src/main/java/com/roversx/thinkterm/TerminalModel.kt
index 0b7a82cb..63d67ed4 100644
--- a/android/app/src/main/java/com/roversx/thinkterm/TerminalModel.kt
+++ b/android/app/src/main/java/com/roversx/thinkterm/TerminalModel.kt
@@ -442,6 +442,8 @@ class TerminalModel(
core.setSetting("resize-mode", if (settings.resizeMode == "release") "\"release\"" else "\"live\"")
core.setSetting("auto-reconnect", settings.autoReconnect.toString())
core.setSetting("pane-bars", settings.paneBars.toString())
+ // The core's own menus and messages follow the app's language.
+ core.setSetting("language", "\"${L10n.currentTag(settings.language)}\"")
}
// MARK: the log
diff --git a/android/app/src/main/java/com/roversx/thinkterm/TerminalScreen.kt b/android/app/src/main/java/com/roversx/thinkterm/TerminalScreen.kt
index 49651329..fbc0d5c5 100644
--- a/android/app/src/main/java/com/roversx/thinkterm/TerminalScreen.kt
+++ b/android/app/src/main/java/com/roversx/thinkterm/TerminalScreen.kt
@@ -157,7 +157,7 @@ fun TerminalScreen(host: Host, store: HostStore, onBack: () -> Unit) {
listOf(
settings.schemeName, settings.smoothScroll, settings.cursorStyle, settings.cursorBlink,
settings.contrast, settings.resizeMode, settings.autoReconnect, settings.paneBars, settings.fontFamily,
- settings.incognitoKeyboard,
+ settings.incognitoKeyboard, settings.language,
)
}.drop(1).collect { model.settingsChanged() }
}
diff --git a/android/build.sh b/android/build.sh
index c0390b28..a88b0961 100755
--- a/android/build.sh
+++ b/android/build.sh
@@ -34,8 +34,10 @@ echo "== assets"
mkdir -p android/app/src/main/assets
cp assets/fonts/JetBrainsMono-Regular.ttf assets/fonts/FiraCode-Regular.ttf assets/fonts/SymbolsNerdFontMono-Regular.ttf android/app/src/main/assets/
cp thinkterm-web/www/schemes.json ios/Resources/strings.json android/app/src/main/assets/
-# The probe sshd's throwaway key, for the emulator's "This Mac" entry.
-[ -f /tmp/ttp-ssh/userkey ] && cp /tmp/ttp-ssh/userkey android/app/src/main/assets/probe_key || true
+# The probe sshd's throwaway key, for the emulator's "This Mac" entry:
+# a debug asset, so no release build carries it.
+mkdir -p android/app/src/debug/assets
+[ -f /tmp/ttp-ssh/userkey ] && cp /tmp/ttp-ssh/userkey android/app/src/debug/assets/probe_key || true
echo "== gradle"
(cd android && "$GRADLE" --quiet assembleDebug 2>&1 | grep -E "error|warning: unused|BUILD|FAIL" || true)
diff --git a/ios/Sources/TerminalInputView.swift b/ios/Sources/TerminalInputView.swift
index 756455b0..8b48c397 100644
--- a/ios/Sources/TerminalInputView.swift
+++ b/ios/Sources/TerminalInputView.swift
@@ -268,7 +268,9 @@ final class TerminalInputView: UIScrollView, UITextInput, UIGestureRecognizerDel
/// The core changed something on screen: the rows are read again
/// when next asked for.
func screenChanged() {
+ inputDelegate?.textWillChange(self)
screen = nil
+ inputDelegate?.textDidChange(self)
}
private func currentScreen() -> ScreenText? {
@@ -469,10 +471,9 @@ final class TerminalInputView: UIScrollView, UITextInput, UIGestureRecognizerDel
return b.i - a.i
}
- var inputDelegate: UITextInputDelegate? {
- get { nil }
- set {}
- }
+ /// UIKit's own listener for the text changing under it: the native
+ /// selection redraws its handles and highlight when told.
+ weak var inputDelegate: UITextInputDelegate?
var tokenizer: UITextInputTokenizer { UITextInputStringTokenizer(textInput: self) }
diff --git a/ios/Sources/TerminalModel.swift b/ios/Sources/TerminalModel.swift
index 373e8d1c..f583dfff 100644
--- a/ios/Sources/TerminalModel.swift
+++ b/ios/Sources/TerminalModel.swift
@@ -127,6 +127,7 @@ final class TerminalModel: ObservableObject, @unchecked Sendable {
settings.$resizeMode.dropFirst().sink { [weak self] _ in self?.applyTerminalPrefs() }.store(in: &subscriptions)
settings.$autoReconnect.dropFirst().sink { [weak self] _ in self?.applyTerminalPrefs() }.store(in: &subscriptions)
settings.$paneBars.dropFirst().sink { [weak self] _ in self?.applyTerminalPrefs() }.store(in: &subscriptions)
+ settings.$language.dropFirst().sink { [weak self] _ in self?.applyTerminalPrefs() }.store(in: &subscriptions)
// A face is shaped at connect time: the connection is made again.
settings.$fontFamily.dropFirst().removeDuplicates().sink { [weak self] _ in
guard let self, self.connection.hasPrefix("pane ") else { return }
@@ -304,6 +305,8 @@ final class TerminalModel: ObservableObject, @unchecked Sendable {
core.setSetting(key: "resize-mode", value: settings.resizeMode == "release" ? "\"release\"" : "\"live\"")
core.setSetting(key: "auto-reconnect", value: settings.autoReconnect ? "true" : "false")
core.setSetting(key: "pane-bars", value: settings.paneBars ? "true" : "false")
+ // The core's own menus and messages follow the app's language.
+ core.setSetting(key: "language", value: "\"\(L10n.currentTag)\"")
}
/// The tab `by` places along the strip from the current one, shown.
@@ -462,6 +465,9 @@ final class TerminalModel: ObservableObject, @unchecked Sendable {
}
}
+ /// The background took the connection down; the foreground brings it back.
+ private var pausedForBackground = false
+
func detachForBackground() {
detach()
report("background")
@@ -470,7 +476,11 @@ final class TerminalModel: ObservableObject, @unchecked Sendable {
backgroundTask = UIApplication.shared.beginBackgroundTask(withName: "thinkterm-connection") { [weak self] in
self?.endBackgroundTask()
}
- } else if connection.hasPrefix("pane ") {
+ } else if !connection.hasPrefix("idle"), !connection.hasPrefix("disconnected"), !connection.hasPrefix("failed") {
+ // Attached or still on the way: torn down for the background,
+ // and dialled again on the way back -- whatever the status
+ // reads by then.
+ pausedForBackground = true
disconnect()
}
}
@@ -484,7 +494,8 @@ final class TerminalModel: ObservableObject, @unchecked Sendable {
func reattachAfterBackground() {
endBackgroundTask()
- if !settings.keepSessionInBackground, connection.hasPrefix("disconnected") {
+ if pausedForBackground {
+ pausedForBackground = false
connect()
}
guard wantsSurface, generation == 0, let layer, let size = drawableSize(of: layer) else { return }
diff --git a/ios/Sources/TerminalScreen.swift b/ios/Sources/TerminalScreen.swift
index 1de08f95..d4363dae 100644
--- a/ios/Sources/TerminalScreen.swift
+++ b/ios/Sources/TerminalScreen.swift
@@ -406,14 +406,28 @@ struct TerminalScreen: View {
private func openOverview() {
guard !overviewShown else { return }
model.refreshViews()
- cardFrame = nil
overviewShown = true
+ if overviewVisible, let frames = cardFrame {
+ // The cards are still up from a close a moment ago and will
+ // not lay out again: the frames they last reported serve.
+ zoom(into: frames)
+ } else {
+ cardFrame = nil
+ }
overviewVisible = true
// Without a card of its own (no threads, or none current) the
// terminal only fades.
if currentThreadId == nil {
withAnimation(.easeOut(duration: 0.25)) { overviewOpen = true }
}
+ // A card the lazy grid never realises reports nothing; the
+ // overview must not stay invisible for it. After a moment, the
+ // terminal only fades.
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {
+ if overviewShown && !overviewOpen {
+ withAnimation(.easeOut(duration: 0.25)) { overviewOpen = true }
+ }
+ }
}
/// Shrink the terminal into the card's thumbnail: scaled to its
@@ -482,6 +496,8 @@ struct TerminalScreen: View {
withAnimation(.easeOut(duration: 0.1)) { livePreview = false }
withAnimation(.easeOut(duration: 0.15)) { zoomFade = 1 }
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
+ // Opened again already: the zoom in progress is the new one's.
+ guard !overviewShown else { return }
withAnimation(.spring(response: 0.35, dampingFraction: 0.9)) {
overviewOpen = false
zoomScale = 1
@@ -501,9 +517,11 @@ struct TerminalScreen: View {
if !overviewShown {
overviewVisible = false
heroFrames = nil
+ // The cards go with the grid; the next open lays them out
+ // again and hears their frames afresh.
+ cardFrame = nil
}
}
- cardFrame = nil
}
// MARK: the terminal with its overlays
diff --git a/ios/Sources/TreeSheet.swift b/ios/Sources/TreeSheet.swift
index 58cd5f02..3f6d2e53 100644
--- a/ios/Sources/TreeSheet.swift
+++ b/ios/Sources/TreeSheet.swift
@@ -89,8 +89,14 @@ struct OverviewScreen: View {
model.refreshViews()
refreshPreviews()
}
- .onReceive(Timer.publish(every: 2, on: .main, in: .common).autoconnect()) { _ in
- refreshPreviews()
+ .task {
+ // One ticker for the grid's life: a publisher made in `body`
+ // would be made again on every render, and its subscription
+ // with it.
+ while !Task.isCancelled {
+ try? await Task.sleep(nanoseconds: 2_000_000_000)
+ if !Task.isCancelled { refreshPreviews() }
+ }
}
}
diff --git a/thinkterm-mobile/src/core.rs b/thinkterm-mobile/src/core.rs
index 21876312..4fce97c3 100644
--- a/thinkterm-mobile/src/core.rs
+++ b/thinkterm-mobile/src/core.rs
@@ -205,6 +205,9 @@ struct State {
next_generation: u64,
/// One per link made; a network event from an older one is dropped.
link_serial: u64,
+ /// A handshake is on the wire: a surface that comes and goes
+ /// meanwhile must not start a second one over the same lease.
+ attaching: bool,
animating: bool,
stats: Stats,
notify: Arc<dyn Notify>,
@@ -244,6 +247,7 @@ pub fn run(cmd_tx: Sender<Cmd>, rx: Receiver<Cmd>, notify: Box<dyn Notify>) {
target: None,
next_generation: 1,
link_serial: 0,
+ attaching: false,
animating: false,
stats: Stats::default(),
notify,
@@ -666,6 +670,7 @@ impl State {
/// surface, if lent, is dropped: the shell re-attaches it by calling
/// `attach_surface` again, which is what it does on any change anyway.
fn disconnect(&mut self) {
+ self.attaching = false;
if let Some(link) = self.link.take() {
link.shutdown();
}
@@ -786,6 +791,11 @@ impl State {
let (Some(link), Some(fonts)) = (self.link.clone(), self.fonts.clone()) else {
return;
};
+ if self.attaching {
+ // The one in flight attaches to whatever surface is there
+ // when it lands; the App resizes to it then.
+ return;
+ }
if self.gpu.is_none() {
// Not a failure: the surface's arrival attaches.
self.notify.on_log("connected before the surface; attaching when it comes".into());
@@ -832,6 +842,7 @@ impl State {
ssh_auth_sock: None,
};
let tx = self.cmd_tx.clone();
+ self.attaching = true;
let spawned = self.pool.spawner().spawn_local(async move {
let outcome = attach(&link, size, 0, me)
.await
@@ -839,11 +850,13 @@ impl State {
let _ = tx.send(Cmd::Attached(outcome));
});
if let Err(err) = spawned {
+ self.attaching = false;
self.fail(format!("spawning the handshake: {err}"));
}
}
fn on_attached(&mut self, outcome: Result<Attached, String>) {
+ self.attaching = false;
let attached = match outcome {
Ok(attached) => attached,
Err(err) => {
diff --git a/thinkterm-web/src/app.rs b/thinkterm-web/src/app.rs
index 685515ad..34e85229 100644
--- a/thinkterm-web/src/app.rs
+++ b/thinkterm-web/src/app.rs
@@ -326,6 +326,9 @@ pub struct Inner<P: Platform, L: Link> {
/// a tab switch takes its colours from here.
overrides: std::collections::HashMap<PaneId, Option<ColorPalette>>,
click_count: u8,
+ /// The button a press put down, for the moves and the cancel that
+ /// carry no button of their own.
+ held_button: MouseButton,
last_click_ms: f64,
focused: bool,
composing: bool,
@@ -583,6 +586,7 @@ impl<P: Platform, L: Link> App<P, L> {
panel_drag: false,
overrides: std::collections::HashMap::new(),
click_count: 0,
+ held_button: MouseButton::None,
last_click_ms: 0.0,
focused: true,
composing: false,
@@ -1693,13 +1697,26 @@ impl<P: Platform, L: Link> App<P, L> {
// as the divider moves; a page that does not hold the tab
// can only ask the server to grow a pane.
if self.inner.borrow().link.lease().owns_viewport() {
- self.drag_divider_to(step.0, step.2);
+ self.drag_divider_to(step.0, step.2, false);
} else {
self.adjust_divider(step.0, step.1);
}
}
Pointer::Up => {
let was = self.inner.borrow_mut().drag_divider.take();
+ if let Some((idx, _, cells)) = was {
+ // Release mode held every step back: the lift is when
+ // the server hears where the divider ended up.
+ let settle = {
+ let inner = self.inner.borrow();
+ cells != 0
+ && inner.settings.resize_mode == crate::settings::ResizeMode::Release
+ && inner.link.lease().owns_viewport()
+ };
+ if settle {
+ self.drag_divider_to(idx, cells, true);
+ }
+ }
self.inner.borrow_mut().drag_layout = None;
if was.is_some() {
// The held-back report goes out with a fresh listing,
@@ -1869,7 +1886,9 @@ impl<P: Platform, L: Link> App<P, L> {
/// Claim the tab with divider `idx` moved `cells` from where the drag
/// began (right/down positive): every pane touching the divider along
/// its extent gives or takes the cells, none below one content row.
- fn drag_divider_to(self: &Rc<Self>, idx: usize, cells: isize) {
+ /// `settle` is the lift of the finger: in Release mode the only step
+ /// the server hears.
+ fn drag_divider_to(self: &Rc<Self>, idx: usize, cells: isize, settle: bool) {
let (link, tab_id) = {
let inner = self.inner.borrow();
let Some(layout) = inner.drag_layout.as_ref() else {
@@ -1895,7 +1914,7 @@ impl<P: Platform, L: Link> App<P, L> {
inner.divider_claim_next = Some((idx, cells));
return;
}
- if inner.settings.resize_mode == crate::settings::ResizeMode::Release {
+ if inner.settings.resize_mode == crate::settings::ResizeMode::Release && !settle {
// The picture moves; the server hears when the finger lifts.
return;
}
@@ -1913,7 +1932,7 @@ impl<P: Platform, L: Link> App<P, L> {
inner.divider_claim_next.take().filter(|_| inner.drag_divider.is_some())
};
match next {
- Some((idx, cells)) => app.drag_divider_to(idx, cells),
+ Some((idx, cells)) => app.drag_divider_to(idx, cells, false),
None => app.refresh_layout(),
}
});
@@ -2196,8 +2215,14 @@ impl<P: Platform, L: Link> App<P, L> {
0 => MouseButton::Left,
1 => MouseButton::Middle,
2 => MouseButton::Right,
+ 255 => inner.held_button,
_ => MouseButton::None,
};
+ match what {
+ Pointer::Down => inner.held_button = button,
+ Pointer::Up => inner.held_button = MouseButton::None,
+ Pointer::Move => {}
+ }
// A program that asked for the mouse gets it, unless Shift holds
// the event back for the page's own selection.
@@ -3787,7 +3812,15 @@ impl<P: Platform, L: Link> App<P, L> {
crate::tree::Row::Thread(t) if t.id == id => Some(menu::for_thread(&t)),
_ => None,
}),
- "project" => Some(menu::for_project(id, inner.tree.live_panes_of_project(id).len())),
+ "project" => Some(menu::for_project(id, inner.tree.live_panes_of_project(id).len())).map(|items| {
+ if inner.platform.is_mobile() {
+ // The phone's sidebar folds on its own; the core's
+ // fold would only hide the threads from the overview.
+ items.into_iter().filter(|item| !item.id.starts_with("collapse")).collect()
+ } else {
+ items
+ }
+ }),
"archived-project" => Some(menu::for_archived_project(id, inner.tree.thread_count_of_project(id))),
"sidebar-options" => Some(menu::for_sidebar_options(inner.tree.archived_open, inner.tree.archived_count())),
"space" => Some(menu::for_space(&inner.tree.spaces())),
diff --git a/thinkterm-web/src/graphics_check.rs b/thinkterm-web/src/graphics_check.rs
index 5d2a6227..a098159b 100644
--- a/thinkterm-web/src/graphics_check.rs
+++ b/thinkterm-web/src/graphics_check.rs
@@ -119,6 +119,9 @@ async fn run(names: Vec<String>, fonts: Vec<js_sys::Uint8Array>, size: f64) -> R
clip: (w as f32, h as f32),
hsv: None,
draw_cursor: true,
+ cursor_shape: None,
+ cursor_hidden: false,
+ min_contrast: 0.0,
},
)?;
}
diff --git a/thinkterm-web/src/input.rs b/thinkterm-web/src/input.rs
index 2b0b14c2..972b0f2a 100644
--- a/thinkterm-web/src/input.rs
+++ b/thinkterm-web/src/input.rs
@@ -53,7 +53,9 @@ fn pointer_input(ev: &PointerEvent) -> PointerInput {
PointerInput {
x: ev.client_x() as f64,
y: ev.client_y() as f64,
- button: ev.button().clamp(0, 255) as u8,
+ // Pointer Events give -1 on a move or a cancel: no button of its
+ // own. 255 says so; the App fills in the one held.
+ button: if ev.button() < 0 { 255 } else { ev.button().min(255) as u8 },
buttons_down: ev.buttons() != 0,
mods: mouse_modifiers(ev),
}