fix: 禁用 glamour word wrap,改用 lipgloss.Print 输出

- getWrapWidth() 支持 wrap_width=-1 禁用换行,添加 LINES fallback
- outputLineByLine() 使用 lipgloss.Print 替代 fmt.Println
- 解决 glamour word wrap 导致列表项换行异常的问题
This commit is contained in:
2026-04-17 07:38:36 +08:00
parent 3f9443c14b
commit e070461fe4
3 changed files with 18 additions and 9 deletions

View File

@@ -82,6 +82,9 @@ func getWrapWidth() int {
if cfg.Markdown.WrapWidth > 0 {
return cfg.Markdown.WrapWidth
}
if cfg.Markdown.WrapWidth < 0 {
return 0
}
}
if cols := os.Getenv("COLUMNS"); cols != "" {
@@ -90,9 +93,15 @@ func getWrapWidth() int {
}
}
if cols := os.Getenv("LINES"); 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 0
}
return width
}

View File

@@ -175,11 +175,11 @@ func outputLineByLine(text string) {
for i, line := range lines {
if line == "" {
fmt.Println()
lipgloss.Print("\n")
continue
}
fmt.Println(line)
lipgloss.Print(line + "\n")
if i < totalLines-1 {
time.Sleep(lineDelay)
@@ -188,7 +188,7 @@ func outputLineByLine(text string) {
}
}
fmt.Println()
lipgloss.Print("\n")
}
var (

View File

@@ -2,15 +2,15 @@
# 模拟流式输出配置
streaming:
line_delay_ms: 1000 # 每行输出后的延迟(毫秒)
last_line_delay_ms: 600 # 最后一行延迟(毫秒)
line_delay_ms: 1000 # 每行输出后的延迟(毫秒)
last_line_delay_ms: 600 # 最后一行延迟(毫秒)
# Markdown 渲染配置
markdown:
glamour_style: dark # 渲染主题dark, light, dracula, tokyo-night 等
wrap_width: 0 # 自动换行宽度(0=自动获取终端宽度)
glamour_style: dark # 渲染主题dark, light, dracula, tokyo-night 等
wrap_width: -1 # 自动换行宽度(-1=禁用0=自动,>0=固定宽度)
# UI 配置
ui:
logo: "🦐"
user_prefix: "👀 "
user_prefix: "👀 "