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
31 changes: 26 additions & 5 deletions Sources/App/Assist/AssistView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,15 @@ struct AssistView: View {
AssistTypingIndicator()
.padding(.vertical, Spaces.half)
} else {
Text(item.content)
Text(item.markdown)
}
}
.padding(8)
.padding(.horizontal, 8)
.background(backgroundForChatItemType(item.itemType))
.roundedCorner(10, corners: roundedCornersForChatItemType(item.itemType))
.foregroundColor(.white)
.foregroundColor(foregroundForChatItemType(item.itemType))
.tint(tintForChatItemType(item.itemType))
.frame(maxWidth: .infinity, alignment: alignmentForChatItemType(item.itemType))
.textSelection(.enabled)
}
Expand Down Expand Up @@ -252,15 +253,35 @@ struct AssistView: View {
switch itemType {
case .input:
.haPrimary
case .output:
.gray
case .output, .typing:
.secondaryBackground
case .error:
.red
case .info, .typing:
case .info:
.gray.opacity(0.5)
}
}

private func foregroundForChatItemType(_ itemType: AssistChatItem.ItemType) -> Color {
switch itemType {
case .input, .error:
.white
case .info:
.secondary
default:
.primary
}
}

private func tintForChatItemType(_ itemType: AssistChatItem.ItemType) -> Color {
switch itemType {
case .input, .error:
.white
default:
.haPrimary
}
}

private func alignmentForChatItemType(_ itemType: AssistChatItem.ItemType) -> Alignment {
switch itemType {
case .input:
Expand Down
27 changes: 24 additions & 3 deletions Sources/Extensions/Watch/Assist/Views/ChatBubbleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ struct ChatBubbleView: View {
AssistTypingIndicator()
.padding(.vertical, Spaces.half)
} else {
Text(item.content)
Text(item.markdown)
}
}
.padding(4)
.padding(.horizontal, 4)
.background(backgroundForChatItemType(item.itemType))
.roundedCorner(6, corners: roundedCornersForChatItemType(item.itemType))
.foregroundColor(.white)
.foregroundColor(foregroundForChatItemType(item.itemType))
.tint(tintForChatItemType(item.itemType))
.frame(maxWidth: .infinity, alignment: alignmentForChatItemType(item.itemType))
.listRowBackground(Color.clear)
.id(item.id)
Expand All @@ -28,14 +29,34 @@ struct ChatBubbleView: View {
case .input:
.haPrimary
case .output, .typing:
.gray
.secondaryBackground
case .error:
.red
case .info:
.gray.opacity(0.5)
}
}

private func foregroundForChatItemType(_ itemType: AssistChatItem.ItemType) -> Color {
switch itemType {
case .input, .error:
.white
case .info:
.secondary
default:
.primary
}
}

private func tintForChatItemType(_ itemType: AssistChatItem.ItemType) -> Color {
switch itemType {
case .input, .error:
.white
default:
.haPrimary
}
}

private func alignmentForChatItemType(_ itemType: AssistChatItem.ItemType) -> Alignment {
switch itemType {
case .input:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xE5",
"green" : "0xE5",
"red" : "0xE5"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x28",
"green" : "0x28",
"red" : "0x28"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
15 changes: 15 additions & 0 deletions Sources/Shared/Assist/AssistChatItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ public struct AssistChatItem: Equatable {

public var id: String = UUID().uuidString
public let content: String
public var markdown: AttributedString {
var content = (try? AttributedString(
markdown: content,
options: AttributedString
.MarkdownParsingOptions(
interpretedSyntax: .inlineOnlyPreservingWhitespace,
failurePolicy: .returnPartiallyParsedIfPossible
)
)) ?? AttributedString(content)
for run in content.runs where run.attributes.link != nil {
content[run.range].underlineStyle = .single
}
return content
}

public let itemType: ItemType

public enum ItemType {
Expand Down
Loading