-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(color): enable accent color for macOS
resolves #5711
- Loading branch information
1 parent
b514c6e
commit 72b22c8
Showing
12 changed files
with
146 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package color | ||
|
||
import ( | ||
"errors" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/jandedobbeleer/oh-my-posh/src/runtime" | ||
) | ||
|
||
func parseHighlightColor(output string) (*RGB, error) { | ||
// Example output: "0.968627 0.831373 1.000000" | ||
components := strings.Fields(output) | ||
if len(components) != 4 { | ||
return nil, errors.New("unexpected highlight color format") | ||
} | ||
|
||
r, err := strconv.ParseFloat(components[0], 64) | ||
if err != nil { | ||
return nil, err | ||
} | ||
g, err := strconv.ParseFloat(components[1], 64) | ||
if err != nil { | ||
return nil, err | ||
} | ||
b, err := strconv.ParseFloat(components[2], 64) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &RGB{ | ||
R: uint8(r * 255), | ||
G: uint8(g * 255), | ||
B: uint8(b * 255), | ||
}, nil | ||
} | ||
|
||
func GetAccentColor(env runtime.Environment) (*RGB, error) { | ||
output, err := env.RunCommand("defaults", "read", "-g", "AppleAccentColor") | ||
if err != nil { | ||
env.Error(err) | ||
return nil, errors.New("unable to read accent color") | ||
} | ||
|
||
index, err := strconv.Atoi(output) | ||
if err != nil { | ||
env.Error(err) | ||
return nil, errors.New("unable to parse accent color index") | ||
} | ||
|
||
var accentColors = map[int]RGB{ | ||
-1: {152, 152, 152}, // Graphite | ||
0: {224, 55, 62}, // Red | ||
1: {247, 130, 25}, // Orange | ||
2: {255, 199, 38}, // Yellow | ||
3: {96, 186, 70}, // Green | ||
4: {0, 122, 255}, // Blue | ||
5: {149, 61, 150}, // Purple | ||
6: {247, 79, 159}, // Pink | ||
} | ||
|
||
color, exists := accentColors[index] | ||
if !exists { | ||
color = accentColors[6] // Default to graphite (white) | ||
} | ||
|
||
return &color, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters