Enha: improve colours and formatingg

This commit is contained in:
Grail Finder
2024-12-05 20:13:07 +03:00
parent 990e0695c5
commit e811bc51d4
4 changed files with 20 additions and 11 deletions

2
bot.go
View File

@@ -113,6 +113,7 @@ func chatRound(userMsg, role string, tv *tview.TextView, regen bool) {
if userMsg != "" && !regen { // no need to write assistant icon since we continue old message
fmt.Fprintf(tv, "(%d) ", len(chatBody.Messages))
fmt.Fprint(tv, cfg.AssistantIcon)
fmt.Fprint(tv, "\n")
}
respText := strings.Builder{}
out:
@@ -131,6 +132,7 @@ out:
chatBody.Messages = append(chatBody.Messages, models.RoleMsg{
Role: cfg.AssistantRole, Content: respText.String(),
})
colorText()
// bot msg is done;
// now check it for func call
// logChat(activeChatName, chatBody.Messages)

View File

@@ -69,7 +69,7 @@ func (m RoleMsg) ToText(i int) string {
default:
icon = fmt.Sprintf("(%d) <%s>: ", i, m.Role)
}
textMsg := fmt.Sprintf("%s%s\n", icon, m.Content)
textMsg := fmt.Sprintf("%s\n%s\n", icon, m.Content)
return strings.ReplaceAll(textMsg, "\n\n", "\n")
}

View File

@@ -9,9 +9,9 @@ import (
)
var (
toolCallRE = regexp.MustCompile(`__tool_call__\s*([\s\S]*?)__tool_call__`)
// quotesRE = regexp.MustCompile(`(".*")`)
// starRE = regexp.MustCompile(`(\*.*\*)`)
toolCallRE = regexp.MustCompile(`__tool_call__\s*([\s\S]*?)__tool_call__`)
quotesRE = regexp.MustCompile(`(".*?")`)
starRE = regexp.MustCompile(`(\*.*?\*)`)
basicSysMsg = `Large Language Model that helps user with any of his requests.`
toolSysMsg = `You're a helpful assistant.
# Tools

21
tui.go
View File

@@ -41,6 +41,13 @@ Press Enter to go back
`
)
func colorText() {
// INFO: looks way too inefficient; use it with care or make it optional
tv := textView.GetText(false)
cq := quotesRE.ReplaceAllString(tv, `[orange:-:-]$1[-:-:-]`)
textView.SetText(starRE.ReplaceAllString(cq, `[turquoise::i]$1[-:-:-]`))
}
func init() {
theme := tview.Theme{
PrimitiveBackgroundColor: tcell.ColorDefault,
@@ -49,7 +56,7 @@ func init() {
BorderColor: tcell.ColorGray,
TitleColor: tcell.ColorRed,
GraphicsColor: tcell.ColorBlue,
PrimaryTextColor: tcell.ColorOlive,
PrimaryTextColor: tcell.ColorLightGray,
SecondaryTextColor: tcell.ColorYellow,
TertiaryTextColor: tcell.ColorOrange,
InverseTextColor: tcell.ColorPurple,
@@ -79,10 +86,6 @@ func init() {
AddItem(position, 0, 1, false)
updateStatusLine := func() {
position.SetText(fmt.Sprintf(indexLine, botRespMode, cfg.AssistantRole, activeChatName))
// INFO: way too ineffective; it should be optional or removed
// tv := textView.GetText(false)
// cq := quotesRE.ReplaceAllString(tv, `[orange]$1[white]`)
// textView.SetText(starRE.ReplaceAllString(cq, `[yellow]$1[white]`))
}
chatOpts := []string{"cancel", "new", "rename current"}
chatList, err := loadHistoryChats()
@@ -113,6 +116,7 @@ func init() {
activeChatName = newChat.Name
chatMap[newChat.Name] = newChat
pages.RemovePage("history")
colorText()
return
// set text
case "cancel":
@@ -135,6 +139,7 @@ func init() {
textView.SetText(chatToText(cfg.ShowSys))
activeChatName = fn
pages.RemovePage("history")
colorText()
return
}
})
@@ -266,6 +271,7 @@ func init() {
textArea.SetMovedFunc(updateStatusLine)
updateStatusLine()
textView.SetText(chatToText(cfg.ShowSys))
colorText()
textView.ScrollToEnd()
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyF1 {
@@ -335,11 +341,11 @@ func init() {
}
if event.Key() == tcell.KeyCtrlE {
textArea.SetText("pressed ctrl+e", true)
colorText()
return nil
}
if event.Key() == tcell.KeyCtrlA {
textArea.SetText("pressed ctrl+a", true)
// list all agents
return nil
}
if event.Key() == tcell.KeyCtrlS {
@@ -369,9 +375,10 @@ func init() {
// read all text into buffer
msgText := textArea.GetText()
if msgText != "" {
fmt.Fprintf(textView, "\n(%d) <user>: %s\n", len(chatBody.Messages), msgText)
fmt.Fprintf(textView, "\n(%d) <user>: \n%s\n", len(chatBody.Messages), msgText)
textArea.SetText("", true)
textView.ScrollToEnd()
colorText()
}
// update statue line
go chatRound(msgText, cfg.UserRole, textView, false)