mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
refactor(partnerctl-chat): optimize color of chat prompt
This commit is contained in:
@@ -25,12 +25,12 @@ class ChatCommand : Runnable {
|
||||
@CommandLine.Option(
|
||||
names = ["--source"],
|
||||
description = ["Input source identity used by Partner runtime."],
|
||||
defaultValue = DEFAULT_SOURCE,
|
||||
required = true
|
||||
)
|
||||
lateinit var source: String
|
||||
|
||||
override fun run() {
|
||||
val screen = ChatScreen()
|
||||
val screen = ChatScreen(source)
|
||||
WebSocketClient(url) { event ->
|
||||
screen.postInteractionEvent(event)
|
||||
}.use { client ->
|
||||
@@ -42,6 +42,5 @@ class ChatCommand : Runnable {
|
||||
|
||||
private companion object {
|
||||
private const val DEFAULT_URL = "ws://127.0.0.1:29600"
|
||||
private const val DEFAULT_SOURCE = "partnerctl"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ import work.slhaf.partner.ctl.support.PromptStyle
|
||||
import work.slhaf.partner.ctl.support.TerminalText
|
||||
|
||||
internal class ChatEventRenderer {
|
||||
fun renderCommittedUserInput(content: String): String {
|
||||
fun renderCommittedUserInput(source: String, content: String): String {
|
||||
return TerminalText.render(
|
||||
listOf(
|
||||
PromptPart("you", PromptStyle.CYAN),
|
||||
PromptPart(": "),
|
||||
PromptPart("$source>", PromptStyle.CYAN),
|
||||
PromptPart(" "),
|
||||
PromptPart(content),
|
||||
)
|
||||
)
|
||||
@@ -23,15 +23,15 @@ internal class ChatEventRenderer {
|
||||
return if (content.isBlank()) {
|
||||
TerminalText.render(
|
||||
listOf(
|
||||
PromptPart("assistant", PromptStyle.GREEN),
|
||||
PromptPart(":"),
|
||||
PromptPart("assistant>", PromptStyle.GREEN),
|
||||
PromptPart(" "),
|
||||
)
|
||||
)
|
||||
} else {
|
||||
TerminalText.render(
|
||||
listOf(
|
||||
PromptPart("assistant", PromptStyle.GREEN),
|
||||
PromptPart(": "),
|
||||
PromptPart("assistant>", PromptStyle.GREEN),
|
||||
PromptPart(" "),
|
||||
PromptPart(content),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.concurrent.LinkedBlockingQueue
|
||||
import kotlin.math.ceil
|
||||
|
||||
internal class ChatScreen(
|
||||
val source: String,
|
||||
private val terminal: Terminal = TerminalBuilder.builder()
|
||||
.system(true)
|
||||
.dumb(true)
|
||||
@@ -90,7 +91,7 @@ internal class ChatScreen(
|
||||
}
|
||||
|
||||
commitDynamicArea()
|
||||
printCommitted(renderer.renderCommittedUserInput(line))
|
||||
printCommitted(renderer.renderCommittedUserInput(source,line))
|
||||
activeReply.setLength(0)
|
||||
repaintDynamicArea()
|
||||
|
||||
@@ -189,11 +190,12 @@ internal class ChatScreen(
|
||||
append(renderer.renderActiveReply(activeReply.toString()))
|
||||
append('\n')
|
||||
}
|
||||
append('\n')
|
||||
append(inputPrompt())
|
||||
}
|
||||
}
|
||||
|
||||
private fun inputPrompt(): String = "partner> ${input}"
|
||||
private fun inputPrompt(): String = "partner> $input"
|
||||
|
||||
private fun measureDisplayRows(text: String): Int {
|
||||
val width = terminal.width.takeIf { it > 0 } ?: DEFAULT_TERMINAL_WIDTH
|
||||
|
||||
Reference in New Issue
Block a user