diff --git a/Source/gui/SNTMessageView.swift b/Source/gui/SNTMessageView.swift index ed1c000b..d3c62ccc 100644 --- a/Source/gui/SNTMessageView.swift +++ b/Source/gui/SNTMessageView.swift @@ -1,4 +1,5 @@ import SwiftUI + import santa_common_SNTConfigurator public let MAX_OUTER_VIEW_WIDTH = 560.0 @@ -48,7 +49,7 @@ public struct SNTMessageView: View { Spacer() - Text(AttributedString(blockMessage)) + AttributedText(blockMessage) .multilineTextAlignment(.center) .padding([.leading, .trailing], 15.0) .fixedSize() @@ -161,3 +162,19 @@ public func DismissButton( .keyboardShortcut(.escape, modifiers: .command) .help("⌘ Esc") } + +// AttributedText is like Text() but it supports all the features of NSAttributedString() +// by using NSTextField under the hood. +struct AttributedText: NSViewRepresentable { + private let attributedString: NSAttributedString + + init(_ attributedString: NSAttributedString) { + self.attributedString = attributedString + } + + func makeNSView(context: Context) -> NSTextField { + NSTextField(labelWithAttributedString: self.attributedString) + } + + func updateNSView(_ textField: NSTextField, context: Context) {} +}