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

Terminal queries do not work correctly in Windows #46

Open
erikgeiser opened this issue Jul 31, 2021 · 0 comments
Open

Terminal queries do not work correctly in Windows #46

erikgeiser opened this issue Jul 31, 2021 · 0 comments

Comments

@erikgeiser
Copy link

erikgeiser commented Jul 31, 2021

On Windows, the query functionality also returns the same incorrect values. This is because the query functions for Windows return hardcoded values. The new Windows Terminal may soon support queries as discussed in microsoft/terminal#3718. In the meantime, it should be documented that the query functions return dummy values on Windows.

This can be tested with the following code:

package main

import (
	"fmt"

	"github.com/muesli/termenv"
)

func profileName(profile termenv.Profile) string {
	switch profile {
	case termenv.Ascii:
		return "ASCII"
	case termenv.ANSI:
		return "ANSI"
	case termenv.ANSI256:
		return "ANSI256"
	case termenv.TrueColor:
		return "TrueColor"
	default:
		return "Unknown"
	}
}
func main() {
	fg := termenv.ForegroundColor()
	fgRGB := termenv.ConvertToRGB(fg)
	fgH, fgS, fgL := fgRGB.Hsl()

	bg := termenv.BackgroundColor()
	bgRGB := termenv.ConvertToRGB(bg)
	bgH, bgS, bgL := bgRGB.Hsl()

	fmt.Printf("Profile: %s\n", profileName(termenv.ColorProfile()))
	fmt.Printf("HasDarkBackground: %v\n", termenv.HasDarkBackground())
	fmt.Println()

	fmt.Printf("ForegroundColor:    %v\n", fg)
	fmt.Printf("ForegroundColorRGB: (%f, %f, %f)\n", fgRGB.R, fgRGB.G, fgRGB.B)
	fmt.Printf("ForegroundColorHSL: (%f, %f, %f)\n", fgH, fgS, fgL)
	fmt.Println()

	fmt.Printf("BackgroundColor:    %v\n", bg)
	fmt.Printf("BackgroundColorRGB: (%f, %f, %f)\n", bgRGB.R, bgRGB.G, bgRGB.B)
	fmt.Printf("BackgroundColorHSL: (%f, %f, %f)\n", bgH, bgS, bgL)
}

Windows Terminal

Tango Dark
image

Tango Light
image

Powershell in native Window

image

CMD

image

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

1 participant