- 使用 ProcessDirect 替代 ChatStream,支持工具调用结果显示 - 新增 project.config.yml 统一配置(Logo、用户前缀、流式延迟、Markdown等) - Markdown 渲染支持自动终端宽度换行 - 按行输出文本,每行延迟可配置 - 简化状态栏,只显示耗时(图标颜色 #f0c75e,文字颜色 #2b2e32) - spinner 动画右移两个字符 - 用户输入前缀可配置化
This commit is contained in:
@@ -2,9 +2,11 @@ package internal
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"charm.land/glamour/v2"
|
||||
"github.com/charmbracelet/x/term"
|
||||
)
|
||||
|
||||
func RenderMarkdown(md string) string {
|
||||
@@ -13,10 +15,11 @@ func RenderMarkdown(md string) string {
|
||||
}
|
||||
|
||||
style := getStyle()
|
||||
wrapWidth := getWrapWidth()
|
||||
|
||||
r, err := glamour.NewTermRenderer(
|
||||
glamour.WithStandardStyle(style),
|
||||
glamour.WithWordWrap(80),
|
||||
glamour.WithWordWrap(wrapWidth),
|
||||
)
|
||||
if err != nil {
|
||||
return md
|
||||
@@ -43,10 +46,11 @@ func RenderParagraph(text string) string {
|
||||
}
|
||||
|
||||
style := getStyle()
|
||||
wrapWidth := getWrapWidth()
|
||||
|
||||
r, err := glamour.NewTermRenderer(
|
||||
glamour.WithStandardStyle(style),
|
||||
glamour.WithWordWrap(80),
|
||||
glamour.WithWordWrap(wrapWidth),
|
||||
)
|
||||
if err != nil {
|
||||
return text
|
||||
@@ -62,9 +66,33 @@ func RenderParagraph(text string) string {
|
||||
}
|
||||
|
||||
func getStyle() string {
|
||||
style := "dark"
|
||||
if s := os.Getenv("GLAMOUR_STYLE"); s != "" {
|
||||
style = s
|
||||
if cfg := GetProjectConfig(); cfg != nil {
|
||||
if cfg.Markdown.GlamourStyle != "" {
|
||||
return cfg.Markdown.GlamourStyle
|
||||
}
|
||||
}
|
||||
return style
|
||||
if s := os.Getenv("GLAMOUR_STYLE"); s != "" {
|
||||
return s
|
||||
}
|
||||
return "dark"
|
||||
}
|
||||
|
||||
func getWrapWidth() int {
|
||||
if cfg := GetProjectConfig(); cfg != nil {
|
||||
if cfg.Markdown.WrapWidth > 0 {
|
||||
return cfg.Markdown.WrapWidth
|
||||
}
|
||||
}
|
||||
|
||||
if cols := os.Getenv("COLUMNS"); cols != "" {
|
||||
if w, err := strconv.Atoi(cols); err == nil && w > 0 {
|
||||
return w
|
||||
}
|
||||
}
|
||||
|
||||
width, _, err := term.GetSize(0)
|
||||
if err != nil || width <= 0 {
|
||||
return 80
|
||||
}
|
||||
return width
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user