Local and Linux shells: the session listens before the shell starts (its first prompt was sometimes lost); ZMODEM: escapes in skipped data aren't a cancel

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs
This commit is contained in:
Claude committed 2026-10-16 23:37:54 +00:00
1 parent be435b52fa
commit 1f1e68751c
2 files changed
+17 -8

No files matched your search

@@ -166,13 +166,15 @@ object Terminal {
suspend fun openLocal(context: Context): String? {
val (cols, rows) = synchronized(session.emulator) { session.emulator.cols to session.emulator.rows }
val link = withContext(Dispatchers.IO) { localShell(context).link(cols, rows) }
if (!withContext(Dispatchers.IO) { link.start() }) {
return (link.state.value as? TerminalLink.State.Closed)?.reason ?: "the shell didn't start"
}
val n = _sessions.value.count { it.kind == TerminalSession.Kind.LOCAL }
// (the session listening before the shell starts: its first prompt not lost)
val s = TerminalSession(link, label = if (n == 0) "Shell" else "Shell ${n + 1}", kind = TerminalSession.Kind.LOCAL) {
app.getExternalFilesDir("captures")
}
if (!withContext(Dispatchers.IO) { link.start() }) {
s.close()
return (link.state.value as? TerminalLink.State.Closed)?.reason ?: "the shell didn't start"
}
s.charset = TermCharset.UTF8
s.keys.backspace = BackspaceMode.DEL
s.keys.enter = com.neodesktop.dmodem.terminal.EnterMode.CR
@@ -192,17 +194,19 @@ object Terminal {
} catch (e: java.io.IOException) {
return e.message
}
if (!withContext(Dispatchers.IO) { link.start() }) {
return (link.state.value as? TerminalLink.State.Closed)?.reason ?: "Linux didn't start"
}
// (the tab: the distribution's name without its version, numbered when there are more)
val short = sys.name.replace(Regex("\\s+[0-9(].*$"), "").removeSuffix(" Linux").ifEmpty { sys.name }
val n = _sessions.value.count { it.linuxId == id }
// (listening before the shell starts: its first prompt not lost)
val s = TerminalSession(
link, label = if (n == 0) short else "$short ${n + 1}", kind = TerminalSession.Kind.LINUX, linuxId = id,
) {
app.getExternalFilesDir("captures")
}
if (!withContext(Dispatchers.IO) { link.start() }) {
s.close()
return (link.state.value as? TerminalLink.State.Closed)?.reason ?: "Linux didn't start"
}
s.charset = TermCharset.UTF8
s.keys.backspace = BackspaceMode.DEL
s.keys.enter = com.neodesktop.dmodem.terminal.EnterMode.CR
@@ -166,8 +166,13 @@ class ZModem(
continue
}
val kind = readByte() and 0x7f
// (the ZDLE before a header is also a CAN: one isn't a cancel)
if (kind == CAN) { cans = 2; continue }
// (the ZDLE before a header is also a CAN: one isn't a cancel; a cancel is
// CANs in a row, and an escape in skipped data, ZDLE then a letter, is none)
if (kind == CAN) {
if (++cans >= 5) throw TransferCancelled("cancelled by the other side")
continue
}
cans = 0
return when (kind) {
'A'.code -> readBinHeader(false)
'C'.code -> readBinHeader(true)