Private
Public Access
1
0

Store ChromaHighlighter in lmcli.Context and use it

In preparation for TUI
This commit is contained in:
2024-03-12 07:19:16 +00:00
parent 0a27b9a8d3
commit f2c7d2bdd0
2 changed files with 7 additions and 14 deletions

View File

@@ -2,7 +2,6 @@ package util
import (
"fmt"
"io"
"os"
"strings"
"time"
@@ -11,7 +10,6 @@ import (
"git.mlow.ca/mlow/lmcli/pkg/lmcli/model"
"git.mlow.ca/mlow/lmcli/pkg/lmcli/tools"
"git.mlow.ca/mlow/lmcli/pkg/util"
"github.com/alecthomas/chroma/v2/quick"
"github.com/charmbracelet/lipgloss"
)
@@ -240,12 +238,6 @@ func RenderConversation(ctx *lmcli.Context, messages []model.Message, spaceForRe
}
}
// HighlightMarkdown applies syntax highlighting to the provided markdown text
// and writes it to stdout.
func HighlightMarkdown(w io.Writer, markdownText string, formatter string, style string) error {
return quick.Highlight(w, markdownText, "md", formatter, style)
}
func RenderMessage(ctx *lmcli.Context, m *model.Message) {
var messageAge string
if m.CreatedAt.IsZero() {
@@ -274,11 +266,7 @@ func RenderMessage(ctx *lmcli.Context, m *model.Message) {
fmt.Printf("%s %s - %s %s\n\n", separator, role, timestamp, separator)
if m.Content != "" {
HighlightMarkdown(
os.Stdout, m.Content,
*ctx.Config.Chroma.Formatter,
*ctx.Config.Chroma.Style,
)
ctx.Chroma.Highlight(os.Stdout, m.Content)
fmt.Println()
}
}