Skip to content

Commit

Permalink
Move message author into dedicated label component
Browse files Browse the repository at this point in the history
  • Loading branch information
fmueller committed May 28, 2024
1 parent a39724b commit 94f757d
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.fmueller.jarvis.conversation;

import com.github.fmueller.jarvis.conversation.ColorHelper.darker
import com.intellij.openapi.project.Project
import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBScrollPane
import com.intellij.util.ui.HTMLEditorKitBuilder
import com.intellij.util.ui.UIUtil
Expand All @@ -11,6 +12,7 @@ import com.vladsch.flexmark.html.HtmlRenderer
import com.vladsch.flexmark.parser.Parser
import com.vladsch.flexmark.util.data.MutableDataSet
import org.jdesktop.swingx.VerticalLayout
import java.awt.Font
import java.util.*
import java.util.regex.Pattern
import javax.swing.BorderFactory
Expand All @@ -29,13 +31,15 @@ class MessagePanel(message: Message, project: Project) : JPanel() {
private val bgColor = if (message.role == Role.ASSISTANT) assistantBgColor else userBgColor

init {
// TODO use label in MarkdownContentPanel to show the role
background = bgColor
layout = VerticalLayout(5)
border = BorderFactory.createEmptyBorder(10, 10, 10, 10)

val markdown = "**${if (message.role == Role.ASSISTANT) "Jarvis" else "You"}**\n\n${message.content}"
parseAndRenderMarkdown(markdown)
add(JBLabel(if (message.role == Role.ASSISTANT) "Jarvis" else "You").apply {
font = font.deriveFont(Font.BOLD)
border = BorderFactory.createEmptyBorder(0, 0, 0, 0)
})
parseAndRenderMarkdown(message.content)
}

// TODO add some tests for the parsing logic
Expand Down Expand Up @@ -71,6 +75,7 @@ class MessagePanel(message: Message, project: Project) : JPanel() {
text = markdownToHtml(markdown)
isEditable = false
background = bgColor
border = BorderFactory.createEmptyBorder(0, 0, 0, 0)
}
add(editorPane)
}
Expand All @@ -80,7 +85,9 @@ class MessagePanel(message: Message, project: Project) : JPanel() {
val editor = syntaxHelper.getHighlightedEditor(languageId, code)
if (editor != null) {
editor.contentComponent.border = BorderFactory.createEmptyBorder(5, 5, 5, 5)
add(JBScrollPane(editor.component))
add(JBScrollPane(editor.component).apply {
border = BorderFactory.createEmptyBorder(0, 0, 0, 0)
})
} else {
addNonCodeContent(code)
}
Expand Down

0 comments on commit 94f757d

Please sign in to comment.