Merge branch 'log-window-ui': monospace log window with smarter autoscroll

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
maxsoch 2026-07-07 06:07:28 +02:00
commit 323f64f921

View file

@ -14,22 +14,41 @@ class LogWindowController: NSWindowController {
self.init(window: window) self.init(window: window)
window.title = "Logs" window.title = "BrewBar Logs"
// the controller keeps the window alive; without this, closing the
// window would deallocate it and reopening would crash
window.isReleasedWhenClosed = false
window.center()
let scrollView = NSScrollView(frame: window.contentView!.bounds) let scrollView = NSScrollView(frame: window.contentView!.bounds)
scrollView.autoresizingMask = [.width, .height] scrollView.autoresizingMask = [.width, .height]
scrollView.hasVerticalScroller = true
textView = NSTextView(frame: scrollView.bounds) textView = NSTextView(frame: scrollView.bounds)
textView.isEditable = false textView.isEditable = false
textView.autoresizingMask = [.width, .height] textView.autoresizingMask = [.width, .height]
textView.font = .monospacedSystemFont(ofSize: 12, weight: .regular)
textView.textColor = .textColor // adapts to light/dark mode
textView.backgroundColor = .textBackgroundColor
textView.textContainerInset = NSSize(width: 8, height: 8)
scrollView.documentView = textView scrollView.documentView = textView
window.contentView?.addSubview(scrollView) window.contentView?.addSubview(scrollView)
} }
func update(text: String) { func update(text: String) {
// only follow the tail if the user is already at the bottom don't
// yank the scroll position away while they are reading older output
let wasAtBottom: Bool = if let scrollView = textView.enclosingScrollView {
scrollView.contentView.bounds.maxY >= textView.frame.height - 30
} else {
true
}
textView.string = text textView.string = text
if wasAtBottom {
textView.scrollToEndOfDocument(nil) textView.scrollToEndOfDocument(nil)
} }
} }
}