UI: the terminal's top bar showed again; screenshots of every tab

- TerminalView filled its background with drawColor(), which fills the
  clip it is given: it could paint over the Compose bar above it (the
  terminal's status, keyboard, snippets, capture and menu).  It fills its
  own bounds now.
- The Modem tab's console turned the modem's echoed CR (ATX3\r\r\n) into
  a blank line: a lone CR is dropped there now.
- ScreenshotsTest: every tab drawn with Robolectric's native graphics into
  app/build/screens/ (Compose UI test).

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 16:16:16 +00:00
1 parent 0564a2dea5
commit 303aa556db
5 files changed
+74 -2

No files matched your search

+3
View File
@@ -91,6 +91,9 @@ dependencies {
testImplementation(libs.junit)
testImplementation(libs.robolectric)
testImplementation(libs.androidx.test.core)
testImplementation(platform(libs.compose.bom))
testImplementation(libs.compose.ui.test.junit4)
debugImplementation(libs.compose.ui.test.manifest)
androidTestImplementation(libs.androidx.test.runner)
androidTestImplementation(libs.androidx.test.ext.junit)
}
@@ -192,7 +192,9 @@ class TerminalView @JvmOverloads constructor(
}
override fun onDraw(canvas: Canvas) {
canvas.drawColor(if (reverse()) theme.fgArgb else theme.bgArgb)
// (the view's own bounds: drawColor() would fill whatever clip it was given)
fillPaint.color = if (reverse()) theme.fgArgb else theme.bgArgb
canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), fillPaint)
val s = session ?: return
val e = s.emulator
synchronized(e) {
@@ -104,7 +104,8 @@ private fun ConsoleText(text: String, modifier: Modifier) {
LaunchedEffect(text) { scroll.scrollTo(scroll.maxValue) }
Card(modifier) {
Text(
text.replace("\r\n", "\n").replace('\r', '\n'),
// (CR LF a line's end; a CR alone, the modem's echo of one, nothing)
text.replace("\r\n", "\n").replace("\r", ""),
fontFamily = FontFamily.Monospace,
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.fillMaxSize().padding(8.dp).verticalScroll(scroll),
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (C) 2026 Neo-Desktop
package com.neodesktop.dmodem.ui
import android.graphics.Bitmap
import androidx.compose.ui.graphics.asAndroidBitmap
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.neodesktop.dmodem.modem.ModemState
import com.neodesktop.dmodem.terminal.Terminal
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
import java.io.File
/** The app's screens drawn (Robolectric's native graphics), into build/screens/ to look at. */
@RunWith(RobolectricTestRunner::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
@Config(sdk = [35], qualifiers = "w411dp-h891dp-xxhdpi")
class ScreenshotsTest {
@get:Rule
val compose = createAndroidComposeRule<MainActivity>()
private fun shot(name: String) {
compose.waitForIdle()
val bmp = compose.onRoot().captureToImage().asAndroidBitmap()
val dir = File("build/screens").apply { mkdirs() }
File(dir, "$name.png").outputStream().use { bmp.compress(Bitmap.CompressFormat.PNG, 100, it) }
}
@Test
fun screens() {
// some text from a "modem" for the console and the terminal
ModemState.console.append("ATX3\r\r\nOK\r\nATD5551234\r\r\nCONNECT 52000/V92\r\n")
ModemState.log.add("dmodem0: created: 8000 Hz, USA")
ModemState.log.add("sip: SIP on 192.168.1.20:5060 (wlan0)")
ModemState.log.add("sip: registered with sip.example.com (200 OK)")
synchronized(Terminal.session.emulator) {
Terminal.session.emulator.appendText(
"\u001b[1;37;44m╔══════════════════════════════╗\u001b[0m\r\n" +
"\u001b[1;37;44m║ Welcome to D-Modem BBS ║\u001b[0m\r\n" +
"\u001b[1;37;44m╚══════════════════════════════╝\u001b[0m\r\n" +
"\u001b[33m[M]\u001b[0messages \u001b[33m[F]\u001b[0miles \u001b[33m[G]\u001b[0moodbye\r\n" +
"\u001b[32mSelect:\u001b[0m ",
)
}
shot("1-modem")
compose.onNodeWithText("Terminal").performClick()
shot("2-terminal")
compose.onNodeWithText("Dial").performClick()
shot("3-dial")
compose.onNodeWithText("Settings").performClick()
shot("4-settings")
compose.onNodeWithText("Log").performClick()
shot("5-log")
}
}
+2
View File
@@ -24,6 +24,8 @@ compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview"
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" }
compose-material3 = { module = "androidx.compose.material3:material3" }
compose-material-icons = { module = "androidx.compose.material:material-icons-core" }
compose-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4" }
compose-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest" }
junit = { module = "junit:junit", version.ref = "junit" }
robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }
androidx-test-core = { module = "androidx.test:core", version.ref = "androidxTestCore" }