本文整理匯總了Golang中github.com/elves/elvish/eval.Evaler.EvalInteractive方法的典型用法代碼示例。如果您正苦於以下問題:Golang Evaler.EvalInteractive方法的具體用法?Golang Evaler.EvalInteractive怎麽用?Golang Evaler.EvalInteractive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/elves/elvish/eval.Evaler
的用法示例。
在下文中一共展示了Evaler.EvalInteractive方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: interact
func interact(ev *eval.Evaler, st *store.Store) {
// Build Editor.
sigch := make(chan os.Signal)
signal.Notify(sigch)
ed := edit.NewEditor(os.Stdin, sigch, ev, st)
// Source rc.elv.
datadir, err := store.EnsureDataDir()
if err != nil {
fmt.Fprintln(os.Stderr, err)
} else {
source(ev, datadir+"/rc.elv", true)
}
// Build readLine function.
readLine := func() (string, error) {
return ed.ReadLine()
}
cooldown := time.Second
usingBasic := false
cmdNum := 0
for {
cmdNum++
// name := fmt.Sprintf("<tty %d>", cmdNum)
line, err := readLine()
if err == io.EOF {
break
} else if err != nil {
fmt.Println("Editor error:", err)
if !usingBasic {
fmt.Println("Falling back to basic line editor")
readLine = basicReadLine
usingBasic = true
} else {
fmt.Println("Don't know what to do, pid is", os.Getpid())
fmt.Println("Restarting editor in", cooldown)
time.Sleep(cooldown)
if cooldown < time.Minute {
cooldown *= 2
}
}
continue
}
// No error; reset cooldown.
cooldown = time.Second
n, err := parse.Parse(line)
printError(err, "<interact>", "parse error", line)
if err == nil {
err := ev.EvalInteractive(line, n)
printError(err, "<interact>", "eval error", line)
}
}
}