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: previews, the bell, keep-alive, and the threads view

RoversX7fc4f03bef7a
diff --git a/thinkterm-mobile/src/core.rs b/thinkterm-mobile/src/core.rs
index 50317d13..ee06c7a2 100644
--- a/thinkterm-mobile/src/core.rs
+++ b/thinkterm-mobile/src/core.rs
@@ -140,6 +140,10 @@ pub enum Cmd {
head: (usize, usize),
},
ClearSelection,
+ Preview {
+ pane: usize,
+ rows: usize,
+ },
SelectedText {
reply: Sender<Option<String>>,
},
@@ -515,6 +519,18 @@ impl State {
app.clear_selection();
}
}
+ Cmd::Preview { pane, rows } => {
+ if let Some(app) = self.app.clone() {
+ let notify = Arc::clone(&self.notify);
+ let task = app.preview_lines(pane, rows);
+ let _ = self.pool.spawner().spawn_local(async move {
+ match task.await {
+ Ok(rows) => notify.on_preview(pane as u32, json(&rows)),
+ Err(err) => notify.on_log(format!("preview of pane {pane}: {err:#}")),
+ }
+ });
+ }
+ }
Cmd::SelectedText { reply } => {
let _ = reply.send(self.app.as_ref().and_then(|app| app.selected_text()));
}
@@ -561,6 +577,7 @@ impl State {
};
match name {
"tabs" => json(&app.tabs_view()),
+ "threads" => json(&app.threads_view()),
"sidebar" => json(&app.sidebar_view()),
"navs" => json(&app.navs_view()),
"status" => json(&app.status_view()),
@@ -861,6 +878,10 @@ impl State {
languages: vec![],
});
host.events.set_wake(app.wake());
+ {
+ let platform = Rc::clone(&app.platform);
+ host.events.set_bell(Rc::new(move |_| platform.bell()));
+ }
{
let app = Rc::clone(&app);
link.set_push_handler(Box::new(move |pdu| app.on_push(pdu)));
diff --git a/thinkterm-mobile/src/lib.rs b/thinkterm-mobile/src/lib.rs
index 369d0030..77e9914f 100644
--- a/thinkterm-mobile/src/lib.rs
+++ b/thinkterm-mobile/src/lib.rs
@@ -54,6 +54,11 @@ pub trait Notify: Send + Sync {
/// Something the App publishes for the display layer, keyed: "bg" is
/// the terminal's background as a hex colour, for the chrome around it.
fn on_published(&self, key: String, value: String);
+ /// A pane rang its bell.
+ fn on_bell(&self);
+ /// The last rows of a pane, answering `request_preview`: JSON, a list
+ /// of rows, each a list of `{"text","fg"}` runs (`App::PreviewRow`).
+ fn on_preview(&self, pane: u32, rows: String);
}
/// Rust's `log` output goes to stdout, which the simulator's console shows;
@@ -190,6 +195,7 @@ impl Core {
known_host: Option<String>,
remote_command: String,
device_id: String,
+ keepalive_secs: u32,
font_paths: Vec<String>,
size_pt: f64,
painter: Box<dyn painter::GlyphPainter>,
@@ -211,6 +217,7 @@ impl Core {
auth,
known_host: known_host.filter(|k| !k.is_empty()),
remote_command,
+ keepalive_secs: keepalive_secs as u64,
},
font_paths,
size_pt,
@@ -341,6 +348,11 @@ impl Core {
}
/// The selected text of the focused pane, for the clipboard.
+ /// Ask for the last `rows` rows of any pane; `on_preview` answers.
+ pub fn request_preview(&self, pane: u32, rows: u32) {
+ let _ = self.tx.send(core::Cmd::Preview { pane: pane as usize, rows: rows as usize });
+ }
+
pub fn selected_text(&self) -> Option<String> {
let (reply, ack) = mpsc::channel();
if self.tx.send(core::Cmd::SelectedText { reply }).is_err() {
diff --git a/thinkterm-mobile/src/platform.rs b/thinkterm-mobile/src/platform.rs
index e0c6b2d2..e16acaf4 100644
--- a/thinkterm-mobile/src/platform.rs
+++ b/thinkterm-mobile/src/platform.rs
@@ -217,6 +217,10 @@ impl Platform for MobilePlatform {
fn set_cursor(&self, _cursor: &str) {}
+ fn bell(&self) {
+ self.notify.on_bell();
+ }
+
fn set_ime_anchor(&self, anchor: thinkterm_web::ime::Anchor) {
self.notify
.on_ime_anchor(anchor.left, anchor.top, anchor.width, anchor.height);
diff --git a/thinkterm-mobile/src/ssh.rs b/thinkterm-mobile/src/ssh.rs
index 31f6ab8f..fc287930 100644
--- a/thinkterm-mobile/src/ssh.rs
+++ b/thinkterm-mobile/src/ssh.rs
@@ -40,6 +40,8 @@ pub struct SshParams {
pub known_host: Option<String>,
/// The command to exec; empty means the default proxy invocation.
pub remote_command: String,
+ /// Seconds between keep-alives; 0 sends none.
+ pub keepalive_secs: u64,
}
pub enum Out {
@@ -124,7 +126,7 @@ async fn run(
) -> Result<String> {
let config = Arc::new(client::Config {
inactivity_timeout: None,
- keepalive_interval: Some(Duration::from_secs(15)),
+ keepalive_interval: (params.keepalive_secs > 0).then(|| Duration::from_secs(params.keepalive_secs)),
keepalive_max: 3,
..Default::default()
});