當前位置: 首頁>>代碼示例>>Golang>>正文


Golang eval.Evaler類代碼示例

本文整理匯總了Golang中github.com/elves/elvish/eval.Evaler的典型用法代碼示例。如果您正苦於以下問題:Golang Evaler類的具體用法?Golang Evaler怎麽用?Golang Evaler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Evaler類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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)
		}
	}
}
開發者ID:yonglehou,項目名稱:elvish,代碼行數:60,代碼來源:run.go

示例2: getIsExternal

// getIsExternal finds a set of all external commands and puts it on the result
// channel.
func getIsExternal(ev *eval.Evaler, result chan<- map[string]bool) {
	names := make(chan string, 32)
	go func() {
		ev.AllExecutables(names)
		close(names)
	}()
	isExternal := make(map[string]bool)
	for name := range names {
		isExternal[name] = true
	}
	result <- isExternal
}
開發者ID:elves,項目名稱:elvish,代碼行數:14,代碼來源:editor.go

示例3: NewEditor

// NewEditor creates an Editor.
func NewEditor(file *os.File, sigs chan os.Signal, ev *eval.Evaler, st *store.Store) *Editor {
	seq := -1
	if st != nil {
		var err error
		seq, err = st.NextCmdSeq()
		if err != nil {
			// TODO(xiaq): Also report the error
			seq = -1
		}
	}

	prompt, rprompt := defaultPrompts()

	ed := &Editor{
		file:   file,
		writer: newWriter(file),
		reader: NewReader(file),
		sigs:   sigs,
		store:  st,
		evaler: ev,
		cmdSeq: seq,
		ps1:    eval.NewPtrVariableWithValidator(prompt, MustBeFn),
		rps1:   eval.NewPtrVariableWithValidator(rprompt, MustBeFn),

		abbreviations: make(map[string]string),
		beforeReadLine: eval.NewPtrVariableWithValidator(
			eval.NewList(), eval.IsListOfFnValue),
		afterReadLine: eval.NewPtrVariableWithValidator(
			eval.NewList(), eval.IsListOfFnValue),
	}
	ev.Editor = ed
	ev.Modules["le"] = makeModule(ed)
	return ed
}
開發者ID:elves,項目名稱:elvish,代碼行數:35,代碼來源:editor.go

示例4: source

func source(ev *eval.Evaler, fname string, notexistok bool) error {
	src, err := readFileUTF8(fname)
	if err != nil {
		if notexistok && os.IsNotExist(err) {
			return nil
		}
		fmt.Fprintln(os.Stderr, err)
		return err
	}

	err = ev.SourceText(src)
	if err != nil {
		printError(err, fname, "error", src)
	}
	return err
}
開發者ID:yonglehou,項目名稱:elvish,代碼行數:16,代碼來源:run.go

示例5: evalText

// evalText is like eval.Evaler.SourceText except that it reports errors.
func evalText(ev *eval.Evaler, name, src string) bool {
	n, err := parse.Parse(name, src)
	if err != nil {
		printError(err, "Parse error")
		return false
	}

	op, err := ev.Compile(n, name, src)
	if err != nil {
		printError(err, "Compile error")
		return false
	}
	err = ev.Eval(op, name, src)
	if err != nil {
		printError(err, "Exception")
		return false
	}
	return true
}
開發者ID:zhsj,項目名稱:elvish,代碼行數:20,代碼來源:run.go

示例6: NewEditor

// NewEditor creates an Editor.
func NewEditor(file *os.File, sigs chan os.Signal, ev *eval.Evaler, st *store.Store) *Editor {
	seq := -1
	if st != nil {
		var err error
		seq, err = st.NextCmdSeq()
		if err != nil {
			// TODO(xiaq): Also report the error
			seq = -1
		}
	}

	ed := &Editor{
		file:   file,
		writer: newWriter(file),
		reader: NewReader(file),
		sigs:   sigs,
		store:  st,
		evaler: ev,
		cmdSeq: seq,
	}
	ev.AddModule("le", makeModule(ed))
	return ed
}
開發者ID:wanlanjian,項目名稱:elvish,代碼行數:24,代碼來源:editor.go


注:本文中的github.com/elves/elvish/eval.Evaler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。