@@ -30,9 +30,17 @@ final class FollowTextView: NSTextView {
3030 discardCursorRects ( )
3131 addCursorRect ( visibleRect , cursor : . arrow )
3232 }
33+
34+ /// Light/dark switch — the coordinator rebuilds storage in the new palette.
35+ var onAppearanceChange : ( ( ) -> Void ) ?
36+
37+ override func viewDidChangeEffectiveAppearance ( ) {
38+ super . viewDidChangeEffectiveAppearance ( )
39+ onAppearanceChange ? ( )
40+ }
3341}
3442
35- /// NSScrollView subclass that fires callbacks on scroll/hover. Intercepts scrollWheel directly so auto-follow disables immediately.
43+ /// NSScrollView subclass that fires callbacks on scroll/hover.
3644final class FollowScrollView : NSScrollView {
3745 var onUserScroll : ( ( ) -> Void ) ?
3846 var onHoverChange : ( ( Bool ) -> Void ) ?
@@ -119,6 +127,7 @@ struct LLMOutputTextView: NSViewRepresentable {
119127 coord . textView = textView
120128 coord . onContentHeight = onContentHeight
121129 coord . startObservingScroll ( scrollView )
130+ textView . onAppearanceChange = { [ weak coord ] in coord ? . rerenderForAppearanceChange ( ) }
122131
123132 // Hard switch: any user scroll wheel/trackpad event disables auto-follow
124133 // immediately, before the bounds observer would have a chance to fire.
@@ -158,11 +167,8 @@ struct LLMOutputTextView: NSViewRepresentable {
158167 let contentNS = contentText as NSString
159168 let contentLen = contentNS . length
160169
161- let isDark = tv . effectiveAppearance . bestMatch ( from : [ . darkAqua , . aqua ] ) == . darkAqua
162- let textColor : NSColor = isDark
163- ? NSColor ( red : 0.2 , green : 0.9 , blue : 0.3 , alpha : 1 )
164- : NSColor ( red : 0.05 , green : 0.35 , blue : 0.1 , alpha : 1 )
165- let font = NSFont . monospacedSystemFont ( ofSize : 16.5 , weight : . regular )
170+ let textColor = Self . textColor ( for : tv )
171+ let font = Self . font
166172 let cursorAttrs : [ NSAttributedString . Key : Any ] = [
167173 . font : font ,
168174 . foregroundColor : cursorVisible ? textColor : NSColor . clear
@@ -291,6 +297,16 @@ struct LLMOutputTextView: NSViewRepresentable {
291297 /// Characters that can start/close markdown styling, plus newline (line-level syntax like "- " / "#").
292298 private static let markdownChars = CharacterSet ( charactersIn : " *`_#-[]|>~ \n " )
293299
300+ static let font = NSFont . monospacedSystemFont ( ofSize : 16.5 , weight : . regular )
301+
302+ /// Neo-green body color for the view's current light/dark appearance.
303+ static func textColor ( for view : NSView ) -> NSColor {
304+ let isDark = view . effectiveAppearance . bestMatch ( from : [ . darkAqua , . aqua ] ) == . darkAqua
305+ return isDark
306+ ? NSColor ( red : 0.2 , green : 0.9 , blue : 0.3 , alpha : 1 )
307+ : NSColor ( red : 0.05 , green : 0.35 , blue : 0.1 , alpha : 1 )
308+ }
309+
294310 /// NSTextTable owning the paragraph at `index`, or nil if not a table cell / out of range.
295311 private static func table ( in str : NSAttributedString , at index : Int ) -> NSTextTable ? {
296312 guard index >= 0 , index < str . length ,
@@ -354,6 +370,24 @@ struct LLMOutputTextView: NSViewRepresentable {
354370 }
355371 }
356372
373+ /// Light/dark switch: rebuild the whole storage in the new palette. The append fast path
374+ /// only colors NEW text, so without this old lines keep the previous theme's color.
375+ func rerenderForAppearanceChange ( ) {
376+ guard let tv = textView , let storage = tv . textStorage , ! lastContentText . isEmpty else { return }
377+ TerminalNeoTheme . updateAppearance ( )
378+ let hadCursor = storage . string . hasSuffix ( " █ " )
379+ let rendered = NSMutableAttributedString ( attributedString : TerminalNeoRenderer . render ( lastContentText ) )
380+ if hadCursor {
381+ rendered . append ( NSAttributedString ( string : " █ " , attributes : [
382+ . font : LLMOutputTextView . font , . foregroundColor : LLMOutputTextView . textColor ( for : tv )
383+ ] ) )
384+ }
385+ storage . beginEditing ( )
386+ storage . setAttributedString ( rendered )
387+ storage . endEditing ( )
388+ if ! autoFollowDisabled { snapToEnd ( tv ) }
389+ }
390+
357391 /// True iff the visible bottom is within 5pt of the content end —
358392 /// tight threshold so we only re-engage when truly at bottom.
359393 func isAtBottom ( _ textView : NSTextView ) -> Bool {
0 commit comments