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