• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

smallnest / goclaw / 21970812588

13 Feb 2026 01:14AM UTC coverage: 5.778% (-0.6%) from 6.376%
21970812588

push

github

smallnest
add infoflow

1514 of 26201 relevant lines covered (5.78%)

0.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/cli/input/reader.go
1
package input
2

3
import (
4
        "fmt"
5
        "io"
6

7
        "github.com/ergochat/readline"
8
)
9

10
// ReadLine 读取一行输入(支持中文)
11
func ReadLine(prompt string) (string, error) {
×
12
        return ReadLineWithHistory(prompt, nil)
×
13
}
×
14

15
// ReadLineWithHistory 读取一行输入(支持历史记录)
16
// 注意:每次调用创建新的 readline 实例,适用于一次性读取
17
func ReadLineWithHistory(prompt string, history []string) (string, error) {
×
18
        // ergochat/readline uses simpler New() API with default config
×
19
        // For custom config, use NewFromConfig()
×
20
        rl, err := readline.New(prompt)
×
21
        if err != nil {
×
22
                return "", err
×
23
        }
×
24
        defer rl.Close()
×
25

×
26
        // 添加历史记录
×
27
        for _, h := range history {
×
28
                if h != "" {
×
29
                        _ = rl.SaveToHistory(h)
×
30
                }
×
31
        }
32

33
        // 读取输入
34
        line, err := rl.ReadLine()
×
35
        if err != nil {
×
36
                // ergochat/readline returns io.EOF for Ctrl+C
×
37
                if err == readline.ErrInterrupt || err == io.EOF {
×
38
                        return "", fmt.Errorf("interrupted")
×
39
                }
×
40
                return "", err
×
41
        }
42

43
        return line, nil
×
44
}
45

46
// NewReadline 创建持久化的 readline 实例
47
// 用于需要多次读取输入并保持历史记录的场景
48
func NewReadline(prompt string) (*readline.Instance, error) {
×
49
        // ergochat/readline's New() uses sensible defaults
×
50
        return readline.New(prompt)
×
51
}
×
52

53
// InitReadlineHistory 初始化 readline 实例的历史记录
54
// Note: ergochat/readline uses SaveToHistory instead of SaveHistory
55
func InitReadlineHistory(rl *readline.Instance, history []string) {
×
56
        for _, h := range history {
×
57
                if h != "" {
×
58
                        _ = rl.SaveToHistory(h)
×
59
                }
×
60
        }
61
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc