Example #1
0
// Override overrides the values in readline.Config that need to be
// set with wrapped values.
func Override(cfg *readline.Config) *readline.Config {
	cfg.Stdin = wrappedstreams.Stdin()
	cfg.Stdout = wrappedstreams.Stdout()
	cfg.Stderr = wrappedstreams.Stderr()

	cfg.FuncGetWidth = TerminalWidth
	cfg.FuncIsTerminal = IsTerminal

	rm := RawMode{StdinFd: int(wrappedstreams.Stdin().Fd())}
	cfg.FuncMakeRaw = rm.Enter
	cfg.FuncExitRaw = rm.Exit

	return cfg
}
Example #2
0
// StdinPiped returns true if the input is piped.
func (m *Meta) StdinPiped() bool {
	fi, err := wrappedstreams.Stdin().Stat()
	if err != nil {
		// If there is an error, let's just say its not piped
		return false
	}

	return fi.Mode()&os.ModeNamedPipe != 0
}
Example #3
0
// IsTerminal determines if this process is attached to a TTY.
func IsTerminal() bool {
	// Windows is always a terminal
	if runtime.GOOS == "windows" {
		return true
	}

	// Same implementation as readline but with our custom fds
	return readline.IsTerminal(int(wrappedstreams.Stdin().Fd())) &&
		(readline.IsTerminal(int(wrappedstreams.Stdout().Fd())) ||
			readline.IsTerminal(int(wrappedstreams.Stderr().Fd())))
}
Example #4
0
func (c *ConsoleCommand) modePiped(session *repl.Session, ui cli.Ui) int {
	var lastResult string
	scanner := bufio.NewScanner(wrappedstreams.Stdin())
	for scanner.Scan() {
		// Handle it. If there is an error exit immediately
		result, err := session.Handle(strings.TrimSpace(scanner.Text()))
		if err != nil {
			ui.Error(err.Error())
			return 1
		}

		// Store the last result
		lastResult = result
	}

	// Output the final result
	ui.Output(lastResult)

	return 0
}