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

Fixed junk output in windows console. (#29) #44

Merged
merged 2 commits into from
Aug 9, 2021
Merged

Fixed junk output in windows console. (#29) #44

merged 2 commits into from
Aug 9, 2021

Conversation

frzam
Copy link
Contributor

@frzam frzam commented Aug 8, 2021

Fixed issue #29

For windows runtime, added originalMode or ENABLE_VIRTUAL_TERMINAL_PROCESSING in SetConsoleMode, and if case of any error, disabled color print.

For windows runtime, added originalMode or
ENABLE_VIRTUAL_TERMINAL_PROCESSING in SetConsoleMode, and if case of any
error, disabled color print.
main.go Outdated
stdout = &formatter.JSON{
Out: stdout,
Scheme: formatter.DefaultColorScheme,
// if disbleColor is true, then don't set Scheme.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better to declare a scheme variable instead of disableColor + duplication code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry my bad. Updated it.

main.go Outdated
Out: stderr,
Scheme: formatter.DefaultColorScheme,
// if disbleColor is true, then don't set Scheme.
if disableColor {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@frzam
Copy link
Contributor Author

frzam commented Aug 9, 2021

After disabling the color in windows in case of error, still I was getting one ResetColor code as junk.

reset-color

So I updated cp = append(append(cp, '\n'), cs.Color(ResetColor)...) with

// If cs is zero that means color is disabled, so only append '\n'
// else append '\n' and ResetColor.
if cs.IsZero() {
	cp = append(cp, '\n')
} else {
       cp = append(append(cp, '\n'), cs.Color(ResetColor)...)
}

Then it worked fine. I hope that was the right way. Let me know if it is not right.

Color output in cmd prompt in case of no errors.

color-output

@rs rs merged commit f759ec3 into rs:master Aug 9, 2021
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

Successfully merging this pull request may close these issues.

None yet

2 participants