mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 04:19:41 -08:00
fix(accent): get correct accent color on Windows
This commit is contained in:
parent
8b21a67d7a
commit
42be6ab608
|
@ -43,7 +43,7 @@ This command is used to get the value of the following variables:
|
|||
case "shell":
|
||||
fmt.Println(env.Shell())
|
||||
case "accent":
|
||||
rgb, err := color.GetAccentColor()
|
||||
rgb, err := color.GetAccentColor(env)
|
||||
if err != nil {
|
||||
fmt.Println("error getting accent color:", err.Error())
|
||||
return
|
||||
|
|
|
@ -2,13 +2,14 @@ package color
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"oh-my-posh/environment"
|
||||
|
||||
"github.com/gookit/color"
|
||||
)
|
||||
|
||||
func MakeColors(palette Palette, cacheEnabled bool, accentColor string) (colors AnsiColors) {
|
||||
func MakeColors(palette Palette, cacheEnabled bool, accentColor string, env environment.Environment) (colors AnsiColors) {
|
||||
defaultColors := &DefaultColors{}
|
||||
defaultColors.SetAccentColor(accentColor)
|
||||
defaultColors.SetAccentColor(env, accentColor)
|
||||
colors = defaultColors
|
||||
if palette != nil {
|
||||
colors = &PaletteColors{ansiColors: colors, palette: palette}
|
||||
|
|
|
@ -30,18 +30,18 @@ func TestGetAnsiFromColorString(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMakeColors(t *testing.T) {
|
||||
colors := MakeColors(nil, false, "")
|
||||
colors := MakeColors(nil, false, "", nil)
|
||||
assert.IsType(t, &DefaultColors{}, colors)
|
||||
|
||||
colors = MakeColors(nil, true, "")
|
||||
colors = MakeColors(nil, true, "", nil)
|
||||
assert.IsType(t, &CachedColors{}, colors)
|
||||
assert.IsType(t, &DefaultColors{}, colors.(*CachedColors).ansiColors)
|
||||
|
||||
colors = MakeColors(testPalette, false, "")
|
||||
colors = MakeColors(testPalette, false, "", nil)
|
||||
assert.IsType(t, &PaletteColors{}, colors)
|
||||
assert.IsType(t, &DefaultColors{}, colors.(*PaletteColors).ansiColors)
|
||||
|
||||
colors = MakeColors(testPalette, true, "")
|
||||
colors = MakeColors(testPalette, true, "", nil)
|
||||
assert.IsType(t, &CachedColors{}, colors)
|
||||
assert.IsType(t, &PaletteColors{}, colors.(*CachedColors).ansiColors)
|
||||
assert.IsType(t, &DefaultColors{}, colors.(*CachedColors).ansiColors.(*PaletteColors).ansiColors)
|
||||
|
|
|
@ -2,13 +2,16 @@
|
|||
|
||||
package color
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"errors"
|
||||
"oh-my-posh/environment"
|
||||
)
|
||||
|
||||
func GetAccentColor() (*RGB, error) {
|
||||
func GetAccentColor(env environment.Environment) (*RGB, error) {
|
||||
return nil, errors.New("not implemented")
|
||||
}
|
||||
|
||||
func (d *DefaultColors) SetAccentColor(defaultColor string) {
|
||||
func (d *DefaultColors) SetAccentColor(env environment.Environment, defaultColor string) {
|
||||
if len(defaultColor) == 0 {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -2,36 +2,29 @@ package color
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
"oh-my-posh/environment"
|
||||
|
||||
"github.com/gookit/color"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
var (
|
||||
dwmapi = syscall.NewLazyDLL("dwmapi.dll")
|
||||
procDwmGetColorizationColor = dwmapi.NewProc("DwmGetColorizationColor")
|
||||
)
|
||||
|
||||
func GetAccentColor() (*RGB, error) {
|
||||
var accentColor uint32
|
||||
var pfOpaqueBlend bool
|
||||
_, _, e := procDwmGetColorizationColor.Call(
|
||||
uintptr(unsafe.Pointer(&accentColor)),
|
||||
uintptr(unsafe.Pointer(&pfOpaqueBlend)))
|
||||
if e != windows.ERROR_SUCCESS {
|
||||
return nil, errors.New("unable to get accent color")
|
||||
func GetAccentColor(env environment.Environment) (*RGB, error) {
|
||||
if env == nil {
|
||||
return nil, errors.New("unable to get color without environment")
|
||||
}
|
||||
// see https://stackoverflow.com/questions/3560890/vista-7-how-to-get-glass-color
|
||||
value, err := env.WindowsRegistryKeyValue(`HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ColorizationColor`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &RGB{
|
||||
R: byte(accentColor >> 16),
|
||||
G: byte(accentColor >> 8),
|
||||
B: byte(accentColor),
|
||||
R: byte(value.Dword >> 16),
|
||||
G: byte(value.Dword >> 8),
|
||||
B: byte(value.Dword),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (d *DefaultColors) SetAccentColor(defaultColor string) {
|
||||
rgb, err := GetAccentColor()
|
||||
func (d *DefaultColors) SetAccentColor(env environment.Environment, defaultColor string) {
|
||||
rgb, err := GetAccentColor(env)
|
||||
if err != nil {
|
||||
d.accent = &Color{
|
||||
Foreground: string(d.AnsiColorFromString(defaultColor, false)),
|
||||
|
|
|
@ -57,7 +57,7 @@ type Config struct {
|
|||
// environment and configuration.
|
||||
func (cfg *Config) MakeColors(env environment.Environment) color.AnsiColors {
|
||||
cacheDisabled := env.Getenv("OMP_CACHE_DISABLED") == "1"
|
||||
return color.MakeColors(cfg.Palette, !cacheDisabled, cfg.AccentColor)
|
||||
return color.MakeColors(cfg.Palette, !cacheDisabled, cfg.AccentColor, env)
|
||||
}
|
||||
|
||||
func (cfg *Config) print(message string) {
|
||||
|
|
Loading…
Reference in a new issue