Ejemplo n.º 1
0
func main() {
	ctx := newCtx()
	ctx.stdin = os.Stdin
	ctx.stdout = os.Stdout
	ctx.stderr = os.Stderr

	completer := &fineline.FilenameCompleter{"/"}

	l := fineline.NewLineReader(completer)
	l.Prompt = "$ "
	l.SetMaxHistory(10)

	for {
		str, err := l.Read()
		if err != nil {
			if err != io.EOF {
				fmt.Println("error", err)
			} else {
				fmt.Println()
			}
			break
		}
		if str == "" {
			fmt.Println()
			continue
		}
		if str == "\n" {
			continue
		}
		l.AddHistory(strings.TrimRight(str, "\n"))
		parser := newParser(str)
		cmd := parser.parseCommand()
		cmd.exec(nil, ctx)
	}
}
Ejemplo n.º 2
0
func (self *Shell) Run() {
	reader := fineline.NewLineReader(nil)

	for {
		command, err := reader.Read()

		command = strings.TrimRight(command, "\n")

		if err != nil {
			break
		}

		msg := &TextMessage{
			Body: command,

			Send: func(text string) {
				fmt.Println(text)
			},
			Reply: func(text string) {
				fmt.Println("You: " + text)
			},
		}

		switch command {
		default:
			self.brain.Receive(msg)
		case "close", "exit":
			self.brain.Shutdown()
			return
		}

	}
}