这是indexloc提供的服务,不要输入任何密码
Skip to content

Terminal queries do not work correctly in Windows #46

@erikgeiser

Description

@erikgeiser

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions