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 moving card carries its border, and a tap returns into its card

RoversX64ab5169a467
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 6e53f13e..cb7d410c 100644
--- a/android/app/src/main/java/com/roversx/thinkterm/TerminalScreen.kt
+++ b/android/app/src/main/java/com/roversx/thinkterm/TerminalScreen.kt
@@ -10,7 +10,6 @@ import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.gestures.detectDragGestures
-import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.gestures.detectTransformGestures
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
@@ -138,6 +137,8 @@ fun TerminalScreen(host: Host, store: HostStore, onBack: () -> Unit) {
var livePreview by remember { mutableStateOf(false) }
val overviewOpen = overviewShown && zoom.value > 0f
var zoomTarget by remember { mutableStateOf<CardFrames?>(null) }
+ /// The thread whose card the terminal is moving into or out of.
+ var heroThread by remember { mutableStateOf<ThreadView?>(null) }
val keyboardUp = WindowInsets.ime.getBottom(density) > 0
val twoLevel = settings.tabBarLevels == "two" && !(model.threads?.threads.isNullOrEmpty())
@@ -174,11 +175,18 @@ fun TerminalScreen(host: Host, store: HostStore, onBack: () -> Unit) {
onDispose { lifecycle.removeObserver(observer) }
}
- fun closeOverview() {
+ /// Back to the terminal. A tapped card hands over its thread and its
+ /// frames: the terminal grows out of that card, not the one it came
+ /// from.
+ fun closeOverview(picked: ThreadView? = null, frames: CardFrames? = null) {
if (!overviewShown) return
+ if (picked != null && frames != null) {
+ heroThread = picked
+ zoomTarget = frames
+ }
scope.launch {
livePreview = false
- hostView?.visibility = android.view.View.VISIBLE
+ hostView?.showPicture(true)
fade.animateTo(0f, tween(150))
zoom.animateTo(0f, spring(dampingRatio = 0.9f, stiffness = 400f))
overviewShown = false
@@ -194,6 +202,7 @@ fun TerminalScreen(host: Host, store: HostStore, onBack: () -> Unit) {
model.onHideKeyboard?.invoke()
cardBounds = null
zoomTarget = null
+ heroThread = currentThread
overviewShown = true
hostView?.input?.touchOverride = { closeOverview() }
// Without a card of its own (no threads, or none current) the
@@ -216,7 +225,7 @@ fun TerminalScreen(host: Host, store: HostStore, onBack: () -> Unit) {
// A faded layer is not enough: the texture repaints itself on
// every new frame (the cursor's blink) and can show through
// for one; hidden outright, it cannot.
- hostView?.visibility = android.view.View.INVISIBLE
+ hostView?.showPicture(false)
livePreview = overviewShown
}
}
@@ -245,7 +254,7 @@ fun TerminalScreen(host: Host, store: HostStore, onBack: () -> Unit) {
liveThread = currentThread?.id,
livePreview = livePreview,
onCardBounds = { cardLaidOut(it) },
- onDismiss = { closeOverview() },
+ onDismiss = { picked, frames -> closeOverview(picked, frames) },
)
}
}
@@ -281,9 +290,6 @@ fun TerminalScreen(host: Host, store: HostStore, onBack: () -> Unit) {
.fillMaxWidth()
.weight(1f)
.onGloballyPositioned { if (!overviewShown) terminalBounds = it.boundsInRoot() }
- // In the overview the shrunken terminal is the live card:
- // a tap on it (the hidden view lets it through) closes.
- .then(if (overviewOpen) Modifier.pointerInput(Unit) { detectTapGestures { closeOverview() } } else Modifier)
.graphicsLayer {
val t = zoom.value
val target = zoomTarget
@@ -343,7 +349,7 @@ fun TerminalScreen(host: Host, store: HostStore, onBack: () -> Unit) {
// the card's size, blown up to the terminal's width, and shrunk with
// the same zoom, so the whole card closes in, not just its bottom.
val hero = zoomTarget
- val heroThread = currentThread
+ val heroThread = heroThread
if (hero != null && heroThread != null && terminalBounds.width > 0) {
val sEnd = hero.thumb.width / terminalBounds.width
val headerPx = hero.thumb.top - hero.card.top
@@ -372,6 +378,35 @@ fun TerminalScreen(host: Host, store: HostStore, onBack: () -> Unit) {
) {
ThreadCardHeader(heroThread, MaterialTheme.colorScheme.primary, Modifier.fillMaxWidth())
}
+ // The moving card's border, around header and terminal slice
+ // together; the card's own border waits until it has landed.
+ val accent = MaterialTheme.colorScheme.primary
+ Spacer(
+ Modifier
+ .fillMaxSize()
+ .zIndex(2.5f)
+ .drawWithContent {
+ val t = zoom.value
+ val a = t * (1f - fade.value)
+ if (a <= 0f) return@drawWithContent
+ val scale = 1f + (sEnd - 1f) * t
+ val top = (terminalBounds.height - hero.thumb.height / sEnd) * t
+ val left = terminalBounds.left + (hero.thumb.left - terminalBounds.left) * t - boxOrigin.x
+ val thumbTop = terminalBounds.top + (hero.thumb.top - terminalBounds.top) * t - boxOrigin.y
+ val frameTop = thumbTop - headerPx * scale
+ val w = terminalBounds.width * scale
+ val h = headerPx * scale + (terminalBounds.height - top) * scale
+ val r = 13.dp.toPx() * t
+ val stroke = 2.dp.toPx()
+ drawRoundRect(
+ color = accent.copy(alpha = accent.alpha * a),
+ topLeft = Offset(left + stroke / 2, frameTop + stroke / 2),
+ size = androidx.compose.ui.geometry.Size(w - stroke, h - stroke),
+ cornerRadius = androidx.compose.ui.geometry.CornerRadius(r, r),
+ style = androidx.compose.ui.graphics.drawscope.Stroke(stroke),
+ )
+ }
+ )
}
if (showTree) {
diff --git a/android/app/src/main/java/com/roversx/thinkterm/TerminalView.kt b/android/app/src/main/java/com/roversx/thinkterm/TerminalView.kt
index eda40a51..9c35365f 100644
--- a/android/app/src/main/java/com/roversx/thinkterm/TerminalView.kt
+++ b/android/app/src/main/java/com/roversx/thinkterm/TerminalView.kt
@@ -80,6 +80,12 @@ class TerminalHostView(context: Context, private val model: TerminalModel) : Fra
}
}
+ /// The picture hidden or shown; touches keep arriving either way,
+ /// which the overview relies on while the terminal sits in its card.
+ fun showPicture(shown: Boolean) {
+ texture.visibility = if (shown) View.VISIBLE else View.INVISIBLE
+ }
+
private fun attachOrResize(width: Int, height: Int) {
if (window == 0L || width <= 0 || height <= 0) return
val density = resources.displayMetrics.density.toDouble()
diff --git a/android/app/src/main/java/com/roversx/thinkterm/TreeSheet.kt b/android/app/src/main/java/com/roversx/thinkterm/TreeSheet.kt
index f9190a5b..e7101afc 100644
--- a/android/app/src/main/java/com/roversx/thinkterm/TreeSheet.kt
+++ b/android/app/src/main/java/com/roversx/thinkterm/TreeSheet.kt
@@ -532,7 +532,9 @@ fun OverviewScreen(
liveThread: String?,
livePreview: Boolean,
onCardBounds: (CardFrames?) -> Unit,
- onDismiss: () -> Unit,
+ /// A tap on a card, with the card's frames, so the terminal can grow
+ /// back out of that card; a pinch passes nothing.
+ onDismiss: (ThreadView?, CardFrames?) -> Unit,
) {
val threads = model.threads?.threads ?: emptyList()
val groups = threads.groupBy { it.project }.toList()
@@ -555,7 +557,7 @@ fun OverviewScreen(
.fillMaxSize()
.background(Color(0xFF0F0F0F))
// Pinching out returns to the terminal.
- .pointerInput(Unit) { awaitPinchOut { onDismiss() } }
+ .pointerInput(Unit) { awaitPinchOut { onDismiss(null, null) } }
) {
Column(
Modifier
@@ -687,29 +689,39 @@ private fun ThreadCard(
live: Boolean,
livePreview: Boolean,
onCardBounds: (CardFrames?) -> Unit,
- onDismiss: () -> Unit,
+ onDismiss: (ThreadView?, CardFrames?) -> Unit,
modifier: Modifier = Modifier,
) {
val accent = MaterialTheme.colorScheme.primary
val shape = RoundedCornerShape(13.dp)
- // The live card reports where it is and where its thumbnail is, so
- // the screen can shrink the terminal, header and all, into it.
+ // Every card knows where it is and where its thumbnail is: the live
+ // one reports it so the terminal can shrink into it, and any card
+ // hands it over when tapped so the terminal can grow back out of it.
var cardRect by remember { mutableStateOf<Rect?>(null) }
var thumbRect by remember { mutableStateOf<Rect?>(null) }
+ fun frames(): CardFrames? {
+ val c = cardRect ?: return null
+ val t = thumbRect ?: return null
+ return CardFrames(c, t)
+ }
fun report() {
- val c = cardRect ?: return
- val t = thumbRect ?: return
- onCardBounds(CardFrames(c, t))
+ if (live) frames()?.let(onCardBounds)
+ }
+ // The moving card draws its own border until it has landed.
+ val border = when {
+ !live -> Color.White.copy(alpha = 0.07f)
+ livePreview -> accent
+ else -> Color.Transparent
}
Column(
modifier
- .onGloballyPositioned { if (live) { cardRect = it.boundsInRoot(); report() } }
+ .onGloballyPositioned { cardRect = it.boundsInRoot(); report() }
.clip(shape)
.background(Color(0xFF1A1C21))
- .border(if (live) 2.dp else 1.dp, if (live) accent else Color.White.copy(alpha = 0.07f), shape)
+ .border(if (live) 2.dp else 1.dp, border, shape)
.clickable {
if (!live) model.sideClick("thread", thread.id)
- onDismiss()
+ onDismiss(thread, frames())
}
) {
ThreadCardHeader(thread, accent)
@@ -731,11 +743,9 @@ private fun ThreadCard(
color = Color.White,
modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp, vertical = 7.dp).graphicsLayer { alpha = rowsAlpha },
)
- if (live) {
- // The terminal itself lands over this, then fades into the
- // same preview as every other card; the box reports where.
- Box(Modifier.fillMaxSize().onGloballyPositioned { thumbRect = it.boundsInRoot(); report() })
- }
+ // The terminal itself lands over this, then fades into the same
+ // preview as every other card; the box reports where.
+ Box(Modifier.fillMaxSize().onGloballyPositioned { thumbRect = it.boundsInRoot(); report() })
}
}
}
diff --git a/ios/Sources/TerminalScreen.swift b/ios/Sources/TerminalScreen.swift
index 77b5c8fd..6d23e1dd 100644
--- a/ios/Sources/TerminalScreen.swift
+++ b/ios/Sources/TerminalScreen.swift
@@ -33,6 +33,12 @@ struct TerminalScreen: View {
@State private var heroScale: CGFloat = 1
@State private var heroOffset: CGSize = .zero
@State private var heroAlpha: Double = 0
+ /// The moving card's border: its natural height follows the zoom.
+ @State private var heroFrameHeight: CGFloat = 0
+ /// The thread whose card the terminal is moving into or out of, and
+ /// the card a tap picked on the way back.
+ @State private var heroThread: ThreadView?
+ @State private var picked: (thread: ThreadView, frames: CardFrames)?
@State private var zoomScale: CGFloat = 1
@State private var zoomOffset: CGSize = .zero
@State private var zoomClip: CGFloat?
@@ -52,14 +58,18 @@ struct TerminalScreen: View {
var body: some View {
ZStack(alignment: .topLeading) {
if overviewVisible {
- OverviewScreen(model: model, isPresented: $overviewShown, cardFrame: $cardFrame, liveThread: currentThreadId, livePreview: livePreview)
+ OverviewScreen(
+ model: model, isPresented: $overviewShown, cardFrame: $cardFrame,
+ liveThread: currentThreadId, livePreview: livePreview,
+ onPick: { thread, frames in if let frames { picked = (thread, frames) } }
+ )
.opacity(overviewOpen ? 1 : 0)
.onChange(of: overviewShown) { _, shown in if !shown { closeOverview() } }
}
// The card's own header rides along with the terminal: laid out at
// the card's size, blown up to the terminal's width, and shrunk
// with the same zoom, so the whole card closes in.
- if let hero = heroFrames, let thread = model.threads?.threads.first(where: { $0.id == currentThreadId }) {
+ if let hero = heroFrames, let thread = heroThread {
let sEnd = hero.thumb.width / max(terminalFrame.width, 1)
ThreadCardHeader(thread: thread)
.frame(width: hero.card.width, height: hero.thumb.minY - hero.card.minY, alignment: .top)
@@ -71,6 +81,17 @@ struct TerminalScreen: View {
.opacity(heroAlpha * zoomFade)
.zIndex(3)
.allowsHitTesting(false)
+ // The moving card's border, around header and terminal slice
+ // together; the card's own border waits until it has landed.
+ RoundedRectangle(cornerRadius: 13)
+ .stroke(Color.accentColor, lineWidth: 2)
+ .frame(width: hero.card.width, height: heroFrameHeight)
+ .scaleEffect(1 / sEnd, anchor: .topLeading)
+ .scaleEffect(heroScale, anchor: .topLeading)
+ .offset(heroOffset)
+ .opacity(heroAlpha * zoomFade)
+ .zIndex(3)
+ .allowsHitTesting(false)
}
// Above the cards, so the shrunken terminal shows in its card;
// untouchable meanwhile, so the cards get the taps.
@@ -414,9 +435,12 @@ struct TerminalScreen: View {
let clip = frame.height / scale
// The header starts above the terminal, at the terminal's width,
// and lands on the card's own header.
+ let headerH = frame.minY - frames.card.minY
heroFrames = frames
+ heroThread = model.threads?.threads.first(where: { $0.id == currentThreadId })
heroScale = 1
- heroOffset = CGSize(width: terminalFrame.minX, height: terminalFrame.minY - (frame.minY - frames.card.minY) / scale)
+ heroOffset = CGSize(width: terminalFrame.minX, height: terminalFrame.minY - headerH / scale)
+ heroFrameHeight = headerH + terminalFrame.height * scale
heroAlpha = 0
withAnimation(.spring(response: 0.4, dampingFraction: 0.85)) {
overviewOpen = true
@@ -428,6 +452,7 @@ struct TerminalScreen: View {
zoomClip = clip
heroScale = scale
heroOffset = CGSize(width: frames.card.minX, height: frames.card.minY)
+ heroFrameHeight = frames.card.height
heroAlpha = 1
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
@@ -439,7 +464,30 @@ struct TerminalScreen: View {
}
}
+ /// Back to the terminal. A tapped card was kept by onPick: the
+ /// terminal grows out of that card, not the one it came from.
private func closeOverview() {
+ if let pick = picked, terminalFrame.width > 0 {
+ picked = nil
+ let frame = pick.frames.thumb
+ let scale = frame.width / terminalFrame.width
+ let clip = frame.height / scale
+ // Placed in the new card without animation: nothing shows yet.
+ var t = Transaction(); t.disablesAnimations = true
+ withTransaction(t) {
+ heroFrames = pick.frames
+ heroThread = pick.thread
+ zoomScale = scale
+ zoomOffset = CGSize(
+ width: frame.minX - terminalFrame.minX,
+ height: frame.minY - terminalFrame.minY - (terminalFrame.height - clip) * scale
+ )
+ zoomClip = clip
+ heroScale = scale
+ heroOffset = CGSize(width: pick.frames.card.minX, height: pick.frames.card.minY)
+ heroFrameHeight = pick.frames.card.height
+ }
+ }
withAnimation(.easeOut(duration: 0.1)) { livePreview = false }
withAnimation(.easeOut(duration: 0.15)) { zoomFade = 1 }
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
@@ -452,7 +500,9 @@ struct TerminalScreen: View {
heroAlpha = 0
if let hero = heroFrames {
let sEnd = hero.thumb.width / max(terminalFrame.width, 1)
- heroOffset = CGSize(width: terminalFrame.minX, height: terminalFrame.minY - (hero.thumb.minY - hero.card.minY) / sEnd)
+ let headerH = hero.thumb.minY - hero.card.minY
+ heroOffset = CGSize(width: terminalFrame.minX, height: terminalFrame.minY - headerH / sEnd)
+ heroFrameHeight = headerH + terminalFrame.height * sEnd
}
}
}
diff --git a/ios/Sources/TreeSheet.swift b/ios/Sources/TreeSheet.swift
index 2edea846..e8d11eab 100644
--- a/ios/Sources/TreeSheet.swift
+++ b/ios/Sources/TreeSheet.swift
@@ -278,17 +278,23 @@ struct OverviewScreen: View {
var liveThread: String?
/// The live card's rows wait until the terminal has faded out of it.
var livePreview: Bool = true
+ /// A tapped card, with its frames: the terminal grows back out of it.
+ var onPick: (ThreadView, CardFrames?) -> Void = { _, _ in }
private let dots = 4
private let rows = 9
private let columns = [GridItem(.flexible(), spacing: 10), GridItem(.flexible(), spacing: 10)]
- /// The live card's two frames, reported together once both are known.
- @State private var liveCardFrame: CGRect?
- @State private var thumbFrame: CGRect?
+ /// Every card's two frames, by thread; the live card's are reported.
+ @State private var cardFrames: [String: CGRect] = [:]
+ @State private var thumbFrames: [String: CGRect] = [:]
+
+ private func frames(of id: String) -> CardFrames? {
+ guard let card = cardFrames[id], let thumb = thumbFrames[id] else { return nil }
+ return CardFrames(card: card, thumb: thumb)
+ }
private func report() {
- guard let card = liveCardFrame, let thumb = thumbFrame else { return }
- let frames = CardFrames(card: card, thumb: thumb)
+ guard let live = liveThread, let frames = frames(of: live) else { return }
if cardFrame != frames { cardFrame = frames }
}
@@ -370,6 +376,7 @@ struct OverviewScreen: View {
let live = thread.id == liveThread
return Button {
if !live { model.sideClick("thread", id: thread.id) }
+ onPick(thread, frames(of: thread.id))
isPresented = false
} label: {
VStack(alignment: .leading, spacing: 0) {
@@ -382,30 +389,32 @@ struct OverviewScreen: View {
.padding(.horizontal, 8)
.padding(.vertical, 7)
.opacity(!live || livePreview ? 1 : 0)
- if live {
- // The terminal itself lands over this, then fades into
- // the same preview as every other card; the frame is
- // reported so the screen above knows where.
- Color.clear
- .background(GeometryReader { geo in
- Color.clear
- .onAppear { thumbFrame = geo.frame(in: .named("screen")); report() }
- .onChange(of: geo.frame(in: .named("screen"))) { _, f in thumbFrame = f; report() }
- })
- }
+ // The terminal itself lands over this, then fades into the
+ // same preview as every other card; the frame is kept so
+ // the screen above knows where.
+ Color.clear
+ .background(GeometryReader { geo in
+ Color.clear
+ .onAppear { thumbFrames[thread.id] = geo.frame(in: .named("screen")); report() }
+ .onChange(of: geo.frame(in: .named("screen"))) { _, f in thumbFrames[thread.id] = f; report() }
+ })
}
.frame(height: 92, alignment: .topLeading)
.background(thread.live ? model.background : Color.black.opacity(0.4))
.clipped()
}
- .background(live ? GeometryReader { geo in
+ .background(GeometryReader { geo in
Color.clear
- .onAppear { liveCardFrame = geo.frame(in: .named("screen")); report() }
- .onChange(of: geo.frame(in: .named("screen"))) { _, f in liveCardFrame = f; report() }
- } : nil)
+ .onAppear { cardFrames[thread.id] = geo.frame(in: .named("screen")); report() }
+ .onChange(of: geo.frame(in: .named("screen"))) { _, f in cardFrames[thread.id] = f; report() }
+ })
.background(Color(red: 0.10, green: 0.11, blue: 0.13))
.clipShape(RoundedRectangle(cornerRadius: 13))
- .overlay(RoundedRectangle(cornerRadius: 13).stroke(live ? Color.accentColor : Color.white.opacity(0.07), lineWidth: live ? 2 : 1))
+ // The moving card draws its own border until it has landed.
+ .overlay(RoundedRectangle(cornerRadius: 13).stroke(
+ live ? (livePreview ? Color.accentColor : Color.clear) : Color.white.opacity(0.07),
+ lineWidth: live ? 2 : 1
+ ))
}
.buttonStyle(.plain)
}