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 sidebar is the TUI's tree, in a panel from the left

RoversXcb6b4f349786
diff --git a/android/app/src/main/java/com/roversx/thinkterm/Sidebar.kt b/android/app/src/main/java/com/roversx/thinkterm/Sidebar.kt
new file mode 100644
index 00000000..5413a14b
--- /dev/null
+++ b/android/app/src/main/java/com/roversx/thinkterm/Sidebar.kt
@@ -0,0 +1,354 @@
+package com.roversx.thinkterm
+
+import androidx.activity.compose.BackHandler
+import androidx.compose.animation.AnimatedVisibility
+import androidx.compose.animation.fadeIn
+import androidx.compose.animation.fadeOut
+import androidx.compose.animation.slideInHorizontally
+import androidx.compose.animation.slideOutHorizontally
+import androidx.compose.foundation.ExperimentalFoundationApi
+import androidx.compose.foundation.background
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.combinedClickable
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxHeight
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.shape.CircleShape
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.Add
+import androidx.compose.material.icons.filled.KeyboardArrowDown
+import androidx.compose.material.icons.filled.MoreHoriz
+import androidx.compose.material.icons.filled.Settings
+import androidx.compose.material.icons.filled.Star
+import androidx.compose.material.icons.filled.Window
+import androidx.compose.material3.AlertDialog
+import androidx.compose.material3.HorizontalDivider
+import androidx.compose.material3.Icon
+import androidx.compose.material3.IconButton
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.OutlinedTextField
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextButton
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateListOf
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.rotate
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+
+/// The desktop's sidebar, as the TUI lays it out: a panel from the left
+/// with the tree — the host, its Spaces, their projects, their threads —
+/// each level folding, New Thread at the top, Settings at the bottom.
+/// Everything is named as the desktop names it.
+@Composable
+fun SidebarDrawer(
+ model: TerminalModel,
+ visible: Boolean,
+ onDismiss: () -> Unit,
+ onEditHost: () -> Unit,
+ onSettings: () -> Unit,
+) {
+ BackHandler(enabled = visible) { onDismiss() }
+ Box(Modifier.fillMaxSize()) {
+ AnimatedVisibility(visible, enter = fadeIn(), exit = fadeOut()) {
+ Box(Modifier.fillMaxSize().background(Color.Black.copy(alpha = 0.45f)).clickable(onClick = onDismiss))
+ }
+ AnimatedVisibility(visible, enter = slideInHorizontally { -it }, exit = slideOutHorizontally { -it }) {
+ Box(
+ Modifier
+ .fillMaxHeight()
+ .width(300.dp)
+ .background(MaterialTheme.colorScheme.surface)
+ ) {
+ SidebarTree(model, onDismiss, onEditHost, onSettings)
+ }
+ }
+ }
+}
+
+/// Which nodes are folded; every Space but the one on show starts folded.
+private class Folded(model: TerminalModel) {
+ val keys = mutableStateListOf<String>().also { keys ->
+ for (space in model.tree?.spaces ?: emptyList()) if (!space.current) keys.add("space:" + space.id)
+ }
+
+ fun toggle(key: String) { if (!keys.remove(key)) keys.add(key) }
+ operator fun contains(key: String) = keys.contains(key)
+}
+
+@OptIn(ExperimentalFoundationApi::class)
+@Composable
+private fun SidebarTree(model: TerminalModel, onDismiss: () -> Unit, onEditHost: () -> Unit, onSettings: () -> Unit) {
+ val folded = remember(model) { Folded(model) }
+ var connectionMenu by remember { mutableStateOf(false) }
+ var spaceMenu by remember { mutableStateOf(false) }
+ var renaming by remember { mutableStateOf<Pair<String, String>?>(null) }
+ var renameText by remember { mutableStateOf("") }
+ val tree = model.tree
+ val editing = model.sidebar?.editing
+ val error = model.sidebar?.newProjectError
+ val secondary = MaterialTheme.colorScheme.onSurfaceVariant
+ val accent = MaterialTheme.colorScheme.primary
+
+ LaunchedEffect(Unit) { model.refreshViews() }
+ LaunchedEffect(editing) {
+ val id = editing?.id
+ if (editing == null || editing.kind == "none" || id == null || renaming != null) return@LaunchedEffect
+ renameText = ""
+ renaming = editing.kind to id
+ }
+
+ Column(Modifier.fillMaxSize()) {
+ LazyColumn(Modifier.fillMaxWidth().weight(1f)) {
+ // The host: the root of the tree, and the connection's actions.
+ item {
+ Box {
+ TreeRow(
+ depth = 0,
+ expandable = true,
+ collapsed = "host" in folded,
+ onToggle = { folded.toggle("host") },
+ onClick = { connectionMenu = true },
+ onLongClick = { connectionMenu = true },
+ trailing = {
+ IconButton(onClick = { connectionMenu = true }, modifier = Modifier.size(32.dp)) {
+ Icon(Icons.Default.MoreHoriz, contentDescription = null, tint = secondary, modifier = Modifier.size(18.dp))
+ }
+ },
+ ) {
+ Box(Modifier.size(8.dp).background(statusColor(model), CircleShape))
+ Text(model.host.display, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
+ }
+ ConnectionMenu(model, expanded = connectionMenu, onDismiss = { connectionMenu = false }, onEditHost = onEditHost)
+ }
+ }
+ if ("host" !in folded) {
+ item {
+ Row(
+ Modifier.fillMaxWidth().clickable { model.sideClick("new-thread"); onDismiss() }.padding(horizontal = 16.dp, vertical = 10.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(8.dp),
+ ) {
+ Icon(Icons.Default.Add, contentDescription = null, tint = accent, modifier = Modifier.size(18.dp))
+ Text(tr("thread.new"), color = accent)
+ }
+ }
+ item {
+ Row(
+ Modifier.fillMaxWidth().padding(start = 16.dp, end = 4.dp, top = 6.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Text(tr("workspaces").uppercase(), fontSize = 11.sp, color = secondary, modifier = Modifier.weight(1f))
+ IconButton(onClick = { model.sideClick("new-project") }, modifier = Modifier.size(32.dp)) {
+ Icon(Icons.Default.Add, contentDescription = tr("project.new"), tint = secondary, modifier = Modifier.size(18.dp))
+ }
+ }
+ }
+ for (space in tree?.spaces ?: emptyList()) {
+ val spaceKey = "space:" + space.id
+ item(key = spaceKey) {
+ Box {
+ TreeRow(
+ depth = 1,
+ expandable = space.projects.isNotEmpty(),
+ collapsed = spaceKey in folded,
+ onToggle = { folded.toggle(spaceKey) },
+ onClick = {
+ if (!space.current) model.setSpace(space.id)
+ if (spaceKey in folded) folded.toggle(spaceKey)
+ },
+ onLongClick = { spaceMenu = true },
+ trailing = {
+ IconButton(onClick = { model.setSpace(space.id); model.sideClick("new-project") }, modifier = Modifier.size(32.dp)) {
+ Icon(Icons.Default.Add, contentDescription = tr("project.new"), tint = secondary, modifier = Modifier.size(16.dp))
+ }
+ },
+ ) {
+ Text(space.name, fontWeight = if (space.current) FontWeight.SemiBold else FontWeight.Normal, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
+ }
+ AppContextMenu(model, "space", "", expanded = spaceMenu, onDismiss = { spaceMenu = false })
+ }
+ }
+ if (spaceKey in folded) continue
+ for (project in space.projects) {
+ val projectKey = "project:" + project.id
+ item(key = projectKey) {
+ var menu by remember { mutableStateOf(false) }
+ Box {
+ TreeRow(
+ depth = 2,
+ expandable = project.threads.isNotEmpty(),
+ collapsed = projectKey in folded,
+ onToggle = { folded.toggle(projectKey) },
+ onClick = { folded.toggle(projectKey) },
+ onLongClick = { menu = true },
+ trailing = {
+ IconButton(onClick = { model.setSpace(space.id); model.sideClick("new-thread", project.id) }, modifier = Modifier.size(32.dp)) {
+ Icon(Icons.Default.Add, contentDescription = tr("thread.new"), tint = secondary, modifier = Modifier.size(16.dp))
+ }
+ },
+ ) {
+ Text(project.name, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
+ }
+ AppContextMenu(model, "project", project.id, expanded = menu, onDismiss = { menu = false })
+ }
+ }
+ if (projectKey in folded) continue
+ for (thread in project.threads) {
+ item(key = "thread:" + thread.id) {
+ var menu by remember { mutableStateOf(false) }
+ Box {
+ TreeRow(
+ depth = 3,
+ expandable = false,
+ collapsed = false,
+ selected = thread.selected,
+ onToggle = {},
+ onClick = { model.openThread(thread.id, space.id); onDismiss() },
+ onLongClick = { menu = true },
+ ) {
+ Box(Modifier.size(8.dp).background(threadColor(thread.status, thread.live), CircleShape))
+ if (thread.pinned) Icon(Icons.Default.Star, contentDescription = null, tint = secondary, modifier = Modifier.size(12.dp))
+ Text(
+ thread.name,
+ fontWeight = if (thread.unread || thread.selected) FontWeight.SemiBold else FontWeight.Normal,
+ color = if (thread.live) MaterialTheme.colorScheme.onSurface else secondary,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ modifier = Modifier.weight(1f),
+ )
+ }
+ AppContextMenu(model, "thread", thread.id, expanded = menu, onDismiss = { menu = false })
+ }
+ }
+ }
+ }
+ }
+ // What the desktop lists after the tree: archived projects of
+ // the Space on show, and windows no thread claims.
+ val rows = model.sidebar?.rows ?: emptyList()
+ val tail = rows.dropWhile { it !is SideRow.Archived && it !is SideRow.Others }
+ for (row in tail) {
+ item(key = row.key) {
+ when (row) {
+ is SideRow.Archived -> Row(
+ Modifier.fillMaxWidth().clickable { model.sideClick("toggle-archived", flag = !row.open) }.padding(start = 16.dp, end = 8.dp, top = 8.dp, bottom = 6.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(6.dp),
+ ) {
+ Icon(Icons.Default.KeyboardArrowDown, contentDescription = null, tint = secondary, modifier = Modifier.size(16.dp).rotate(if (row.open) 0f else -90f))
+ Text("${row.label} (${row.count})", fontSize = 12.sp, color = secondary)
+ }
+ is SideRow.Project -> {
+ var menu by remember { mutableStateOf(false) }
+ Box {
+ TreeRow(depth = 2, expandable = false, collapsed = true, onToggle = {}, onClick = { menu = true }, onLongClick = { menu = true }) {
+ Text(row.name, color = secondary, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
+ }
+ AppContextMenu(model, "archived-project", row.id, expanded = menu, onDismiss = { menu = false })
+ }
+ }
+ is SideRow.Others -> Text(tr("otherwindows").uppercase(), fontSize = 11.sp, color = secondary, modifier = Modifier.padding(start = 16.dp, top = 10.dp, bottom = 2.dp))
+ is SideRow.Window -> Row(
+ Modifier
+ .fillMaxWidth()
+ .background(if (row.selected) accent.copy(alpha = 0.18f) else Color.Transparent)
+ .clickable { model.sideClick("window", row.id.toString()); onDismiss() }
+ .padding(horizontal = 16.dp, vertical = 8.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(8.dp),
+ ) {
+ Icon(Icons.Default.Window, contentDescription = null, tint = secondary, modifier = Modifier.size(16.dp))
+ Text(row.title.ifEmpty { tr("window.n", row.id) }, maxLines = 1, overflow = TextOverflow.Ellipsis)
+ }
+ else -> {}
+ }
+ }
+ }
+ if (!error.isNullOrEmpty()) {
+ item {
+ Text(error, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.error, modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp))
+ }
+ }
+ }
+ }
+ HorizontalDivider()
+ Row(
+ Modifier.fillMaxWidth().clickable { onDismiss(); onSettings() }.padding(horizontal = 16.dp, vertical = 12.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(8.dp),
+ ) {
+ Icon(Icons.Default.Settings, contentDescription = null, tint = secondary, modifier = Modifier.size(18.dp))
+ Text(tr("settings"), color = secondary)
+ }
+ }
+
+ if (renaming != null) {
+ AlertDialog(
+ onDismissRequest = { model.sideKey("Escape", ""); renaming = null },
+ title = { Text(tr("rename")) },
+ text = { OutlinedTextField(value = renameText, onValueChange = { renameText = it }, label = { Text(tr("f.name")) }, singleLine = true) },
+ confirmButton = { TextButton(onClick = { model.sideKey("Enter", renameText); renaming = null }) { Text(tr("save")) } },
+ dismissButton = { TextButton(onClick = { model.sideKey("Escape", ""); renaming = null }) { Text(tr("cancel")) } },
+ )
+ }
+}
+
+/// One row of the tree: indented by its depth, a fold chevron when it
+/// has children, its content, and a trailing button.
+@OptIn(ExperimentalFoundationApi::class)
+@Composable
+private fun TreeRow(
+ depth: Int,
+ expandable: Boolean,
+ collapsed: Boolean,
+ selected: Boolean = false,
+ onToggle: () -> Unit,
+ onClick: () -> Unit,
+ onLongClick: () -> Unit,
+ trailing: @Composable (() -> Unit)? = null,
+ content: @Composable androidx.compose.foundation.layout.RowScope.() -> Unit,
+) {
+ val accent = MaterialTheme.colorScheme.primary
+ val secondary = MaterialTheme.colorScheme.onSurfaceVariant
+ Row(
+ Modifier
+ .fillMaxWidth()
+ .background(if (selected) accent.copy(alpha = 0.18f) else Color.Transparent)
+ .combinedClickable(onClick = onClick, onLongClick = onLongClick)
+ .padding(start = 8.dp + 14.dp * depth, end = 4.dp, top = 6.dp, bottom = 6.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(8.dp),
+ ) {
+ if (expandable) {
+ Icon(
+ Icons.Default.KeyboardArrowDown,
+ contentDescription = null,
+ tint = secondary,
+ modifier = Modifier.size(20.dp).rotate(if (collapsed) -90f else 0f).clickable(onClick = onToggle),
+ )
+ } else {
+ Spacer(Modifier.width(20.dp))
+ }
+ content()
+ if (trailing != null) trailing()
+ }
+}
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 9e546b57..7a06972c 100644
--- a/android/app/src/main/java/com/roversx/thinkterm/TerminalModel.kt
+++ b/android/app/src/main/java/com/roversx/thinkterm/TerminalModel.kt
@@ -45,6 +45,8 @@ class TerminalModel(
private set
var sidebar by mutableStateOf<SidebarView?>(null)
private set
+ var tree by mutableStateOf<TreeView?>(null)
+ private set
var navs by mutableStateOf<List<NavView>>(emptyList())
private set
var status by mutableStateOf<StatusView?>(null)
@@ -308,6 +310,15 @@ class TerminalModel(
fun sideKey(key: String, value: String) = core.sideKey(key, value)
+ /// Show a thread, switching the Space on show to its own first when
+ /// it is in another one, so the strips follow.
+ fun openThread(id: String, spaceId: String?) {
+ if (spaceId != null && tree?.spaces?.firstOrNull { it.current }?.id != spaceId) core.setSpace(spaceId)
+ sideClick("thread", id)
+ }
+
+ fun setSpace(id: String) = core.setSpace(id)
+
fun contextMenu(kind: String, id: String): List<MenuItem> = Views.menu(core.contextMenu(kind, id))
/// Run a menu row. Copy and paste are the shell's to do.
@@ -349,6 +360,8 @@ class TerminalModel(
if (sidebar != this.sidebar) this.sidebar = sidebar
val threads = Views.threads(core.view("threads"))
if (threads != this.threads) this.threads = threads
+ val tree = Views.tree(core.view("tree"))
+ if (tree != this.tree) this.tree = tree
val navs = Views.navs(core.view("navs"))
if (navs != this.navs) this.navs = navs
val status = Views.status(core.view("status"))
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 c52d1ddf..d2655a1a 100644
--- a/android/app/src/main/java/com/roversx/thinkterm/TerminalScreen.kt
+++ b/android/app/src/main/java/com/roversx/thinkterm/TerminalScreen.kt
@@ -417,8 +417,14 @@ fun TerminalScreen(host: Host, store: HostStore, onBack: () -> Unit) {
)
}
- if (showTree) {
- TreeSheet(model = model, onDismiss = { showTree = false }, onEditHost = { showTree = false; editingHost = model.host })
+ Box(Modifier.fillMaxSize().zIndex(2.8f)) {
+ SidebarDrawer(
+ model = model,
+ visible = showTree,
+ onDismiss = { showTree = false },
+ onEditHost = { showTree = false; editingHost = model.host },
+ onSettings = { showSettings = true },
+ )
}
if (showSettings) {
Box(Modifier.fillMaxSize().zIndex(3f).background(MaterialTheme.colorScheme.background)) {
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 75ee3847..f40030dc 100644
--- a/android/app/src/main/java/com/roversx/thinkterm/TreeSheet.kt
+++ b/android/app/src/main/java/com/roversx/thinkterm/TreeSheet.kt
@@ -82,342 +82,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import kotlinx.coroutines.delay
-/// The desktop's sidebar and tab strip in one sheet, the way both are on
-/// screen at once there: the Space, its threads by project, under an
-/// threads under them, as far as the desktop's sidebar goes.
-/// Everything is named as the desktop names it: thread, tab, pane.
-@Composable
-fun TreeSheet(model: TerminalModel, onDismiss: () -> Unit, onEditHost: () -> Unit) {
- val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
- val open = remember { TreeOpen() }
- var spaceMenu by remember { mutableStateOf<List<MenuItem>>(emptyList()) }
- var spacesShown by remember { mutableStateOf(false) }
- var renaming by remember { mutableStateOf<Pair<String, String>?>(null) }
- var renameText by remember { mutableStateOf("") }
- var connectionMenu by remember { mutableStateOf(false) }
- val threads = model.threads?.threads ?: emptyList()
- val rows = model.sidebar?.rows ?: emptyList()
- val error = model.sidebar?.newProjectError
- val editing = model.sidebar?.editing
-
- LaunchedEffect(Unit) {
- model.refreshViews()
- spaceMenu = model.contextMenu("space", "")
- // The current thread starts open: its tabs are what the strip shows.
- model.threads?.current?.let { if (!open.threads.contains(it.id)) open.threads.add(it.id) }
- }
- LaunchedEffect(editing) {
- val id = editing?.id
- if (editing == null || editing.kind == "none" || id == null || renaming != null) return@LaunchedEffect
- renameText = ""
- renaming = editing.kind to id
- }
-
- ModalBottomSheet(
- onDismissRequest = onDismiss,
- sheetState = sheetState,
- modifier = Modifier.fillMaxSize(),
- ) {
- Row(
- Modifier.fillMaxWidth().padding(start = 8.dp, end = 4.dp),
- verticalAlignment = Alignment.CenterVertically,
- ) {
- TextButton(onClick = onDismiss) { Text(tr("done")) }
- Spacer(Modifier.width(8.dp))
- Text(tr("threads"), style = MaterialTheme.typography.titleMedium)
- Spacer(Modifier.weight(1f))
- Box {
- IconButton(onClick = {
- spaceMenu = model.contextMenu("space", "")
- spacesShown = true
- }) {
- Icon(Icons.Default.Layers, contentDescription = tr("workspaces"))
- }
- DropdownMenu(expanded = spacesShown, onDismissRequest = { spacesShown = false }) {
- for (item in spaceMenu) {
- if (item.kind != "item") continue
- DropdownMenuItem(
- text = { Text(item.label) },
- enabled = item.enabled,
- leadingIcon = if (item.checked) ({ Icon(Icons.Default.Check, contentDescription = null) }) else null,
- onClick = {
- model.menuAction(item.id)
- spaceMenu = model.contextMenu("space", "")
- spacesShown = false
- },
- )
- }
- }
- }
- IconButton(onClick = { model.chromeClick("new-tab") }) {
- Icon(Icons.Default.Add, contentDescription = tr("thread.new"))
- }
- }
- // The host this sheet belongs to: its state, and what can be done
- // with the connection (this used to be a dot in the bar).
- Box {
- Row(
- Modifier
- .fillMaxWidth()
- .clickable { connectionMenu = true }
- .padding(horizontal = 16.dp, vertical = 8.dp),
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(8.dp),
- ) {
- Box(Modifier.size(8.dp).background(statusColor(model), CircleShape))
- Text(model.host.display, style = MaterialTheme.typography.bodyMedium, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
- Text(
- if (model.isConnected) tr("disconnect") else tr("reconnect"),
- style = MaterialTheme.typography.labelMedium,
- color = MaterialTheme.colorScheme.primary,
- )
- }
- ConnectionMenu(model, expanded = connectionMenu, onDismiss = { connectionMenu = false }, onEditHost = onEditHost)
- }
- LazyColumn(Modifier.fillMaxWidth().weight(1f)) {
- items(rows) { row -> SideRowView(model, row, threads, open, onDismiss) }
- if (!error.isNullOrEmpty()) {
- item {
- Text(
- error,
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.error,
- modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
- )
- }
- }
- }
- }
-
- if (renaming != null) {
- AlertDialog(
- onDismissRequest = {
- model.sideKey("Escape", "")
- renaming = null
- },
- title = { Text(tr("rename")) },
- text = {
- OutlinedTextField(
- value = renameText,
- onValueChange = { renameText = it },
- singleLine = true,
- label = { Text(tr("f.name")) },
- )
- },
- confirmButton = {
- TextButton(onClick = {
- model.sideKey("Enter", renameText)
- renaming = null
- }) { Text(tr("save")) }
- },
- dismissButton = {
- TextButton(onClick = {
- model.sideKey("Escape", "")
- renaming = null
- }) { Text(tr("cancel")) }
- },
- )
- }
-}
-
-/// Which threads and tabs are unfolded, for as long as the sheet is up.
-private class TreeOpen {
- val threads = mutableStateListOf<String>()
- val tabs = mutableStateListOf<String>()
-
- fun toggleThread(id: String) { if (!threads.remove(id)) threads.add(id) }
-
- fun toggleTab(key: String) { if (!tabs.remove(key)) tabs.add(key) }
-}
-
-@Composable
-private fun SideRowView(
- model: TerminalModel,
- row: SideRow,
- threads: List<ThreadView>,
- open: TreeOpen,
- onDismiss: () -> Unit,
-) {
- val accent = MaterialTheme.colorScheme.primary
- val secondary = MaterialTheme.colorScheme.onSurfaceVariant
- when (row) {
- is SideRow.Space -> Text(
- row.name,
- style = MaterialTheme.typography.titleMedium,
- modifier = Modifier.padding(start = 16.dp, end = 16.dp, top = 10.dp, bottom = 4.dp),
- )
- is SideRow.NewThread -> Row(
- Modifier
- .fillMaxWidth()
- .clickable { model.sideClick("new-thread") }
- .padding(horizontal = 16.dp, vertical = 10.dp),
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(8.dp),
- ) {
- Icon(Icons.Default.Add, contentDescription = null, tint = accent, modifier = Modifier.size(18.dp))
- Text(tr("thread.new"), color = accent)
- }
- is SideRow.Pinned -> TreeCaption(tr("pinned"))
- is SideRow.Workspaces -> TreeCaption(tr("workspaces"))
- is SideRow.Others -> TreeCaption(tr("otherwindows"))
- is SideRow.Project -> ProjectRow(model, row)
- is SideRow.Thread -> {
- val thread = threads.firstOrNull { it.id == row.row.id }
- if (thread == null) {
- Text(row.row.name, modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp))
- } else {
- ThreadRows(model, thread, if (row.row.project.isEmpty()) 0.dp else 14.dp, open, onDismiss)
- }
- }
- is SideRow.Archived -> Row(
- Modifier
- .fillMaxWidth()
- .clickable { model.sideClick("toggle-archived", flag = !row.open) }
- .padding(horizontal = 16.dp, vertical = 8.dp),
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(6.dp),
- ) {
- Icon(
- Icons.AutoMirrored.Filled.KeyboardArrowRight,
- contentDescription = null,
- tint = secondary,
- modifier = Modifier.size(14.dp).rotate(if (row.open) 90f else 0f),
- )
- Text("${row.label} (${row.count})", style = MaterialTheme.typography.bodySmall, color = secondary)
- }
- is SideRow.Window -> Row(
- Modifier
- .fillMaxWidth()
- .background(if (row.selected) accent.copy(alpha = 0.2f) else Color.Transparent)
- .clickable { model.sideClick("window", row.id.toString()) }
- .padding(horizontal = 16.dp, vertical = 8.dp),
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(8.dp),
- ) {
- Icon(Icons.Default.Window, contentDescription = null, tint = secondary, modifier = Modifier.size(16.dp))
- Text(
- row.title.ifEmpty { tr("window.n", row.id) },
- maxLines = 1,
- overflow = TextOverflow.Ellipsis,
- )
- }
- }
-}
-
-@Composable
-private fun TreeCaption(text: String) {
- Text(
- text.uppercase(),
- style = MaterialTheme.typography.labelSmall,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- modifier = Modifier.padding(start = 16.dp, end = 16.dp, top = 12.dp, bottom = 2.dp),
- )
-}
-
-@Composable
-private fun ProjectRow(model: TerminalModel, row: SideRow.Project) {
- val accent = MaterialTheme.colorScheme.primary
- val secondary = MaterialTheme.colorScheme.onSurfaceVariant
- var menu by remember { mutableStateOf(false) }
- Box {
- Row(
- Modifier
- .fillMaxWidth()
- .combinedClickable(
- onClick = { model.sideClick("toggle-project", row.id) },
- onLongClick = { menu = true },
- )
- .padding(start = 8.dp, end = 8.dp, top = 4.dp, bottom = 4.dp),
- verticalAlignment = Alignment.CenterVertically,
- ) {
- IconButton(onClick = { model.sideClick("toggle-project", row.id) }, modifier = Modifier.size(28.dp)) {
- Icon(
- Icons.AutoMirrored.Filled.KeyboardArrowRight,
- contentDescription = null,
- tint = secondary,
- modifier = Modifier.size(16.dp).rotate(if (row.collapsed) 0f else 90f),
- )
- }
- Column(Modifier.weight(1f).padding(start = 4.dp)) {
- Text(
- row.name,
- style = MaterialTheme.typography.titleSmall,
- maxLines = 1,
- overflow = TextOverflow.Ellipsis,
- )
- Text(
- row.path,
- style = MaterialTheme.typography.labelSmall,
- color = secondary,
- maxLines = 1,
- overflow = TextOverflow.Ellipsis,
- )
- }
- if (!row.archived) {
- IconButton(onClick = { model.sideClick("new-thread", row.id) }, modifier = Modifier.size(28.dp)) {
- Icon(Icons.Default.Add, contentDescription = null, tint = accent, modifier = Modifier.size(18.dp))
- }
- }
- }
- AppContextMenu(
- model = model,
- kind = if (row.archived) "archived-project" else "project",
- id = row.id,
- expanded = menu,
- onDismiss = { menu = false },
- )
- }
-}
-
-/// A thread, and when open, its tabs under it.
-@Composable
-private fun ThreadRows(
- model: TerminalModel,
- thread: ThreadView,
- indent: Dp,
- open: TreeOpen,
- onDismiss: () -> Unit,
-) {
- val accent = MaterialTheme.colorScheme.primary
- val secondary = MaterialTheme.colorScheme.onSurfaceVariant
- var menu by remember { mutableStateOf(false) }
- Column {
- Box {
- Row(
- Modifier
- .fillMaxWidth()
- .background(if (thread.current) accent.copy(alpha = 0.18f) else Color.Transparent)
- .combinedClickable(
- onClick = {
- model.sideClick("thread", thread.id)
- onDismiss()
- },
- onLongClick = { menu = true },
- )
- .padding(start = 16.dp + indent, end = 8.dp, top = 6.dp, bottom = 6.dp),
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(8.dp),
- ) {
- Box(Modifier.size(8.dp).background(threadColor(thread.status, thread.live), CircleShape))
- Text(
- thread.name,
- fontWeight = if (thread.unread) FontWeight.SemiBold else FontWeight.Normal,
- maxLines = 1,
- overflow = TextOverflow.Ellipsis,
- modifier = Modifier.weight(1f),
- )
- if (thread.pinned) {
- Icon(Icons.Default.PushPin, contentDescription = null, tint = secondary, modifier = Modifier.size(14.dp))
- }
- if (!thread.live) {
- Text(tr("thread.off"), style = MaterialTheme.typography.labelSmall, color = secondary)
- }
- }
- AppContextMenu(model = model, kind = "thread", id = thread.id, expanded = menu, onDismiss = { menu = false })
- }
- }
-}
-
private const val OVERVIEW_ROWS = 9
private const val OVERVIEW_COLS = 38
diff --git a/android/app/src/main/java/com/roversx/thinkterm/Views.kt b/android/app/src/main/java/com/roversx/thinkterm/Views.kt
index 8ba77c97..19464654 100644
--- a/android/app/src/main/java/com/roversx/thinkterm/Views.kt
+++ b/android/app/src/main/java/com/roversx/thinkterm/Views.kt
@@ -68,6 +68,13 @@ data class ThreadTab(
data class PaneRef(val pane: Int, val title: String)
+/// The tree whole, every Space with its projects and threads: `App::tree_view`.
+data class TreeView(val spaces: List<TreeSpace>)
+
+data class TreeSpace(val id: String, val name: String, val current: Boolean, val projects: List<TreeProject>)
+
+data class TreeProject(val id: String, val name: String, val path: String, val threads: List<ThreadRow>)
+
/// A thumbnail row: `App::PreviewRow`.
data class PreviewRow(val runs: List<PreviewRun>)
@@ -253,6 +260,40 @@ object Views {
)
}
+ fun tree(json: String): TreeView? {
+ val root = obj(json) ?: return null
+ return TreeView(
+ root.optJSONArray("spaces").map { sp ->
+ TreeSpace(
+ id = sp.optString("id"),
+ name = sp.optString("name"),
+ current = sp.optBoolean("current"),
+ projects = sp.optJSONArray("projects").map { pr ->
+ TreeProject(
+ id = pr.optString("id"),
+ name = pr.optString("name"),
+ path = pr.optString("path"),
+ threads = pr.optJSONArray("threads").map { threadRow(it) },
+ )
+ },
+ )
+ }
+ )
+ }
+
+ private fun threadRow(r: JSONObject) = ThreadRow(
+ id = r.optString("id"),
+ project = r.optString("project"),
+ name = r.optString("name"),
+ status = r.optString("status"),
+ dot = r.optString("dot"),
+ pinned = r.optBoolean("pinned"),
+ unread = r.optBoolean("unread"),
+ live = r.optBoolean("live"),
+ selected = r.optBoolean("selected"),
+ deleting = r.optBoolean("deleting"),
+ )
+
fun previewRows(json: String): List<PreviewRow> {
val arr = array(json) ?: return emptyList()
return arr.map { row ->
diff --git a/ios/Resources/strings.json b/ios/Resources/strings.json
index 72d13472..2f1cba2c 100644
--- a/ios/Resources/strings.json
+++ b/ios/Resources/strings.json
@@ -144,6 +144,7 @@
"panes.n": "%d Bereiche",
"paste": "Einsetzen",
"pinned": "Angeheftet",
+ "project.new": "Neues Projekt",
"reconnect": "Erneut verbinden",
"rename": "Umbenennen",
"resize.auto": "Auto",
@@ -169,6 +170,7 @@
"settings": "Einstellungen",
"showlog": "Protokoll zeigen",
"showlog.foot": "Das Verbindungsprotokoll über dem Terminal, zum Melden von Problemen.",
+ "sidebar": "Seitenleiste",
"snip.command": "Befehl",
"snip.enter": "Nach dem Senden Enter drücken",
"snip.new": "Neuer Schnipsel",
@@ -350,6 +352,7 @@
"panes.n": "%d panes",
"paste": "Paste",
"pinned": "Pinned",
+ "project.new": "New project",
"reconnect": "Reconnect",
"rename": "Rename",
"resize.auto": "Auto",
@@ -375,6 +378,7 @@
"settings": "Settings",
"showlog": "Show log",
"showlog.foot": "The connection’s log over the terminal, for reporting a problem.",
+ "sidebar": "Sidebar",
"snip.command": "Command",
"snip.enter": "Press Enter after sending",
"snip.new": "New snippet",
@@ -556,6 +560,7 @@
"panes.n": "%d volets",
"paste": "Coller",
"pinned": "Épinglées",
+ "project.new": "Nouveau projet",
"reconnect": "Reconnecter",
"rename": "Renommer",
"resize.auto": "Auto",
@@ -581,6 +586,7 @@
"settings": "Réglages",
"showlog": "Afficher le journal",
"showlog.foot": "Le journal de connexion par-dessus le terminal, pour signaler un problème.",
+ "sidebar": "Barre latérale",
"snip.command": "Commande",
"snip.enter": "Appuyer sur Entrée après l’envoi",
"snip.new": "Nouvel extrait",
@@ -762,6 +768,7 @@
"panes.n": "ペイン %d",
"paste": "ペースト",
"pinned": "ピン留め",
+ "project.new": "新規プロジェクト",
"reconnect": "再接続",
"rename": "名前を変更",
"resize.auto": "自動",
@@ -787,6 +794,7 @@
"settings": "設定",
"showlog": "ログを表示",
"showlog.foot": "接続ログを端末の上に重ねて表示します。",
+ "sidebar": "サイドバー",
"snip.command": "コマンド",
"snip.enter": "送信後に Enter を押す",
"snip.new": "新しいスニペット",
@@ -968,6 +976,7 @@
"panes.n": "%d 个窗格",
"paste": "粘贴",
"pinned": "已置顶",
+ "project.new": "新建项目",
"reconnect": "重新连接",
"rename": "重命名",
"resize.auto": "自动",
@@ -993,6 +1002,7 @@
"settings": "设置",
"showlog": "显示日志",
"showlog.foot": "把连接日志盖在终端上,方便报问题。",
+ "sidebar": "侧栏",
"snip.command": "命令",
"snip.enter": "发送后按回车",
"snip.new": "新建片段",
diff --git a/ios/Sources/Sidebar.swift b/ios/Sources/Sidebar.swift
new file mode 100644
index 00000000..60b7af3e
--- /dev/null
+++ b/ios/Sources/Sidebar.swift
@@ -0,0 +1,299 @@
+import SwiftUI
+
+/// The desktop's sidebar, as the TUI lays it out: a panel from the left
+/// with the tree — the host, its Spaces, their projects, their threads —
+/// each level folding, New Thread at the top, Settings at the bottom.
+/// Everything is named as the desktop names it.
+struct SidebarPanel: View {
+ @ObservedObject var model: TerminalModel
+ @ObservedObject private var lang = AppLanguage.shared
+ @Binding var isPresented: Bool
+ var hostName: String
+ var connected: Bool
+ var onEditHost: () -> Void
+ var onSettings: () -> Void
+ /// Folded nodes; every Space but the one on show starts folded.
+ @State private var folded: Set<String>?
+ @State private var renaming: (kind: String, id: String)?
+ @State private var renameText = ""
+
+ private var connectionColor: Color {
+ if model.reconnecting { return .orange }
+ if connected { return .green }
+ if model.connection.hasPrefix("connecting") || model.connection.contains("reconnect") { return .orange }
+ return .red
+ }
+
+ var body: some View {
+ ZStack(alignment: .leading) {
+ if isPresented {
+ Color.black.opacity(0.45)
+ .ignoresSafeArea()
+ .onTapGesture { isPresented = false }
+ .transition(.opacity)
+ panel
+ .frame(width: 300)
+ .background(Color(white: 0.09))
+ .ignoresSafeArea(edges: .bottom)
+ .transition(.move(edge: .leading))
+ }
+ }
+ .animation(.easeOut(duration: 0.22), value: isPresented)
+ .onChange(of: isPresented) { _, shown in
+ if shown {
+ model.refreshViews()
+ if folded == nil {
+ folded = Set((model.tree?.spaces ?? []).filter { !$0.current }.map { "space:" + $0.id })
+ }
+ }
+ }
+ .onChange(of: model.sidebar?.editing) { _, editing in
+ guard let editing, editing.kind != "none", let id = editing.id else { return }
+ if renaming == nil {
+ renameText = ""
+ renaming = (editing.kind, id)
+ }
+ }
+ .alert(tr("rename"), isPresented: Binding(get: { renaming != nil }, set: { if !$0 { renaming = nil } })) {
+ TextField(tr("f.name"), text: $renameText)
+ Button(tr("save")) {
+ model.sideKey("Enter", value: renameText)
+ renaming = nil
+ }
+ Button(tr("cancel"), role: .cancel) {
+ model.sideKey("Escape", value: "")
+ renaming = nil
+ }
+ }
+ }
+
+ private func isFolded(_ key: String) -> Bool { folded?.contains(key) ?? false }
+
+ private func toggle(_ key: String) {
+ var set = folded ?? []
+ if set.contains(key) { set.remove(key) } else { set.insert(key) }
+ folded = set
+ }
+
+ private var panel: some View {
+ VStack(spacing: 0) {
+ ScrollView {
+ VStack(alignment: .leading, spacing: 0) {
+ // The host: the root of the tree, and the connection's actions.
+ Menu {
+ Button(connected ? tr("disconnect") : tr("reconnect")) {
+ if connected { model.disconnect() } else { model.connect() }
+ }
+ if model.host != nil {
+ Button(tr("edithost")) { onEditHost() }
+ }
+ } label: {
+ treeRow(depth: 0, expandable: true, collapsed: isFolded("host"), onToggle: { toggle("host") }) {
+ Circle().fill(connectionColor).frame(width: 8, height: 8)
+ Text(hostName).fontWeight(.semibold).lineLimit(1)
+ Spacer(minLength: 0)
+ Image(systemName: "ellipsis").foregroundColor(.secondary)
+ }
+ }
+ .buttonStyle(.plain)
+
+ if !isFolded("host") {
+ Button {
+ model.sideClick("new-thread")
+ isPresented = false
+ } label: {
+ Label(tr("thread.new"), systemImage: "plus")
+ .foregroundColor(.accentColor)
+ .padding(.horizontal, 16)
+ .padding(.vertical, 10)
+ }
+ .buttonStyle(.plain)
+
+ HStack {
+ Text(tr("workspaces").uppercased()).font(.caption2).foregroundColor(.secondary)
+ Spacer()
+ Button { model.sideClick("new-project") } label: {
+ Image(systemName: "plus").font(.caption).foregroundColor(.secondary).frame(width: 28, height: 28)
+ }
+ .buttonStyle(.plain)
+ }
+ .padding(.leading, 16)
+ .padding(.trailing, 4)
+
+ ForEach(model.tree?.spaces ?? []) { space in
+ spaceRows(space)
+ }
+ tailRows
+ if let error = model.sidebar?.new_project_error {
+ Text(error).font(.caption).foregroundColor(.red).padding(.horizontal, 16).padding(.vertical, 8)
+ }
+ }
+ }
+ .padding(.top, 8)
+ }
+ Divider()
+ Button(action: onSettings) {
+ Label(tr("settings"), systemImage: "gearshape")
+ .foregroundColor(.secondary)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .padding(.horizontal, 16)
+ .padding(.vertical, 12)
+ }
+ .buttonStyle(.plain)
+ }
+ .foregroundColor(.white)
+ }
+
+ @ViewBuilder
+ private func spaceRows(_ space: TreeSpace) -> some View {
+ let key = "space:" + space.id
+ treeRow(depth: 1, expandable: !space.projects.isEmpty, collapsed: isFolded(key), onToggle: { toggle(key) }) {
+ Text(space.name).fontWeight(space.current ? .semibold : .regular).lineLimit(1)
+ Spacer(minLength: 0)
+ Button {
+ model.setSpace(space.id)
+ model.sideClick("new-project")
+ } label: {
+ Image(systemName: "plus").font(.caption).foregroundColor(.secondary).frame(width: 28, height: 28)
+ }
+ .buttonStyle(.plain)
+ }
+ .contentShape(Rectangle())
+ .onTapGesture {
+ if !space.current { model.setSpace(space.id) }
+ if isFolded(key) { toggle(key) }
+ }
+ .contextMenu { AppMenuItems(model: model, kind: "space", id: "") }
+ if !isFolded(key) {
+ ForEach(space.projects) { project in
+ projectRows(space, project)
+ }
+ }
+ }
+
+ @ViewBuilder
+ private func projectRows(_ space: TreeSpace, _ project: TreeProject) -> some View {
+ let key = "project:" + project.id
+ treeRow(depth: 2, expandable: !project.threads.isEmpty, collapsed: isFolded(key), onToggle: { toggle(key) }) {
+ Text(project.name).lineLimit(1)
+ Spacer(minLength: 0)
+ Button {
+ model.setSpace(space.id)
+ model.sideClick("new-thread", id: project.id)
+ } label: {
+ Image(systemName: "plus").font(.caption).foregroundColor(.secondary).frame(width: 28, height: 28)
+ }
+ .buttonStyle(.plain)
+ }
+ .contentShape(Rectangle())
+ .onTapGesture { toggle(key) }
+ .contextMenu { AppMenuItems(model: model, kind: "project", id: project.id) }
+ if !isFolded(key) {
+ ForEach(project.threads) { thread in
+ treeRow(depth: 3, expandable: false, collapsed: false, selected: thread.selected, onToggle: {}) {
+ Circle().fill(TerminalScreen.threadColor(status: thread.status, live: thread.live)).frame(width: 8, height: 8)
+ if thread.pinned {
+ Image(systemName: "star.fill").font(.system(size: 9)).foregroundColor(.secondary)
+ }
+ Text(thread.name)
+ .fontWeight(thread.unread || thread.selected ? .semibold : .regular)
+ .foregroundColor(thread.live ? .white : .secondary)
+ .lineLimit(1)
+ Spacer(minLength: 0)
+ }
+ .contentShape(Rectangle())
+ .onTapGesture {
+ model.openThread(thread.id, space: space.id)
+ isPresented = false
+ }
+ .contextMenu { AppMenuItems(model: model, kind: "thread", id: thread.id) }
+ }
+ }
+ }
+
+ /// What the desktop lists after the tree: archived projects of the
+ /// Space on show, and windows no thread claims.
+ @ViewBuilder
+ private var tailRows: some View {
+ let rows = model.sidebar?.rows ?? []
+ let tail = Array(rows.drop(while: { row in
+ if case .archived = row { return false }
+ if case .others = row { return false }
+ return true
+ }))
+ ForEach(tail) { row in
+ switch row {
+ case .archived(let count, let open, let label):
+ Button { model.sideClick("toggle-archived", flag: !open) } label: {
+ HStack(spacing: 6) {
+ Image(systemName: "chevron.right").rotationEffect(.degrees(open ? 90 : 0)).font(.caption)
+ Text("\(label) (\(count))")
+ }
+ .font(.footnote)
+ .foregroundColor(.secondary)
+ .padding(.leading, 16)
+ .padding(.vertical, 6)
+ }
+ .buttonStyle(.plain)
+ case .project(let id, let name, _, _, true):
+ treeRow(depth: 2, expandable: false, collapsed: true, onToggle: {}) {
+ Text(name).foregroundColor(.secondary).lineLimit(1)
+ Spacer(minLength: 0)
+ }
+ .contextMenu { AppMenuItems(model: model, kind: "archived-project", id: id) }
+ case .others:
+ Text(tr("otherwindows").uppercased()).font(.caption2).foregroundColor(.secondary)
+ .padding(.leading, 16).padding(.top, 10).padding(.bottom, 2)
+ case .window(let id, let title, let selected):
+ Button {
+ model.sideClick("window", id: String(id))
+ isPresented = false
+ } label: {
+ HStack(spacing: 8) {
+ Image(systemName: "macwindow").foregroundColor(.secondary)
+ Text(title.isEmpty ? tr("window.n", id) : title).lineLimit(1)
+ Spacer(minLength: 0)
+ }
+ .padding(.horizontal, 16)
+ .padding(.vertical, 8)
+ .background(selected ? Color.accentColor.opacity(0.18) : Color.clear)
+ }
+ .buttonStyle(.plain)
+ default:
+ EmptyView()
+ }
+ }
+ }
+
+ /// One row of the tree: indented by its depth, a fold chevron when it
+ /// has children, and its content.
+ private func treeRow<Content: View>(
+ depth: Int,
+ expandable: Bool,
+ collapsed: Bool,
+ selected: Bool = false,
+ onToggle: @escaping () -> Void,
+ @ViewBuilder content: () -> Content
+ ) -> some View {
+ HStack(spacing: 8) {
+ if expandable {
+ Button(action: onToggle) {
+ Image(systemName: "chevron.down")
+ .font(.caption)
+ .foregroundColor(.secondary)
+ .rotationEffect(.degrees(collapsed ? -90 : 0))
+ .frame(width: 20, height: 20)
+ }
+ .buttonStyle(.plain)
+ } else {
+ Spacer().frame(width: 20)
+ }
+ content()
+ }
+ .padding(.leading, 8 + CGFloat(depth) * 14)
+ .padding(.trailing, 4)
+ .padding(.vertical, 6)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .background(selected ? Color.accentColor.opacity(0.18) : Color.clear)
+ }
+}
diff --git a/ios/Sources/TerminalModel.swift b/ios/Sources/TerminalModel.swift
index 570d5afa..4c7a3e4a 100644
--- a/ios/Sources/TerminalModel.swift
+++ b/ios/Sources/TerminalModel.swift
@@ -20,6 +20,7 @@ final class TerminalModel: ObservableObject, @unchecked Sendable {
/// The last rows of panes the overview asked about, by pane.
@Published var previews: [Int: [PreviewRow]] = [:]
@Published var sidebar: SidebarView?
+ @Published var tree: TreeView?
@Published var navs: [NavView] = []
@Published var status: StatusView?
@Published var title = ""
@@ -339,6 +340,15 @@ final class TerminalModel: ObservableObject, @unchecked Sendable {
core.sideKey(key: key, value: value)
}
+ /// Show a thread, switching the Space on show to its own first when
+ /// it is in another one, so the strips follow.
+ func openThread(_ id: String, space: String?) {
+ if let space, tree?.spaces.first(where: { $0.current })?.id != space { core.setSpace(id: space) }
+ sideClick("thread", id: id)
+ }
+
+ func setSpace(_ id: String) { core.setSpace(id: id) }
+
func contextMenu(_ kind: String, id: String) -> [MenuItem] {
ViewJSON.decode([MenuItem].self, core.contextMenu(kind: kind, id: id)) ?? []
}
@@ -368,6 +378,8 @@ final class TerminalModel: ObservableObject, @unchecked Sendable {
if sidebar != self.sidebar { self.sidebar = sidebar }
let threads = ViewJSON.decode(ThreadsView.self, core.view(name: "threads"))
if threads != self.threads { self.threads = threads }
+ let tree = ViewJSON.decode(TreeView.self, core.view(name: "tree"))
+ if tree != self.tree { self.tree = tree }
let navs = ViewJSON.decode([NavView].self, core.view(name: "navs")) ?? []
if navs != self.navs { self.navs = navs }
let status = ViewJSON.decode(StatusView.self, core.view(name: "status"))
diff --git a/ios/Sources/TerminalScreen.swift b/ios/Sources/TerminalScreen.swift
index 2b25218f..1de08f95 100644
--- a/ios/Sources/TerminalScreen.swift
+++ b/ios/Sources/TerminalScreen.swift
@@ -125,6 +125,16 @@ struct TerminalScreen: View {
.zIndex(1)
.allowsHitTesting(!overviewOpen)
}
+ .overlay {
+ SidebarPanel(
+ model: model,
+ isPresented: $showTree,
+ hostName: hostName,
+ connected: connected,
+ onEditHost: { showTree = false; editingHost = model.host },
+ onSettings: { showTree = false; showSettings = true }
+ )
+ }
.coordinateSpace(name: "screen")
.background(overviewOpen ? Color(white: 0.06) : model.background)
.background(GeometryReader { geo in
@@ -159,12 +169,6 @@ struct TerminalScreen: View {
}
}
.ignoresSafeArea(.container, edges: .bottom)
- .sheet(isPresented: $showTree) {
- TreeSheet(model: model, isPresented: $showTree, menu: $menu, hostName: hostName, connected: connected, onEditHost: {
- showTree = false
- editingHost = model.host
- })
- }
.sheet(isPresented: $showSettings) {
NavigationStack {
SettingsView(model: model, showLog: $showLog)
diff --git a/ios/Sources/TreeSheet.swift b/ios/Sources/TreeSheet.swift
index 92a540e1..58cd5f02 100644
--- a/ios/Sources/TreeSheet.swift
+++ b/ios/Sources/TreeSheet.swift
@@ -1,210 +1,5 @@
import SwiftUI
-/// The desktop's sidebar and tab strip in one list, the way both are on
-/// screen at once on the desktop: the Space, its pinned threads, its
-/// projects with their threads, as far as the desktop's sidebar goes;
-/// under a tab with several panes, its panes. Everything is named as the
-/// desktop names it: thread, tab, pane.
-struct TreeSheet: View {
- @ObservedObject var model: TerminalModel
- @ObservedObject private var lang = AppLanguage.shared
- @Binding var isPresented: Bool
- @Binding var menu: MenuSheet?
- /// The host this sheet belongs to, and what can be done with its
- /// connection (this used to be a dot in the bar).
- var hostName: String = ""
- var connected: Bool = true
- var onEditHost: () -> Void = {}
- @State private var spaceMenu: [MenuItem] = []
- @State private var renaming: (kind: String, id: String)?
- @State private var renameText = ""
-
- private var threads: [ThreadView] { model.threads?.threads ?? [] }
-
- private var connectionColor: Color {
- if model.reconnecting { return .orange }
- if connected { return .green }
- if model.connection.hasPrefix("connecting") || model.connection.contains("reconnect") { return .orange }
- return .red
- }
-
- var body: some View {
- NavigationStack {
- List {
- Section {
- Menu {
- Button(connected ? tr("disconnect") : tr("reconnect")) {
- if connected { model.disconnect() } else { model.connect() }
- }
- if model.host != nil {
- Button(tr("edithost")) { onEditHost() }
- }
- } label: {
- HStack(spacing: 8) {
- Circle().fill(connectionColor).frame(width: 8, height: 8)
- Text(hostName).lineLimit(1)
- Spacer()
- Text(connected ? tr("disconnect") : tr("reconnect")).font(.subheadline).foregroundColor(.accentColor)
- }
- }
- }
- ForEach(model.sidebar?.rows ?? []) { row in
- rowView(row)
- }
- if let error = model.sidebar?.new_project_error {
- Text(error).font(.caption).foregroundColor(.red)
- }
- }
- .listStyle(.plain)
- .navigationTitle(tr("threads"))
- .navigationBarTitleDisplayMode(.inline)
- .toolbar {
- ToolbarItem(placement: .cancellationAction) {
- Button(tr("done")) { isPresented = false }
- }
- ToolbarItemGroup(placement: .topBarTrailing) {
- Menu {
- ForEach(spaceMenu, id: \.rowId) { item in
- if item.kind == "item" {
- Button {
- model.menuAction(item.id)
- reloadSpaces()
- } label: {
- Label(item.label, systemImage: item.checked ? "checkmark" : "")
- }
- }
- }
- } label: { Image(systemName: "square.stack.3d.up") }
- Button { model.chromeClick("new-tab") } label: { Image(systemName: "plus") }
- }
- }
- .alert(tr("rename"), isPresented: Binding(get: { renaming != nil }, set: { if !$0 { renaming = nil } })) {
- TextField(tr("f.name"), text: $renameText)
- Button(tr("save")) {
- model.sideKey("Enter", value: renameText)
- renaming = nil
- }
- Button(tr("cancel"), role: .cancel) {
- model.sideKey("Escape", value: "")
- renaming = nil
- }
- }
- }
- .onAppear {
- model.refreshViews()
- reloadSpaces()
- }
- .onChange(of: model.sidebar?.editing) { _, editing in
- guard let editing, editing.kind != "none", let id = editing.id else { return }
- if renaming == nil {
- renameText = ""
- renaming = (editing.kind, id)
- }
- }
- }
-
- private func reloadSpaces() {
- spaceMenu = model.contextMenu("space", id: "")
- }
-
- @ViewBuilder
- private func rowView(_ row: SideRow) -> some View {
- switch row {
- case .space(_, let name):
- Text(name).font(.headline)
- case .newThread:
- Button { model.sideClick("new-thread") } label: {
- Label(tr("thread.new"), systemImage: "plus").foregroundColor(.accentColor)
- }
- case .pinned:
- caption(tr("pinned"))
- case .workspaces:
- caption(tr("workspaces"))
- case .project(let id, let name, let path, let collapsed, let archived):
- HStack {
- Button { model.sideClick("toggle-project", id: id) } label: {
- Image(systemName: "chevron.right")
- .rotationEffect(.degrees(collapsed ? 0 : 90))
- .foregroundColor(.secondary)
- .font(.caption)
- }
- .buttonStyle(.plain)
- VStack(alignment: .leading, spacing: 1) {
- Text(name).font(.subheadline.weight(.semibold))
- Text(path).font(.caption2).foregroundColor(.secondary).lineLimit(1)
- }
- Spacer()
- if !archived {
- Button { model.sideClick("new-thread", id: id) } label: { Image(systemName: "plus") }
- .buttonStyle(.plain)
- .foregroundColor(.accentColor)
- }
- }
- .contextMenu {
- AppMenuItems(model: model, kind: archived ? "archived-project" : "project", id: id)
- }
- case .thread(let t):
- if let thread = threads.first(where: { $0.id == t.id }) {
- threadRows(thread, indent: t.project.isEmpty ? 0 : 14)
- } else {
- Text(t.name)
- }
- case .archived(let count, let open, let label):
- Button { model.sideClick("toggle-archived", flag: !open) } label: {
- HStack {
- Image(systemName: "chevron.right").rotationEffect(.degrees(open ? 90 : 0)).font(.caption)
- Text("\(label) (\(count))")
- }
- .font(.footnote)
- .foregroundColor(.secondary)
- }
- case .others:
- caption(tr("otherwindows"))
- case .window(let id, let title, let selected):
- Button { model.sideClick("window", id: String(id)) } label: {
- HStack {
- Image(systemName: "macwindow").foregroundColor(.secondary)
- Text(title.isEmpty ? tr("window.n", id) : title)
- }
- }
- .listRowBackground(selected ? Color.accentColor.opacity(0.2) : nil)
- }
- }
-
- private func caption(_ text: String) -> some View {
- Text(text.uppercased()).font(.caption2).foregroundColor(.secondary).padding(.top, 6)
- }
-
- /// A thread, and when open, its tabs under it.
- @ViewBuilder
- private func threadRows(_ thread: ThreadView, indent: CGFloat) -> some View {
- HStack(spacing: 8) {
- Circle().fill(TerminalScreen.threadColor(status: thread.status, live: thread.live)).frame(width: 8, height: 8)
- Button {
- model.sideClick("thread", id: thread.id)
- isPresented = false
- } label: {
- Text(thread.name)
- .fontWeight(thread.unread ? .semibold : .regular)
- .frame(maxWidth: .infinity, alignment: .leading)
- }
- .buttonStyle(.plain)
- if thread.pinned {
- Image(systemName: "pin").font(.caption).foregroundColor(.secondary)
- }
- if !thread.live {
- Text(tr("thread.off")).font(.caption2).foregroundColor(.secondary)
- }
- }
- .padding(.leading, indent)
- .listRowBackground(thread.current ? Color.accentColor.opacity(0.18) : nil)
- .contextMenu {
- AppMenuItems(model: model, kind: "thread", id: thread.id)
- }
- }
-
-}
-
/// The desktop's Live Overview as an overlay under the terminal: a card
/// per thread, grouped by project, two to a row. Each card is the
/// thread's name and state with its current tab's title,
diff --git a/ios/Sources/Views.swift b/ios/Sources/Views.swift
index 19805f68..9c044247 100644
--- a/ios/Sources/Views.swift
+++ b/ios/Sources/Views.swift
@@ -93,6 +93,25 @@ struct PaneRef: Decodable, Hashable, Identifiable {
var id: Int { pane }
}
+/// The tree whole, every Space with its projects and threads: `App::tree_view`.
+struct TreeView: Decodable, Hashable {
+ var spaces: [TreeSpace]
+}
+
+struct TreeSpace: Decodable, Hashable, Identifiable {
+ var id: String
+ var name: String
+ var current: Bool
+ var projects: [TreeProject]
+}
+
+struct TreeProject: Decodable, Hashable, Identifiable {
+ var id: String
+ var name: String
+ var path: String
+ var threads: [ThreadRow]
+}
+
/// A thumbnail row: `App::PreviewRow`.
struct PreviewRow: Decodable, Hashable {
var runs: [PreviewRun]
@@ -188,7 +207,7 @@ enum SideRow: Decodable, Hashable, Identifiable {
}
}
-struct ThreadRow: Decodable, Hashable {
+struct ThreadRow: Decodable, Hashable, Identifiable {
var id: String
var project: String
var name: String
diff --git a/ios/tools/gen-strings.py b/ios/tools/gen-strings.py
index b4ae73fb..6f59fcd1 100644
--- a/ios/tools/gen-strings.py
+++ b/ios/tools/gen-strings.py
@@ -28,6 +28,8 @@ EXTRA = {
"ok": ["OK", "好", "OK", "OK", "OK"],
"copy": ["Copy", "复制", "コピー", "Copier", "Kopieren"],
"p.layout": ["Layout", "布局", "レイアウト", "Disposition", "Layout"],
+ "project.new": ["New project", "新建项目", "新規プロジェクト", "Nouveau projet", "Neues Projekt"],
+ "sidebar": ["Sidebar", "侧栏", "サイドバー", "Barre latérale", "Seitenleiste"],
"thread.delete.title": ["Delete “%@”?", "删除“%@”?", "「%@」を削除しますか?", "Supprimer « %@ » ?", "„%@“ löschen?"],
"thread.delete.body": [
"Its tabs close and the programs in them end.",
diff --git a/thinkterm-mobile/src/core.rs b/thinkterm-mobile/src/core.rs
index 9aabaef7..3bf3763b 100644
--- a/thinkterm-mobile/src/core.rs
+++ b/thinkterm-mobile/src/core.rs
@@ -578,6 +578,7 @@ impl State {
match name {
"tabs" => json(&app.tabs_view()),
"threads" => json(&app.threads_view()),
+ "tree" => json(&app.tree_view()),
"sidebar" => json(&app.sidebar_view()),
"navs" => json(&app.navs_view()),
"status" => json(&app.status_view()),
diff --git a/thinkterm-web/src/app.rs b/thinkterm-web/src/app.rs
index 45f85341..68a3fec0 100644
--- a/thinkterm-web/src/app.rs
+++ b/thinkterm-web/src/app.rs
@@ -2645,12 +2645,21 @@ impl<P: Platform, L: Link> App<P, L> {
/// The sidebar's rows from the model, with the pending delete shown.
fn side_rows(inner: &Inner<P, L>) -> Vec<crate::tree::Row> {
- let deleting = inner
+ inner.tree.rows_with(inner.tab_id, &inner.workspace, inner.window_id, Self::deleting(inner))
+ }
+
+ fn deleting(inner: &Inner<P, L>) -> Option<&str> {
+ inner
.deleting
.as_ref()
.filter(|(_, since)| inner.platform.monotonic_ms() - since < CLOSE_CONFIRM_MS)
- .map(|(id, _)| id.as_str());
- inner.tree.rows_with(inner.tab_id, &inner.workspace, inner.window_id, deleting)
+ .map(|(id, _)| id.as_str())
+ }
+
+ /// Every Space with its projects and threads: the TUI's sidebar tree.
+ pub fn tree_view(&self) -> crate::tree::TreeView {
+ let inner = self.inner.borrow();
+ inner.tree.tree(inner.tab_id, &inner.workspace, Self::deleting(&inner))
}
/// Ask the server for its tree, its session view and the agents in
diff --git a/thinkterm-web/src/tree.rs b/thinkterm-web/src/tree.rs
index 0fcc08de..3cddd28c 100644
--- a/thinkterm-web/src/tree.rs
+++ b/thinkterm-web/src/tree.rs
@@ -67,6 +67,28 @@ pub struct ThreadRow {
pub deleting: bool,
}
+/// The tree whole: `TreeModel::tree`.
+#[derive(Debug, Clone, PartialEq, Default, serde::Serialize)]
+pub struct TreeView {
+ pub spaces: Vec<TreeSpace>,
+}
+
+#[derive(Debug, Clone, PartialEq, serde::Serialize)]
+pub struct TreeSpace {
+ pub id: String,
+ pub name: String,
+ pub current: bool,
+ pub projects: Vec<TreeProject>,
+}
+
+#[derive(Debug, Clone, PartialEq, serde::Serialize)]
+pub struct TreeProject {
+ pub id: String,
+ pub name: String,
+ pub path: String,
+ pub threads: Vec<ThreadRow>,
+}
+
/// A Space as the Space menu lists it.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SpaceEntry {
@@ -229,6 +251,72 @@ impl TreeModel {
.or(thread.planned_workspace_name.as_deref())
}
+ fn thread_row(
+ &self,
+ t: &ThinkTermSessionThread,
+ project_id: &str,
+ selected: Option<&str>,
+ deleting: Option<&str>,
+ ) -> ThreadRow {
+ let live = !t.tabs.is_empty();
+ let is_selected = selected == Some(t.id.as_str());
+ let dot = if is_selected {
+ Dot::Active
+ } else if t.is_unread {
+ Dot::Unread
+ } else if t.is_pinned {
+ Dot::Pinned
+ } else if live {
+ Dot::Open
+ } else {
+ Dot::Quiet
+ };
+ ThreadRow {
+ id: t.id.clone(),
+ project_id: project_id.to_string(),
+ name: t.name.clone(),
+ status: self.status_of(t),
+ dot,
+ pinned: t.is_pinned,
+ unread: t.is_unread,
+ live,
+ selected: is_selected,
+ deleting: deleting == Some(t.id.as_str()),
+ }
+ }
+
+ /// The whole tree, every Space with its projects and their threads,
+ /// as the TUI's sidebar shows it; `rows` is one Space of it flattened
+ /// the desktop's way.
+ pub fn tree(&self, current_tab: TabId, current_workspace: &str, deleting: Option<&str>) -> TreeView {
+ let Some(session) = &self.session else {
+ return TreeView::default();
+ };
+ let selected = self.selected_thread(current_tab, current_workspace);
+ let current = self.current_space().map(|s| s.id.clone()).unwrap_or_default();
+ let spaces = session
+ .spaces
+ .iter()
+ .map(|space| TreeSpace {
+ id: space.id.clone(),
+ name: space.name.clone(),
+ current: space.id == current,
+ projects: session
+ .projects
+ .iter()
+ .filter(|p| p.space_id == space.id)
+ .map(|p| TreeProject {
+ id: p.id.clone(),
+ name: p.name.clone(),
+ path: p.path.clone(),
+ threads: p.threads.iter().map(|t| self.thread_row(t, &p.id, selected, deleting)).collect(),
+ })
+ .collect(),
+ })
+ .collect();
+ TreeView { spaces }
+ }
+
/// The worst of what the thread's panes are doing, the desktop's way:
/// an agent waiting on someone, or a program that failed, outranks
/// one still working, which outranks having finished unseen.
@@ -344,33 +432,7 @@ impl TreeModel {
});
rows.push(Row::NewThread);
let in_space = |p: &&codec::ThinkTermSessionProject| p.space_id == space_id;
- let thread_row = |t: &ThinkTermSessionThread, project_id: &str| {
- let live = !t.tabs.is_empty();
- let is_selected = selected == Some(t.id.as_str());
- let dot = if is_selected {
- Dot::Active
- } else if t.is_unread {
- Dot::Unread
- } else if t.is_pinned {
- Dot::Pinned
- } else if live {
- Dot::Open
- } else {
- Dot::Quiet
- };
- Row::Thread(ThreadRow {
- id: t.id.clone(),
- project_id: project_id.to_string(),
- name: t.name.clone(),
- status: self.status_of(t),
- dot,
- pinned: t.is_pinned,
- unread: t.is_unread,
- live,
- selected: is_selected,
- deleting: deleting == Some(t.id.as_str()),
- })
- };
+ let thread_row = |t: &ThinkTermSessionThread, project_id: &str| Row::Thread(self.thread_row(t, project_id, selected, deleting));
let pinned: Vec<Row> = session
.projects
.iter()