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

Disable colors #150

Merged
merged 2 commits into from
Aug 8, 2023
Merged

Disable colors #150

merged 2 commits into from
Aug 8, 2023

Conversation

umputun
Copy link
Owner

@umputun umputun commented Aug 7, 2023

Add support of b/w output without colorization per host. The new param is --no-color.

The change was way too complicated for such a simple functionality because of the tight coupling between the core parts and the logger. I have refactored logging support and made it injectable.

@umputun umputun merged commit f0f214c into master Aug 8, 2023
4 checks passed
@umputun umputun deleted the disable-colors branch August 8, 2023 02:44
@knutov
Copy link
Contributor

knutov commented Aug 8, 2023

Something possible goes wrong, after this PR:


tasks:
  - name: print
    commands:
      - name: print
        echo: "hello world"

spot -p test.yml -t s2 --task print

spot v1.10.1-9aab799-2023-07-27T15:02:00Z
[s2 s2.xxxxxxxx:22] run task "print", commands: 1
[s2 s2.xxxxxxxx:22] completed command "print" {echo: hello world} (501ms)
[s2 s2.xxxxxxxx:22] completed task "print", commands: 1 (760ms)

spot v1.11.0-b97d854-2023-08-08T04:02:08Z
# <--- now any output here with this task

umputun added a commit that referenced this pull request Aug 8, 2023
@iRay
Copy link

iRay commented Nov 27, 2023

Seems some regression appeared once again.
Installed spot with brew.
Created a simple task the same like the one above.

tasks:
  - name: print
    commands:
      - name: print
        echo: "hello world"

Run with: spot -p spot.yml -t prod
Getting the next output:

spot v1.12.0-b327c23-2023-11-13T20:20:26Z
[104.xxx.yy.xxx:xx] run task "print", commands: 1
[104.xxx.yy.xxx:xx] completed command "print" {echo: hello world} (497ms)
[104.xxx.yy.xxx:xx] completed task "print", commands: 1 (1.444s)

All colors are "red". Thought it was something with term color scheme. Changed scheme, but everything remains the same in red colors.
Tried to execute ls -la on the remote system - no output.
After adding verbose with -v param I can see directory listing of the remote host.

Just in case uninstalled spot with brew and installed it with go install - the same behaviour.
Tried to run with --dbg to see if something is wrong, but with no luck. Everything looks fine.

System: MBP M1, macOS: Sonoma 14.1.1 (23B81)
P.S.
Verbose output:

spot v1.12.0-b327c23-2023-11-13T20:20:26Z
[104.xxx.yy.105:xx] run task "print", commands: 1
[104.xxx.yy.105:xx] run command "print"
[104.xxx.yy.105:xx]  > echo "hello world"
[104.xxx.yy.105:xx]  > hello world
[104.xxx.yy.105:xx] completed command "print" {echo: hello world} (1.235s)
[104.xxx.yy.105:xx] completed task "print", commands: 1 (2.189s)

@umputun
Copy link
Owner Author

umputun commented Nov 27, 2023

i can't reproduce "same color issue" with neither brew version or the current master

image

Tried to execute ls -la on the remote system - no output.
After adding verbose with -v param I can see directory listing of the remote host.

This is how it suppose to work, not sure what the issue here.

@umputun
Copy link
Owner Author

umputun commented Nov 27, 2023

I don't have any good explanation why everything is red for you, but can see only two possibilities:

  • both hosts makes red color by accident. there is a probability to have them the same color, nothing fancy is going on here - just a simple crc % colors, i.e.
// hostColorizer returns a function that formats a string with a color based on the hostAddr name.
func (s *colorizedWriter) hostColorizer(host string) func(format string, a ...interface{}) string {
	colors := []color.Attribute{
		color.FgHiRed, color.FgHiGreen, color.FgHiYellow,
		color.FgHiBlue, color.FgHiMagenta, color.FgHiCyan,
		color.FgRed, color.FgGreen, color.FgYellow,
		color.FgBlue, color.FgMagenta, color.FgCyan,
	}
	i := int(crc32.ChecksumIEEE([]byte(host))) % len(colors)
	c := colors[i]
	if s.monochrome {
		c = color.Reset
	}
	return color.New(c).SprintfFunc()
}
  • you have set SPOT_NO_COLOR env and red is the default in you terminal scheme

@iRay
Copy link

iRay commented Nov 27, 2023

I didn’t see output for ls command for the remote host (only with -v flag) and output was in red so it confused me.
With hostColorizer method now everything is clear, thank you!

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.

3 participants