@@ -17,6 +17,13 @@ enum MenuBarIndicator: Equatable {
1717 }
1818 }
1919
20+ var terminalText : String { " > \( text) " }
21+
22+ var usageUnderlineRange : NSRange ? {
23+ guard case . remaining = self else { return nil }
24+ return NSRange ( location: 2 , length: ( text as NSString ) . length)
25+ }
26+
2027 var accessibilityLabel : String {
2128 switch self {
2229 case . remaining( let percent) :
@@ -43,8 +50,8 @@ struct MenuBarUsageLabel: View {
4350/// them in one image prevents macOS menu bar label simplification from dropping
4451/// the custom outline while preserving the text.
4552enum CodexMenuBarIconRenderer {
46- static let size = NSSize ( width: 42 , height: 22 )
47- static let outlineLineWidth : CGFloat = 1.35
53+ static let size = NSSize ( width: 46 , height: 22 )
54+ static let outlineLineWidth : CGFloat = 1.2
4855
4956 static func image( for indicator: MenuBarIndicator ) -> NSImage {
5057 let image = NSImage ( size: size, flipped: false ) { rect in
@@ -57,19 +64,12 @@ enum CodexMenuBarIconRenderer {
5764 NSColor . black. setStroke ( )
5865 outline. stroke ( )
5966
60- let paragraph = NSMutableParagraphStyle ( )
61- paragraph. alignment = . center
62- let attributes : [ NSAttributedString . Key : Any ] = [
63- . font: NSFont . monospacedDigitSystemFont ( ofSize: 9 , weight: . bold) ,
64- . foregroundColor: NSColor . black,
65- . paragraphStyle: paragraph,
66- ]
67- let text = NSAttributedString ( string: indicator. text, attributes: attributes)
67+ let text = attributedText ( for: indicator)
6868 let textSize = text. size ( )
6969 let textRect = NSRect (
70- x: 5 ,
70+ x: 4 ,
7171 y: ( ( rect. height - textSize. height) / 2 ) + 0.5 ,
72- width: rect. width - 10 ,
72+ width: rect. width - 8 ,
7373 height: textSize. height
7474 )
7575 text. draw ( in: textRect)
@@ -79,8 +79,31 @@ enum CodexMenuBarIconRenderer {
7979 return image
8080 }
8181
82+ static func attributedText( for indicator: MenuBarIndicator ) -> NSAttributedString {
83+ let paragraph = NSMutableParagraphStyle ( )
84+ paragraph. alignment = . center
85+ let text = NSMutableAttributedString (
86+ string: indicator. terminalText,
87+ attributes: [
88+ . font: NSFont . monospacedSystemFont ( ofSize: 8.5 , weight: . semibold) ,
89+ . foregroundColor: NSColor . black,
90+ . paragraphStyle: paragraph,
91+ ]
92+ )
93+ if let range = indicator. usageUnderlineRange {
94+ text. addAttributes (
95+ [
96+ . underlineStyle: NSUnderlineStyle . single. rawValue,
97+ . underlineColor: NSColor . black,
98+ ] ,
99+ range: range
100+ )
101+ }
102+ return text
103+ }
104+
82105 static func outlinePath( in rect: NSRect ) -> NSBezierPath {
83- let drawingRect = rect. insetBy ( dx: 2.5 , dy: 2.5 )
106+ let drawingRect = rect. insetBy ( dx: 2 , dy: 2 )
84107 let center = CGPoint ( x: drawingRect. midX, y: drawingRect. midY)
85108 let radiusX = drawingRect. width / 2
86109 let radiusY = drawingRect. height / 2
@@ -89,7 +112,7 @@ enum CodexMenuBarIconRenderer {
89112
90113 for index in 0 ... sampleCount {
91114 let angle = ( Double ( index) / Double( sampleCount) ) * 2 * Double. pi
92- let lobe = 1 + 0.07 * cos( 8 * angle)
115+ let lobe = 1 + 0.04 * cos( 8 * angle)
93116 let point = CGPoint (
94117 x: center. x + CGFloat( cos ( angle) * lobe) * radiusX,
95118 y: center. y + CGFloat( sin ( angle) * lobe) * radiusY
0 commit comments