tui: use ctx chroma highlighter

This commit is contained in:
Matt Low 2024-03-12 08:12:12 +00:00
parent 1570c23d63
commit 758f74aba5

View File

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