Example #1
0
func script(fname string) {
	ev, _ := newEvalerAndStore()
	vs, err := ev.Source(fname)
	printError(err)
	eval.PrintExituses(vs)
	if err != nil || eval.HasFailure(vs) {
		os.Exit(1)
	}
}
Example #2
0
// TODO(xiaq): Currently only the editor deals with signals.
func interact() {
	ev, st := newEvalerAndStore()
	datadir, err := store.EnsureDataDir()
	printError(err)
	if err == nil {
		// XXX
		vs, err := ev.Source(datadir + "/rc.elv")
		if err != nil && !os.IsNotExist(err) {
			printError(err)
		}
		eval.PrintExituses(vs)
	}

	cmdNum := 0

	username := "******"
	user, err := user.Current()
	if err == nil {
		username = user.Username
	}
	hostname, err := os.Hostname()
	if err != nil {
		hostname = "???"
	}
	rpromptStr := username + "@" + hostname

	sigch := make(chan os.Signal, sigchSize)

	ed := edit.NewEditor(os.Stdin, sigch, st)

	for {
		cmdNum++
		name := fmt.Sprintf("<tty %d>", cmdNum)

		prompt := func() string {
			return sysutil.Getwd() + "> "
		}
		rprompt := func() string {
			return rpromptStr
		}

		signal.Notify(sigch)
		lr := ed.ReadLine(prompt, rprompt)
		signal.Stop(sigch)

		if lr.EOF {
			break
		} else if lr.Err != nil {
			fmt.Println("Editor error:", lr.Err)
			fmt.Println("My pid is", os.Getpid())
		}

		n, err := parse.Parse(name, lr.Line)
		printError(err)

		if err == nil {
			vs, err := ev.Eval(name, lr.Line, ".", n)
			printError(err)
			eval.PrintExituses(vs)
		}
	}
}