diff --git a/modules/cmdrunner/settings.go b/modules/cmdrunner/settings.go index 7f88f89f..faa7dda9 100644 --- a/modules/cmdrunner/settings.go +++ b/modules/cmdrunner/settings.go @@ -18,6 +18,7 @@ type Settings struct { args []string `help:"The arguments to the command, with each item as an element in an array. Example: for curl -I cisco.com, the arguments array would be ['-I', 'cisco.com']."` cmd string `help:"The terminal command to be run, withouth the arguments. Ie: ping, whoami, curl."` tail bool `help:"Automatically scroll to the end of the command output."` + pty bool `help:"Run the command in a pseudo-terminal. Some apps will behave differently if they feel in a terminal. For example, some apps will produce colorized output in a terminal, and non-colorized output otherwise. Default false" optional:"true"` maxLines int `help:"Maximum number of lines kept in the buffer."` // The dimensions of the module @@ -32,6 +33,7 @@ func NewSettingsFromYAML(name string, moduleConfig *config.Config, globalConfig args: utils.ToStrs(moduleConfig.UList("args")), cmd: moduleConfig.UString("cmd"), + pty: moduleConfig.UBool("pty", false), tail: moduleConfig.UBool("tail", false), maxLines: moduleConfig.UInt("maxLines", 256), } diff --git a/modules/cmdrunner/widget.go b/modules/cmdrunner/widget.go index 77ea058a..ecb4f2f0 100644 --- a/modules/cmdrunner/widget.go +++ b/modules/cmdrunner/widget.go @@ -124,13 +124,12 @@ func runCommandLoop(widget *Widget) { widget.resetBuffer() cmd := exec.Command(widget.settings.cmd, widget.settings.args...) cmd.Env = widget.environment() - f, err := pty.Start(cmd) - // The command has exited, print any error messages - if err != nil { - widget.handleError(err) + var err error + if widget.settings.pty { + err = runCommandPty(widget, cmd) + } else { + err = runCommand(widget, cmd) } - - _, err = io.Copy(widget.buffer, f) if err != nil { widget.handleError(err) } @@ -138,6 +137,22 @@ func runCommandLoop(widget *Widget) { } } +func runCommand(widget *Widget, cmd *exec.Cmd) error { + cmd.Stdout = widget + return cmd.Run() +} + +func runCommandPty(widget *Widget, cmd *exec.Cmd) error { + f, err := pty.Start(cmd) + // The command has exited, print any error messages + if err != nil { + return err + } + + _, err = io.Copy(widget.buffer, f) + return err +} + func (widget *Widget) handleError(err error) { widget.m.Lock() _, writeErr := widget.buffer.WriteString(err.Error())