本文整理汇总了Golang中github.com/peterh/liner.State类的典型用法代码示例。如果您正苦于以下问题:Golang State类的具体用法?Golang State怎么用?Golang State使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了State类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: configureLiner
func configureLiner(linerState *liner.State) {
linerState.SetCtrlCAborts(true)
linerState.SetCompleter(func(line string) (c []string) {
for _, n := range commandCompletions {
if strings.HasPrefix(n, strings.ToLower(line)) {
c = append(c, n)
}
}
return
})
/* TODO
// WordCompleter takes the currently edited line with the cursor position and
// returns the completion candidates for the partial word to be completed. If
// the line is "Hello, wo!!!" and the cursor is before the first '!',
// ("Hello, wo!!!", 9) is passed to the completer which may returns
// ("Hello, ", {"world", "Word"}, "!!!") to have "Hello, world!!!".
linerState.SetWordCompleter(func(line string, pos int) (head string, completions []string, tail string) {
for _, n := range wordCompletions {
if strings.HasPrefix(n, strings.ToLower(line)) {
c = append(c, n)
}
}
return
})
*/
}
开发者ID:onlyafly,项目名称:piquant,代码行数:28,代码来源:main.go
示例2: writeLinerHistory
func writeLinerHistory(line *liner.State) {
if f, err := os.Create(historyFilename); err != nil {
log.Print("Error writing history file: ", err)
} else {
line.WriteHistory(f)
f.Close()
}
}
开发者ID:onlyafly,项目名称:piquant,代码行数:8,代码来源:main.go
示例3: persist
// from google/cayley
func persist(term *liner.State, path string) error {
f, err := os.OpenFile(path, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0666)
if err != nil {
return fmt.Errorf("could not open %q to append history: %v", path, err)
}
defer f.Close()
_, err = term.WriteHistory(f)
if err != nil {
return fmt.Errorf("could not write history to %q: %v", path, err)
}
return term.Close()
}
开发者ID:sombr,项目名称:ccat,代码行数:13,代码来源:query_cmd.go
示例4: msgAdd
func (ce *CtrlEngine) msgAdd(
c *cli.Context,
from, to, file string,
mailInput, permanentSignature bool,
attachments []string,
minDelay, maxDelay int32,
line *liner.State,
r io.Reader,
) error {
fromMapped, err := identity.Map(from)
if err != nil {
return err
}
prev, _, err := ce.msgDB.GetNym(fromMapped)
if err != nil {
return err
}
if prev == "" {
return log.Errorf("user ID %s not found", from)
}
// TODO: handle attachments
var msg []byte
if file != "" {
// read message from file
msg, err = ioutil.ReadFile(file)
if err != nil {
return log.Error(err)
}
} else if line != nil {
// read message from terminal
fmt.Fprintln(ce.fileTable.StatusFP,
"type message (end with Ctrl-D on empty line):")
var inbuf bytes.Buffer
for {
ln, err := line.Prompt("")
if err != nil {
if err == io.EOF {
break
}
return log.Error(err)
}
inbuf.WriteString(ln + "\n")
}
msg = inbuf.Bytes()
} else {
// read message from stdin
msg, err = ioutil.ReadAll(r)
if err != nil {
return log.Error(err)
}
}
if mailInput {
recipient, message, err := mail.Parse(bytes.NewBuffer(msg))
if err != nil {
return err
}
to = recipient
msg = []byte(message)
}
toMapped, err := identity.Map(to)
if err != nil {
return err
}
prev, _, contactType, err := ce.msgDB.GetContact(fromMapped, toMapped)
if err != nil {
return err
}
if prev == "" || contactType == msgdb.GrayList || contactType == msgdb.BlackList {
return log.Errorf("contact %s not found (for user ID %s)", to, from)
}
// store message in message DB
now := times.Now()
err = ce.msgDB.AddMessage(fromMapped, toMapped, now, true, string(msg),
permanentSignature, minDelay, maxDelay)
if err != nil {
return err
}
log.Info("message added")
if line != nil {
fmt.Fprintln(ce.fileTable.StatusFP, "message added")
}
return nil
}
开发者ID:JonathanLogan,项目名称:mute,代码行数:89,代码来源:msg.go
示例5: openLinerHistory
func openLinerHistory(line *liner.State) {
if f, err := os.Open(historyFilename); err == nil {
line.ReadHistory(f)
f.Close()
}
}
开发者ID:onlyafly,项目名称:piquant,代码行数:6,代码来源:main.go
示例6: saveHistory
func (r *REPL) saveHistory(prompt *liner.State) {
if f, err := os.Create(r.historyPath); err == nil {
prompt.WriteHistory(f)
f.Close()
}
}
开发者ID:tsandall,项目名称:opa,代码行数:6,代码来源:repl.go
示例7: loadHistory
func (r *REPL) loadHistory(prompt *liner.State) {
if f, err := os.Open(r.historyPath); err == nil {
prompt.ReadHistory(f)
f.Close()
}
}
开发者ID:tsandall,项目名称:opa,代码行数:6,代码来源:repl.go
注:本文中的github.com/peterh/liner.State类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论