Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable ANSI colors for Windows 10 and newer #496

Closed
hacdias opened this issue Feb 27, 2017 · 13 comments
Closed

Enable ANSI colors for Windows 10 and newer #496

hacdias opened this issue Feb 27, 2017 · 13 comments

Comments

@hacdias
Copy link
Contributor

hacdias commented Feb 27, 2017

Hey!

I've been reading a bit about Windows CMD and Virtual Processing. This code bellow is enough to make ANSI work on Windows 10 and newer:

handle := syscall.Handle(os.Stdout.Fd())
kernel32DLL := syscall.NewLazyDLL("kernel32.dll")
setConsoleModeProc := kernel32DLL.NewProc("SetConsoleMode")
setConsoleModeProc.Call(uintptr(handle), 0x0001|0x0002|0x0004)

More information about it here: https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx

It would be interesting to add!

@hacdias hacdias closed this as completed Feb 27, 2017
@hacdias hacdias reopened this Feb 27, 2017
@hacdias hacdias changed the title Enable ANSI colors for Windows Enable ANSI colors for Windows 10 and newer Feb 27, 2017
@ezk84
Copy link

ezk84 commented May 11, 2017

Indeed it would be nice to be able to see coloured output rather than the following in Windows 10:

?[34mINFO?[0m[0000] A walrus appears                              ?[34manimal?[0m=walrus

@hacdias
Copy link
Contributor Author

hacdias commented May 11, 2017

The addition of that code would solve that. What do you think @sirupsen?

@ezk84
Copy link

ezk84 commented May 11, 2017

It does solve the issue, I've tested it myself. Tricky things will be making sure this runs only in Windows.

Maybe creating a PR would move this faster (thought looking at the PR list, maybe no so much :D)

@hacdias
Copy link
Contributor Author

hacdias commented May 11, 2017

Done @ezk84 😄 Let's see what happens.

@ezk84
Copy link

ezk84 commented May 11, 2017

@hacdias I've added a PR for your PR, where I make a few alterations to make it more likely to be accepted into @sirupsen's repo.

@hacdias
Copy link
Contributor Author

hacdias commented May 12, 2017

Done! Thank you 😄

@dmathieu
Copy link
Contributor

It looks like this issue has been resolved. Closing.
Please let me know if this isn't the case.

@omarhachach
Copy link

Continues to be an issue for me, this is what my console looks like:

?[36mINFO?[0m[0000] Loaded module: Help
?[37mDEBU?[0m[0002] hi
?[37mDEBU?[0m[0003] Error sending message.                        ?[37merror?[0m="HTTP 400 Bad Request, {\"embed\": [\"url\"]}"

Using Ubuntu on Windows (in cmd) it seems to work, just not in a standard cmd window.

@hacdias
Copy link
Contributor Author

hacdias commented Sep 7, 2017

Make sure this isn't checked:

image

@omarhachach
Copy link

It isn't, still doesn't work.
cmd Properties

@hacdias
Copy link
Contributor Author

hacdias commented Sep 7, 2017

I just checked the code and they removed what I have added. Check this: https://github.com/sirupsen/logrus#formatters

@jrandalldemllo
Copy link

Indeed, commit e66f229 seems to be where it was removed.
Following README's instruction:

For Windows, see github.com/mattn/go-colorable.

go get github.com/mattn/go-colorable

Then setting logrus.SetOutput(colorable.NewColorableStdout()) fixed this for me, in case others were wondering.

@qiuker521
Copy link

yes, this issue +1,
seems #471 does not work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants