diff --git a/build.gradle.kts b/build.gradle.kts index 7b66ab9..dba0dd5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,4 +14,4 @@ repositories { mavenCentral() } -version = PhoebenchVersion(1, 2, 0, "") \ No newline at end of file +version = PhoebenchVersion(1, 2, 1, "") \ No newline at end of file diff --git a/clients/cli/src/main/kotlin/com/jaytux/phoebench/clients/cli/AuthHandlers.kt b/clients/cli/src/main/kotlin/com/jaytux/phoebench/clients/cli/AuthHandlers.kt index 3b884aa..c55f8dd 100644 --- a/clients/cli/src/main/kotlin/com/jaytux/phoebench/clients/cli/AuthHandlers.kt +++ b/clients/cli/src/main/kotlin/com/jaytux/phoebench/clients/cli/AuthHandlers.kt @@ -6,16 +6,21 @@ import kotlin.system.exitProcess import kotlin.uuid.Uuid object AuthHandlers { + suspend fun checkServer() = + Client.callRoute(Routes.handshake, EmptyRequest()).bind { handshake -> + if(handshake.version != ProtocolVersion.VERSION) { + val server = Client.getServer() ?: "" + Client.onClearServer() + ErrorResponse("Cannot use $server: protocol version mismatch (server: ${handshake.version}, expected: ${ProtocolVersion.VERSION})").error() + } + Unit.value() + } + fun serverPrompt(server: String?): Either { val useServer = server.maybePrompt("server") { it } Client.onSelectServer(useServer) return runBlocking { - Client.callRoute(Routes.handshake, EmptyRequest()).bind { handshake -> - if (handshake.version != ProtocolVersion.VERSION) { - Client.onClearServer() - ErrorResponse("Mismatched protocol version (server: ${handshake.version}, client: ${ProtocolVersion.VERSION})").error() - } else Client.onSelectServer(useServer).value() - } + checkServer().bind { Client.onSelectServer(useServer).value() } } } diff --git a/clients/compose/src/commonMain/kotlin/com/jaytux/phoebench/clients/ui/HomeView.kt b/clients/compose/src/commonMain/kotlin/com/jaytux/phoebench/clients/ui/HomeView.kt index 7825a91..51dd04a 100644 --- a/clients/compose/src/commonMain/kotlin/com/jaytux/phoebench/clients/ui/HomeView.kt +++ b/clients/compose/src/commonMain/kotlin/com/jaytux/phoebench/clients/ui/HomeView.kt @@ -25,6 +25,7 @@ import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton +import androidx.compose.material3.LocalContentColor import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Scaffold @@ -237,10 +238,12 @@ fun SignupView(server: String?, error: String?, onSwitchLogin: () -> Unit, onSig @Composable fun AuthenticatedRoot() { val snacks = SnackProvider.get() + val auth = AuthProvider.get() val state = remember { SnackbarHostState() } val vm = viewModel { HomeVM() } var loggingOut by remember { mutableStateOf(false) } var currentProject by remember { mutableStateOf(null) } + val server by auth.server LaunchedEffect(snacks) { snacks.snacks.collect { state.showSnackbar(it) } @@ -254,7 +257,12 @@ fun AuthenticatedRoot() { Scaffold( topBar = { TopAppBar( - title = { Text("PhoeBench v${ClientVersion.VERSION}", style = MaterialTheme.typography.headlineLarge) }, + title = { + Column { + Text("PhoeBench v${ClientVersion.VERSION}", style = MaterialTheme.typography.headlineLarge) + server?.let { Text("Connected to $it", style = MaterialTheme.typography.bodySmall, color = LocalContentColor.current.copy(0.6f)) } + } + }, colors = TopAppBarDefaults.topAppBarColors( containerColor = MaterialTheme.colorScheme.primaryContainer, titleContentColor = MaterialTheme.colorScheme.onPrimaryContainer diff --git a/clients/compose/src/commonMain/kotlin/com/jaytux/phoebench/clients/ui/ProjectView.kt b/clients/compose/src/commonMain/kotlin/com/jaytux/phoebench/clients/ui/ProjectView.kt index 6233ce1..8f4525b 100644 --- a/clients/compose/src/commonMain/kotlin/com/jaytux/phoebench/clients/ui/ProjectView.kt +++ b/clients/compose/src/commonMain/kotlin/com/jaytux/phoebench/clients/ui/ProjectView.kt @@ -133,24 +133,20 @@ fun MonitorMessage(msg: ServerMonitorEvent.ITextEvent) = when(msg) { val weight = if(ANSI.BOLD in ansi) FontWeight.Bold else null val decoration = if(ANSI.UNDERLINE in ansi) TextDecoration.Underline else null val color = when { - ANSI.FG_BLACK in ansi -> Color.Black ANSI.FG_RED in ansi -> Color.Red ANSI.FG_GREEN in ansi -> Color.Green ANSI.FG_YELLOW in ansi -> Color.Yellow ANSI.FG_BLUE in ansi -> Color.Blue - ANSI.FG_MAGENTA in ansi -> Color.Magenta - ANSI.FG_CYAN in ansi -> Color.Cyan + ANSI.FG_GRAY in ansi -> Color.Gray else -> LocalContentColor.current } val background = when { - ANSI.BG_BLACK in ansi -> Color.Black ANSI.BG_RED in ansi -> Color.Red ANSI.BG_GREEN in ansi -> Color.Green ANSI.BG_YELLOW in ansi -> Color.Yellow ANSI.BG_BLUE in ansi -> Color.Blue - ANSI.BG_MAGENTA in ansi -> Color.Magenta - ANSI.BG_CYAN in ansi -> Color.Cyan + ANSI.BG_GRAY in ansi -> Color.Gray else -> null }?.let { Modifier.background(it) } ?: Modifier diff --git a/common/src/commonMain/kotlin/com/jaytux/phoebench/common/Events.kt b/common/src/commonMain/kotlin/com/jaytux/phoebench/common/Events.kt index 232d6bf..c603e9d 100644 --- a/common/src/commonMain/kotlin/com/jaytux/phoebench/common/Events.kt +++ b/common/src/commonMain/kotlin/com/jaytux/phoebench/common/Events.kt @@ -78,13 +78,11 @@ sealed class ProjectEvent { enum class ANSI(val bitIdx: Int, val ansiCode: Int) { BOLD(0, 1), UNDERLINE(1, 4), - FG_BLACK(2, 30), FG_RED(3, 31), FG_GREEN(4, 32), - FG_YELLOW(5, 33), FG_BLUE(6, 34), FG_MAGENTA(7, 35), - FG_CYAN(8, 36), + FG_RED(2, 31), FG_GREEN(3, 32), FG_YELLOW(4, 33), + FG_BLUE(5, 34), FG_GRAY(6, 90), - BG_BLACK(9, 40), BG_RED(10, 41), BG_GREEN(11, 42), - BG_YELLOW(12, 43), BG_BLUE(13, 44), BG_MAGENTA(14, 45), - BG_CYAN(15, 46); + BG_RED(7, 41), BG_GREEN(8, 42), BG_YELLOW(9, 43), + BG_BLUE(10, 44), BG_GRAY(11, 100); companion object { private val _mapping: Map diff --git a/server/src/main/kotlin/com/jaytux/phoebench/server/Main.kt b/server/src/main/kotlin/com/jaytux/phoebench/server/Main.kt index 6306b04..31cf5d4 100644 --- a/server/src/main/kotlin/com/jaytux/phoebench/server/Main.kt +++ b/server/src/main/kotlin/com/jaytux/phoebench/server/Main.kt @@ -179,7 +179,6 @@ fun Application.module() { ) { _, id, sender -> val bus = Buses.monitorBus(id) val backlog = bus.onConnect() - println("Bus [$id] connected; sending backlog (${backlog.start != null} // ${backlog.messages.size} // ${backlog.end != null})") sender(bus.bus.serializer, backlog) bus.bus } diff --git a/server/src/main/kotlin/com/jaytux/phoebench/server/MutableBackLog.kt b/server/src/main/kotlin/com/jaytux/phoebench/server/MutableBackLog.kt index 732c20a..0b4543b 100644 --- a/server/src/main/kotlin/com/jaytux/phoebench/server/MutableBackLog.kt +++ b/server/src/main/kotlin/com/jaytux/phoebench/server/MutableBackLog.kt @@ -11,21 +11,18 @@ class MutableBackLog { fun registerStart(event: TStart) { if(start != null) throw IllegalStateException("Start is already set.") start = event - println("[BACKLOG]: start '$event'") } fun onEvent(event: TEvent) { if(start == null) throw IllegalStateException("Start is not set yet.") if(end != null) throw IllegalStateException("End is already set.") _events += event - println("[BACKLOG]: event '$event'") } fun registerEnd(event: TEnd) { if(start == null) throw IllegalStateException("Start is not set yet.") if(end != null) throw IllegalStateException("End is already set.") end = event - println("[BACKLOG]: end '$event'") } fun reset() {