summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2024-12-05 20:13:07 +0300
committerGrail Finder <wohilas@gmail.com>2024-12-05 20:13:07 +0300
commite811bc51d401ecde194df562034ae529943546d0 (patch)
tree6a9cec3b0d132c1dd0594dfea54cc976ee9061d9
parent990e0695c582c2c8d647c258cde0342ac14e3a75 (diff)
Enha: improve colours and formatingg
-rw-r--r--bot.go2
-rw-r--r--models/models.go2
-rw-r--r--tools.go6
-rw-r--r--tui.go21
4 files changed, 20 insertions, 11 deletions
diff --git a/bot.go b/bot.go
index 6ff579d..23769dd 100644
--- a/bot.go
+++ b/bot.go
@@ -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)
diff --git a/models/models.go b/models/models.go
index 0373e9b..2ac087a 100644
--- a/models/models.go
+++ b/models/models.go
@@ -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")
}
diff --git a/tools.go b/tools.go
index 5c5472e..bb9012e 100644
--- a/tools.go
+++ b/tools.go
@@ -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
diff --git a/tui.go b/tui.go
index ef8c282..28d1c44 100644
--- a/tui.go
+++ b/tui.go
@@ -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)