ANSI update
This commit is contained in:
@@ -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() ?: "<unknown server ULR>"
|
||||
Client.onClearServer()
|
||||
ErrorResponse("Cannot use $server: protocol version mismatch (server: ${handshake.version}, expected: ${ProtocolVersion.VERSION})").error()
|
||||
}
|
||||
Unit.value()
|
||||
}
|
||||
|
||||
fun serverPrompt(server: String?): Either<ErrorResponse, Unit> {
|
||||
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() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Uuid?>(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
|
||||
|
||||
+2
-6
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user