Skip to content

Commit ed5247f

Browse files
feat(terminal): redesign workspace tabs and distro launcher
Show open shells in a compact tab strip with direct switching and long-press actions. Give closing tabs progress feedback and block input to the closing session. Preserve shell-provided titles and render each session’s OSC background within the terminal bounds.
1 parent 92a9398 commit ed5247f

9 files changed

Lines changed: 571 additions & 547 deletions

File tree

‎app/src/main/java/org/randomcoder/udroid/runtime/RuntimeSupervisorService.kt‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class RuntimeSupervisorService : Service() {
9292

9393
private val terminalClient =
9494
object : TerminalSessionClient {
95+
override fun acceptsTerminalInput(session: TerminalSession): Boolean =
96+
terminalTabs.acceptsInput(session.mHandle)
97+
9598
override fun onTextChanged(changedSession: TerminalSession) {
9699
attachedViews
97100
.filter { it.mTermSession === changedSession }
@@ -333,6 +336,7 @@ class RuntimeSupervisorService : Service() {
333336
TerminalTabSnapshot(
334337
id = tab.id,
335338
title = tab.title,
339+
shortTitle = tab.shortTitle,
336340
hasCustomTitle = tab.customTitle != null,
337341
rootfsName = tab.rootfsName,
338342
pid = tab.value.pid.takeIf { it > 0 }?.toLong(),
@@ -464,11 +468,7 @@ class RuntimeSupervisorService : Service() {
464468

465469
fun selectTerminalTab(id: String): Boolean {
466470
val requested = terminalTabs.get(id) ?: return false
467-
if (requested.closeState == TerminalTabCloseState.CLOSING ||
468-
requested.closeState == TerminalTabCloseState.FORCE_CLOSING
469-
) {
470-
return false
471-
}
471+
if (requested.closeState.isClosing) return false
472472
val tab = terminalTabs.select(id) ?: return false
473473
attachedViews.forEach { view ->
474474
if (view.mTermSession !== tab.value) view.attachSession(tab.value)
@@ -709,6 +709,10 @@ class RuntimeSupervisorService : Service() {
709709
return
710710
}
711711
if (application.terminal) {
712+
if (!terminalTabs.acceptsInput(terminalTabs.activeId)) {
713+
callback(Result.failure(IllegalStateException("This terminal is closing")))
714+
return
715+
}
712716
val arguments = listOf(application.executable) + application.arguments
713717
val command =
714718
arguments

‎app/src/main/java/org/randomcoder/udroid/runtime/TerminalTabs.kt‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.randomcoder.udroid.runtime
33
data class TerminalTabSnapshot(
44
val id: String,
55
val title: String,
6+
val shortTitle: String,
67
val hasCustomTitle: Boolean,
78
val rootfsName: String,
89
val pid: Long?,
@@ -17,7 +18,10 @@ enum class TerminalTabCloseState {
1718
OPEN,
1819
CLOSING,
1920
FORCE_CLOSING,
20-
FAILED,
21+
FAILED;
22+
23+
val isClosing: Boolean
24+
get() = this == CLOSING || this == FORCE_CLOSING
2125
}
2226

2327
fun terminalDistroTitle(rawName: String?): String =
@@ -30,6 +34,7 @@ fun terminalDistroTitle(rawName: String?): String =
3034
else ->
3135
rawName
3236
.removePrefix("udroid-")
37+
.removePrefix("proot-")
3338
.removeSuffix("-raw")
3439
.split('-')
3540
.joinToString(" ") { word -> word.replaceFirstChar(Char::titlecase) }
@@ -52,6 +57,9 @@ internal data class TerminalTab<T>(
5257

5358
val title: String
5459
get() = customTitle ?: shellTitle ?: defaultTitle
60+
61+
val shortTitle: String
62+
get() = customTitle ?: shellTitle ?: defaultTitle.takeUnless { it == terminalDistroTitle(rootfsName) } ?: "Shell"
5563
}
5664

5765
internal class TerminalTabRegistry<T> {
@@ -68,6 +76,8 @@ internal class TerminalTabRegistry<T> {
6876

6977
fun get(id: String): TerminalTab<T>? = tabs[id]
7078

79+
fun acceptsInput(id: String?): Boolean = tabs[id]?.closeState?.isClosing == false
80+
7181
fun findByValue(value: T): TerminalTab<T>? =
7282
tabs.values.firstOrNull { it.value === value }
7383

@@ -137,11 +147,7 @@ internal class TerminalTabRegistry<T> {
137147

138148
fun beginClose(id: String): TerminalTab<T>? {
139149
val tab = tabs[id] ?: return null
140-
if (tab.closeState == TerminalTabCloseState.CLOSING ||
141-
tab.closeState == TerminalTabCloseState.FORCE_CLOSING
142-
) {
143-
return null
144-
}
150+
if (tab.closeState.isClosing) return null
145151
tab.closeState = TerminalTabCloseState.CLOSING
146152
tab.closeError = null
147153
return tab

0 commit comments

Comments
 (0)