Skip to content

Commit c190d94

Browse files
committed
Re-render activity log + LLM output on light/dark switch; darker task banner green in light mode
- ArrowCursorTextView/FollowTextView: viewDidChangeEffectiveAppearance hook so a render actually fires when the appearance flips (before, the log only re-themed on the next text change and sat with the old palette on the new background). - LLMOutputTextView: rebuild the whole storage in the new palette and refresh TerminalNeoTheme — the append fast path only colored NEW text, leaving old lines in the previous theme's color. - TaskBannerView: solid darker green in light mode; systemGreen at 0.7 washed out the white text.
1 parent de12e05 commit c190d94

3 files changed

Lines changed: 58 additions & 8 deletions

File tree

‎Agent/Views/ActivityLog/ActivityLogView.swift‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,18 @@ final class ArrowCursorTextView: NSTextView {
3030
discardCursorRects()
3131
addCursorRect(visibleRect, cursor: .arrow)
3232
}
33+
34+
/// Light/dark switch — the coordinator re-renders with the new palette. Without this the
35+
/// log keeps its old colors until the next text change happens to trigger a render.
36+
var onAppearanceChange: (() -> Void)?
37+
38+
override func viewDidChangeEffectiveAppearance() {
39+
super.viewDidChangeEffectiveAppearance()
40+
onAppearanceChange?()
41+
}
3342
}
3443

35-
/// Scroll view that keeps the bottom pinned when its own height changes (e.g. the LLM
44+
/// Scroll view that keeps the bottom pinned
3645
/// Output HUD above it grows while streaming with "Activity Log Below HUD" on). AppKit keeps
3746
/// the clip origin fixed on resize, so without this the last lines drop out of view until
3847
/// the next throttled snap pulls them back — the up/down jump.
@@ -133,6 +142,7 @@ struct ActivityLogView: NSViewRepresentable {
133142
// Enable link detection and clicking
134143
textView.isAutomaticLinkDetectionEnabled = false
135144
textView.delegate = context.coordinator
145+
textView.onAppearanceChange = { [weak coord = context.coordinator] in coord?.scheduleRender() }
136146
context.coordinator.startObservingScroll(scrollView)
137147
context.coordinator.latestTextView = textView
138148
context.coordinator.latestScrollView = scrollView

‎Agent/Views/Header/TaskBannerView.swift‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import SwiftUI
66
struct TaskBannerView: View {
77
@Environment(\.accessibilityReduceMotion) private var reduceMotion
88
@Environment(\.colorSchemeContrast) private var colorSchemeContrast
9+
@Environment(\.colorScheme) private var colorScheme
910
private var highContrast: Bool { colorSchemeContrast == .increased }
11+
/// Light mode needs a solid, darker green — systemGreen at 0.7 washes out the white text.
12+
private var taskBarColor: Color {
13+
if highContrast { return Color(red: 0, green: 0.4, blue: 0) }
14+
return colorScheme == .dark ? Color.green.opacity(0.7) : Color(red: 0.13, green: 0.58, blue: 0.24)
15+
}
1016
let prompt: String
1117
let appleAIPrompt: String?
1218
@Binding var showAppleAIBanner: Bool
@@ -64,7 +70,7 @@ struct TaskBannerView: View {
6470
}
6571
.padding(.horizontal, 12)
6672
.padding(.vertical, 5)
67-
.background(highContrast ? Color(red: 0, green: 0.4, blue: 0) : Color.green.opacity(0.7))
73+
.background(taskBarColor)
6874

6975
if let goal = autoPilotGoal {
7076
let text = goal.isEmpty ? "(pending)" : goal

‎Agent/Views/Output/LLMOutputTextView.swift‎

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
3644
final 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

Comments
 (0)