Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion Packages/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Packages/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/nalexn/ViewInspector", from: "0.10.0"),
.package(url: "https://github.com/gonzalezreal/textual", from: "0.3.1"),
],
targets: [
.target(
Expand All @@ -20,7 +21,10 @@ let package = Package(
),
.target(
name: "RxCodeChatKit",
dependencies: ["RxCodeCore"],
dependencies: [
"RxCodeCore",
.product(name: "Textual", package: "textual"),
],
path: "Sources/RxCodeChatKit",
resources: [
.process("Resources"),
Expand Down
12 changes: 4 additions & 8 deletions Packages/Sources/RxCodeChatKit/ChatMessageBubble.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,10 @@ private struct CompactChatMessageBubble: View {
}

private func assistantText(_ text: String) -> some View {
ChatTextContentView(
markdown: text,
size: ClaudeTheme.messageSize(14),
color: ClaudeTheme.textPrimary,
lineSpacing: 2
)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.vertical, 2)
MarkdownContentView(text: text)
.foregroundStyle(ClaudeTheme.textPrimary)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.vertical, 2)
}

private var compactBoundaryBubble: some View {
Expand Down
73 changes: 8 additions & 65 deletions Packages/Sources/RxCodeChatKit/ChatTextContentView.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import SwiftUI
import RxCodeCore
#if os(macOS)
import AppKit
#endif

/// Renders inline chat text — plain strings, pre-built attributed strings, or
/// inline-only markdown — using native SwiftUI `Text`.
public struct ChatTextContentView: View {
enum Content {
case plain(String)
Expand Down Expand Up @@ -80,22 +79,6 @@ public struct ChatTextContentView: View {
}

public var body: some View {
#if os(macOS)
nativeBody
#else
swiftUIBody
#endif
}

private static func markdownAttributedString(_ text: String) -> AttributedString {
(try? AttributedString(
markdown: text,
options: .init(interpretedSyntax: .inlineOnlyPreservingWhitespace)
)) ?? AttributedString(text)
}

@ViewBuilder
private var swiftUIBody: some View {
let text = {
switch content {
case .plain(let value):
Expand All @@ -108,6 +91,7 @@ public struct ChatTextContentView: View {
text
.font(.system(size: size, weight: weight, design: design))
.foregroundStyle(color)
.tint(ClaudeTheme.accent)
.lineSpacing(lineSpacing)
.lineLimit(maximumNumberOfLines)
.textSelection(.enabled)
Expand All @@ -117,51 +101,10 @@ public struct ChatTextContentView: View {
})
}

#if os(macOS)
@ViewBuilder
private var nativeBody: some View {
switch content {
case .plain(let text):
NativeChatTextView(
text,
font: nativeFont,
color: NSColor(color),
lineSpacing: lineSpacing,
maximumNumberOfLines: maximumNumberOfLines,
openURL: openURL
)
case .attributed(let attributed):
NativeChatTextView(
attributed: attributed,
font: nativeFont,
color: NSColor(color),
lineSpacing: lineSpacing,
maximumNumberOfLines: maximumNumberOfLines,
openURL: openURL
)
}
}

private var nativeFont: NSFont {
if design == .monospaced {
return NSFont.monospacedSystemFont(ofSize: size, weight: nativeWeight)
}
return NSFont.systemFont(ofSize: size, weight: nativeWeight)
}

private var nativeWeight: NSFont.Weight {
switch weight {
case .ultraLight: return .ultraLight
case .thin: return .thin
case .light: return .light
case .regular: return .regular
case .medium: return .medium
case .semibold: return .semibold
case .bold: return .bold
case .heavy: return .heavy
case .black: return .black
default: return .regular
}
private static func markdownAttributedString(_ text: String) -> AttributedString {
(try? AttributedString(
markdown: text,
options: .init(interpretedSyntax: .inlineOnlyPreservingWhitespace)
)) ?? AttributedString(text)
}
#endif
}
Loading