feat: 配置系统重构,添加用户配置和中文注释

This commit is contained in:
2026-04-23 20:11:22 +08:00
parent e070461fe4
commit dd3c8a03e1
10 changed files with 336 additions and 318 deletions

View File

@@ -1,3 +1,5 @@
// Package internal 包含 hxclaw 的内部工具模块
// 提供配置管理、Markdown 渲染、输入读取等功能
package internal
import (
@@ -9,6 +11,8 @@ import (
"github.com/charmbracelet/x/term"
)
// RenderMarkdown 将 Markdown 文本渲染为终端友好的格式
// 支持通过配置或环境变量指定渲染主题和换行宽度
func RenderMarkdown(md string) string {
if md == "" {
return ""
@@ -67,8 +71,8 @@ func RenderParagraph(text string) string {
func getStyle() string {
if cfg := GetProjectConfig(); cfg != nil {
if cfg.Markdown.GlamourStyle != "" {
return cfg.Markdown.GlamourStyle
if cfg.Markdown.Theme != "" {
return cfg.Markdown.Theme
}
}
if s := os.Getenv("GLAMOUR_STYLE"); s != "" {
@@ -79,10 +83,10 @@ func getStyle() string {
func getWrapWidth() int {
if cfg := GetProjectConfig(); cfg != nil {
if cfg.Markdown.WrapWidth > 0 {
return cfg.Markdown.WrapWidth
if cfg.Markdown.LineWidth > 0 {
return cfg.Markdown.LineWidth
}
if cfg.Markdown.WrapWidth < 0 {
if cfg.Markdown.LineWidth < 0 {
return 0
}
}