tui: use ctx chroma highlighter

This commit is contained in:
Matt Low 2024-03-12 08:12:12 +00:00
parent 78c80431b4
commit 79ad681f4c

View File

@ -13,7 +13,6 @@ import (
"git.mlow.ca/mlow/lmcli/pkg/lmcli"
models "git.mlow.ca/mlow/lmcli/pkg/lmcli/model"
"git.mlow.ca/mlow/lmcli/pkg/lmcli/tools"
"git.mlow.ca/mlow/lmcli/pkg/util/tty"
"github.com/charmbracelet/bubbles/textarea"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
@ -24,8 +23,6 @@ type model struct {
ctx *lmcli.Context
convShortname string
highlighter *tty.ChromaHighlighter
// application state
conversation *models.Conversation
messages []models.Message
@ -155,12 +152,6 @@ func initialModel(ctx *lmcli.Context, convShortname string) model {
confirmPrompt: false,
}
m.highlighter = tty.NewChromaHighlighter(
"markdown", // we're highlighting markdown
*ctx.Config.Chroma.Formatter,
*ctx.Config.Chroma.Style,
)
m.content = viewport.New(0, 0)
m.input = textarea.New()
@ -295,7 +286,7 @@ func (m *model) updateContent() {
sb.WriteString(fmt.Sprintf("%s:\n\n", style.Render(string(message.Role))))
highlighted, _ := m.highlighter.HighlightS(message.Content)
highlighted, _ := m.ctx.Chroma.HighlightS(message.Content)
sb.WriteString(contentStyle.Width(m.content.Width - 5).Render(highlighted))
if i < msgCnt-1 {
sb.WriteString("\n\n")