mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-27 11:59:40 -08:00
feat(cli): get accent color
This commit is contained in:
parent
eb11aa9081
commit
3279821d0b
11
.vscode/launch.json
vendored
11
.vscode/launch.json
vendored
|
@ -109,6 +109,17 @@
|
|||
"--config=${workspaceRoot}/themes/default.omp.json"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Get value",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "debug",
|
||||
"program": "${workspaceRoot}/src",
|
||||
"args": [
|
||||
"get",
|
||||
"accent"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
|
|
|
@ -2,25 +2,29 @@ package cli
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"oh-my-posh/color"
|
||||
"oh-my-posh/environment"
|
||||
"time"
|
||||
|
||||
color2 "github.com/gookit/color"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// getCmd represents the get command
|
||||
var getCmd = &cobra.Command{
|
||||
Use: "get [shell|millis]",
|
||||
Use: "get [shell|millis|accent]",
|
||||
Short: "Get a value from oh-my-posh",
|
||||
Long: `Get a value from oh-my-posh.
|
||||
|
||||
This command is used to get the value of the following variables:
|
||||
|
||||
- shell
|
||||
- millis`,
|
||||
- millis
|
||||
- accent`,
|
||||
ValidArgs: []string{
|
||||
"millis",
|
||||
"shell",
|
||||
"accent",
|
||||
},
|
||||
Args: NoArgsOrOneValidArg,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
@ -38,6 +42,14 @@ This command is used to get the value of the following variables:
|
|||
fmt.Print(time.Now().UnixNano() / 1000000)
|
||||
case "shell":
|
||||
fmt.Println(env.Shell())
|
||||
case "accent":
|
||||
rgb, err := color.GetAccentColor()
|
||||
if err != nil {
|
||||
fmt.Println("error getting accent color:", err.Error())
|
||||
return
|
||||
}
|
||||
accent := color2.RGB(rgb.R, rgb.G, rgb.B)
|
||||
fmt.Println("#" + accent.Hex())
|
||||
default:
|
||||
_ = cmd.Help()
|
||||
}
|
||||
|
|
|
@ -19,6 +19,10 @@ func MakeColors(palette Palette, cacheEnabled bool, accentColor string) (colors
|
|||
return
|
||||
}
|
||||
|
||||
type RGB struct {
|
||||
R, G, B uint8
|
||||
}
|
||||
|
||||
// DefaultColors is the default AnsiColors implementation.
|
||||
type DefaultColors struct {
|
||||
accent *Color
|
||||
|
|
|
@ -2,6 +2,12 @@
|
|||
|
||||
package color
|
||||
|
||||
import "errors"
|
||||
|
||||
func GetAccentColor() (*RGB, error) {
|
||||
return nil, errors.New("not implemented")
|
||||
}
|
||||
|
||||
func (d *DefaultColors) SetAccentColor(defaultColor string) {
|
||||
if len(defaultColor) == 0 {
|
||||
return
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package color
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
|
@ -13,24 +14,33 @@ var (
|
|||
procDwmGetColorizationColor = dwmapi.NewProc("DwmGetColorizationColor")
|
||||
)
|
||||
|
||||
func (d *DefaultColors) SetAccentColor(defaultColor string) {
|
||||
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")
|
||||
}
|
||||
return &RGB{
|
||||
R: byte(accentColor >> 16),
|
||||
G: byte(accentColor >> 8),
|
||||
B: byte(accentColor),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (d *DefaultColors) SetAccentColor(defaultColor string) {
|
||||
rgb, err := GetAccentColor()
|
||||
if err != nil {
|
||||
d.accent = &Color{
|
||||
Foreground: string(d.AnsiColorFromString(defaultColor, false)),
|
||||
Background: string(d.AnsiColorFromString(defaultColor, true)),
|
||||
}
|
||||
return
|
||||
}
|
||||
r := byte(accentColor >> 16)
|
||||
g := byte(accentColor >> 8)
|
||||
b := byte(accentColor)
|
||||
foreground := color.RGB(r, g, b, false)
|
||||
background := color.RGB(r, g, b, true)
|
||||
foreground := color.RGB(rgb.R, rgb.G, rgb.B, false)
|
||||
background := color.RGB(rgb.R, rgb.G, rgb.B, true)
|
||||
d.accent = &Color{
|
||||
Foreground: foreground.String(),
|
||||
Background: background.String(),
|
||||
|
|
Loading…
Reference in a new issue