本文整理匯總了Golang中github.com/peterh/liner.State.Prompt方法的典型用法代碼示例。如果您正苦於以下問題:Golang State.Prompt方法的具體用法?Golang State.Prompt怎麽用?Golang State.Prompt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/peterh/liner.State
的用法示例。
在下文中一共展示了State.Prompt方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}