diff --git a/CHANGELOG.md b/CHANGELOG.md index 25403d91..a720171e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Add `interactive: true` setting to improve support for interactive CLI apps + ([#217](https://github.com/go-task/task/issues/217), [#563](https://github.com/go-task/task/pull/563)). - Fix some `nil` errors ([#534](https://github.com/go-task/task/issues/534), [#573](https://github.com/go-task/task/pull/573)). - Add ability to declare an included Taskfile as optional diff --git a/docs/usage.md b/docs/usage.md index c3b49340..4b0fe773 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -950,6 +950,28 @@ $ task default > The `output` option can also be specified by the `--output` or `-o` flags. +## Interactive CLI application + +When running interactive CLI applications inside Task they can sometimes behave +weirdly, specially when the [output mode](#output-syntax) is set to something +other than `interleaved` (the default), or when interactive apps are ran in +parallel with other tasks. + +The `interactive: true` tells Task this is an interactive application, and Task +will try to optimize for it: + +```yaml +version: '3' + +tasks: + cmds: + - vim my-file.txt + interactive: true +``` + +If you still have problem running an interactive app through Task, please open +an issue about it. + ## Short task syntax Starting on Task v3, you can now write tasks with a shorter syntax if they diff --git a/task.go b/task.go index aca863b9..231552aa 100644 --- a/task.go +++ b/task.go @@ -415,13 +415,12 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi return nil } - stdOut := e.Output.WrapWriter(e.Stdout, t.Prefix) - stdErr := e.Output.WrapWriter(e.Stderr, t.Prefix) - + outputWrapper := e.Output if t.Interactive { - stdOut = output.Interleaved{}.WrapWriter(e.Stdout, t.Prefix) - stdErr = output.Interleaved{}.WrapWriter(e.Stderr, t.Prefix) + outputWrapper = output.Interleaved{} } + stdOut := outputWrapper.WrapWriter(e.Stdout, t.Prefix) + stdErr := outputWrapper.WrapWriter(e.Stderr, t.Prefix) defer func() { if _, ok := stdOut.(*os.File); !ok {