task icon indicating copy to clipboard operation
task copied to clipboard

v3: color output doesn't work properly on Windows

Open wdscxsj opened this issue 5 years ago • 6 comments

  • Task version: 3.0.0-preview4
  • Windows version: Windows 10 Enterprise 1909 64-bit

Taskfile.yml:

# https://taskfile.dev

version: '3'

tasks:
  default:
    cmds:
      - winver

Color output doesn't work in cmd.exe and powershell.exe:

1

Works well in ConEmu and Terminal:

2

With version: '2', it works well in ConEmu and Terminal (with no color), but still fails in cmd.exe and powershell.exe:

3

Maybe mattn's colorable is a good solution?

wdscxsj avatar Jun 12 '20 01:06 wdscxsj

Just got hit by that. Command help hints that it should be possible to disable colored output, there is a flag to enable it, but it is enabled by default.

Options:
  -c, --color             colored output (default true)

Either --no-color or #459 should be available for us poor windows users without color :(

telenieko avatar Apr 01 '21 15:04 telenieko

an alternative is to use --color=false . does that work on your end?

ivotron avatar Apr 01 '21 16:04 ivotron

an alternative is to use --color=false . does that work on your end?

That seems to have no effect on windows (v3.3.0)

❯ task --color=false test
←[0mtask: Command........

telenieko avatar Apr 01 '21 19:04 telenieko

Hi everybody, thanks for reporting this!

No sure what's happening on Windows. By the screenshots seems that it's not supported on CMD. Did anyone try on PowerShell?

--color=false is supported and does work on macOS. Need to check on Windows to see what's happening...

Anyway, just added support for NO_COLOR=1 as well so perhaps that works for now...

  • https://github.com/go-task/task/issues/459
  • https://github.com/fatih/color/pull/137

andreynering avatar May 31 '21 02:05 andreynering

No sure what's happening on Windows. By the screenshots seems that it's not supported on CMD. Did anyone try on PowerShell?

I am on PowerShell Core (Run: pwsh.exe)

--color=false is supported and does work on macOS. Need to check on Windows to see what's happening... Anyway, just added support for NO_COLOR=1 as well so perhaps that works for now...

Testing:

❯ task test
←[32mtask: [test] echo "hello go-task"
←[0mhello go-task

❯ task test --color=false
←[0mtask: [test] echo "hello go-task"
←[0mhello go-task

❯ $env:NO_COLOR=1
❯ task test
task: [test] echo "hello go-task"
hello go-task

telenieko avatar Jun 03 '21 08:06 telenieko

I've investigated a bit this issue and found out some things. If you run a task that has more than one task as dependency the colored output doesn't work only for the first one, subsequent ones will have no issues.

e.g. Running this:

  python:lint:
    desc: Lint Python code
    deps:
      - task: poetry:install-deps
    cmds:
      - poetry run flake8 --show-source

produces this:

image

This line is the "culprit": https://github.com/go-task/task/blob/6c73ab823b5e34430eacbb7b2ec14bd80995a58b/internal/execext/exec.go#L58

You can easily verify that's the cause by changing that line to:

	logger.Blue()(opts.Stdout, "NOT COLORED FIRST TIME\n")
	err = r.Run(ctx, p)
	logger.Blue()(opts.Stdout, "COLORED ALWAYS\n")
	return err

This is the result: image

Am not sure how to best fix this issue, I don't have enough knowledge about the codebase. There's probably some strange thing going on with stdout and stderr. 😕

Hope this helps.

silvanocerza avatar Sep 07 '21 14:09 silvanocerza

I've just tried the sample on Windows 11 with Task v3.26 on both cmd and powershell and it looks fine to me. Since this was reported in the Task v3 preview and no-one has commented or referenced this issue for nearly 2 years, I'm going to close it.

If anyone is still having this problem or thinks this isn't fixed, please open a new issue with steps to reproduce it.

pd93 avatar Jun 27 '23 09:06 pd93