formatter

package
v2.0.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Reset   = "\033[0m"
	Red     = "\033[31m"
	Green   = "\033[32m"
	Yellow  = "\033[33m"
	Blue    = "\033[34m"
	Magenta = "\033[35m"
	Cyan    = "\033[36m"
	White   = "\033[37m"
	Bold    = "\033[1m"
	Dim     = "\033[2m"
)

ANSI 颜色码

Variables

This section is empty.

Functions

func WithColors

func WithColors(score, content, meta, title string) func(*TerminalConfig)

WithColors 设置颜色方案

func WithContentMax

func WithContentMax(max int) func(*TerminalConfig)

WithContentMax 设置内容最大长度

func WithShowDocID

func WithShowDocID(show bool) func(*TerminalConfig)

WithShowDocID 设置是否显示文档ID

func WithShowIndex

func WithShowIndex(show bool) func(*TerminalConfig)

WithShowIndex 设置是否显示序号

func WithShowScore

func WithShowScore(show bool) func(*TerminalConfig)

WithShowScore 设置是否显示分数

Types

type JSONFormatter

type JSONFormatter struct {
	core.BaseFormatter
}

JSONFormatter JSON 格式化器

func NewJSONFormatter

func NewJSONFormatter() *JSONFormatter

NewJSONFormatter 创建 JSON 格式化器

func (*JSONFormatter) FormatAll

func (f *JSONFormatter) FormatAll(hit *core.Hit) string

FormatAll 格式化为 JSON。

type TerminalConfig

type TerminalConfig struct {
	ShowScore    bool   // 是否显示分数
	ShowDocID    bool   // 是否显示文档ID
	ShowIndex    bool   // 是否显示序号
	ContentMax   int    // 内容最大长度,0 表示不限制
	ScoreColor   string // 分数颜色
	ContentColor string // 内容颜色
	MetaColor    string // 元数据颜色
	TitleColor   string // 标题颜色
}

TerminalConfig 终端格式化配置

func DefaultTerminalConfig

func DefaultTerminalConfig() *TerminalConfig

DefaultTerminalConfig 默认终端配置

type TerminalFormatter

type TerminalFormatter struct {
	core.BaseFormatter
	// contains filtered or unexported fields
}

TerminalFormatter 终端彩色输出格式化器

func NewTerminalFormatter

func NewTerminalFormatter(opts ...func(*TerminalConfig)) *TerminalFormatter

NewTerminalFormatter 创建终端格式化器

func (*TerminalFormatter) Format

func (f *TerminalFormatter) Format(hit *core.Hit) string

Format 格式化 Hit 容器为终端输出。 遍历 hit.Chunks 输出每个 Chunk。 hit 为 nil 或 Chunks 为空时返回空字符串。

func (*TerminalFormatter) FormatAll

func (f *TerminalFormatter) FormatAll(hit *core.Hit) string

FormatAll 格式化 Hit 容器,含标题和全部 Chunks。 标题显示 Chunks 数量。

func (*TerminalFormatter) Print

func (f *TerminalFormatter) Print(hit *core.Hit)

Print 便捷方法:直接打印到标准输出

func (*TerminalFormatter) Println

func (f *TerminalFormatter) Println(hit *core.Hit)

Println 便捷方法:打印并换行

func (*TerminalFormatter) Write

func (f *TerminalFormatter) Write(w io.Writer, hit *core.Hit) error

Write 格式化并写入输出流

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL