-
-
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
ee7a857
commit 11bb6fa
Showing
10 changed files
with
129 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package color | ||
|
||
/* | ||
#cgo CFLAGS: -x objective-c | ||
#cgo LDFLAGS: -framework Cocoa | ||
#import <Cocoa/Cocoa.h> | ||
typedef struct { | ||
uint8_t R; | ||
uint8_t G; | ||
uint8_t B; | ||
} RGB; | ||
RGB getAccentColor() { | ||
RGB color = {0, 0, 0}; // Default to black | ||
NSColor *accentColor; | ||
if (@available(macOS 10.14, *)) { | ||
accentColor = [NSColor controlAccentColor]; | ||
} else { | ||
accentColor = [NSColor blueColor]; // Default fallback | ||
} | ||
NSColor *rgbColor = [accentColor colorUsingColorSpace:[NSColorSpace sRGBColorSpace]]; | ||
if (rgbColor) { | ||
CGFloat red, green, blue, alpha; | ||
[rgbColor getRed:&red green:&green blue:&blue alpha:&alpha]; | ||
color.R = (uint8_t)(red * 255); | ||
color.G = (uint8_t)(green * 255); | ||
color.B = (uint8_t)(blue * 255); | ||
} | ||
return color; | ||
} | ||
*/ | ||
import "C" | ||
import ( | ||
"errors" | ||
"time" | ||
|
||
"github.com/jandedobbeleer/oh-my-posh/src/runtime" | ||
) | ||
|
||
func GetAccentColor(env runtime.Environment) (*RGB, error) { | ||
defer env.Trace(time.Now()) | ||
|
||
color := C.getAccentColor() | ||
|
||
if color.R == 0 && color.G == 0 && color.B == 0 { | ||
err := errors.New("unable to get accent color") | ||
env.Error(err) | ||
return nil, err | ||
} | ||
|
||
return &RGB{ | ||
R: uint8(color.R), | ||
G: uint8(color.G), | ||
B: uint8(color.B), | ||
}, 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