Private
Public Access
1
0

Alter format and add colouring to user/role message headings

This commit is contained in:
2023-11-16 05:02:43 +00:00
parent cac2a1e80c
commit 22e0ff4115
3 changed files with 45 additions and 1 deletions

View File

@@ -4,6 +4,8 @@ import (
"fmt"
"strings"
"time"
"github.com/gookit/color"
)
// ShowWaitAnimation "draws" an animated ellipses to stdout until something is
@@ -59,7 +61,33 @@ func HandleDelayedResponse(response chan string) string {
}
func (m *Message) RenderTTY(paddingDown bool) {
fmt.Printf("<%s>\n\n", m.FriendlyRole())
var messageAge string
if m.CreatedAt.IsZero() {
messageAge = "now"
} else {
now := time.Now()
messageAge = humanTimeElapsedSince(now.Sub(m.CreatedAt))
}
var roleStyle color.Style
switch m.Role {
case "system":
roleStyle = color.Style{color.HiRed}
case "user":
roleStyle = color.Style{color.HiGreen}
case "assistant":
roleStyle = color.Style{color.HiBlue}
default:
roleStyle = color.Style{color.FgWhite}
}
roleStyle.Add(color.Bold)
headerColor := color.FgYellow
separator := headerColor.Sprint("===")
timestamp := headerColor.Sprint(messageAge)
role := roleStyle.Sprint(m.FriendlyRole())
fmt.Printf("%s %s - %s %s\n\n", separator, role, timestamp, separator)
if m.OriginalContent != "" {
fmt.Print(m.OriginalContent)
}