Alter format and add colouring to user/role message headings
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user