pretty-print + syntax highlight call/tool blocks
Call blocks: always pretty-print JSON + highlight on expand. Tool blocks: detect JSON/diff and highlight accordingly.
This commit is contained in:
parent
481f7f9d76
commit
ee3a0a1e76
51
gui/main.qml
51
gui/main.qml
|
|
@ -619,15 +619,30 @@ ApplicationWindow {
|
|||
onClicked: callText.visible = !callText.visible
|
||||
}
|
||||
}
|
||||
Label {
|
||||
Text {
|
||||
id: callText
|
||||
Layout.fillWidth: true
|
||||
text: block.blockContent
|
||||
textFormat: Text.PlainText
|
||||
wrapMode: Text.Wrap
|
||||
font.family: "monospace"
|
||||
font.pixelSize: Qt.application.font.pixelSize * 0.85
|
||||
opacity: 0.4
|
||||
opacity: 0.7
|
||||
visible: false
|
||||
color: palette.text
|
||||
|
||||
onVisibleChanged: {
|
||||
if (visible && textFormat === Text.PlainText) {
|
||||
try {
|
||||
let obj = JSON.parse(block.blockContent)
|
||||
let pretty = JSON.stringify(obj, null, 2)
|
||||
text = chatModel.highlightedHtml(pretty, "json")
|
||||
} catch(e) {
|
||||
text = chatModel.highlightedHtml(block.blockContent, "json")
|
||||
}
|
||||
textFormat = Text.RichText
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -646,17 +661,43 @@ ApplicationWindow {
|
|||
onClicked: toolText.visible = !toolText.visible
|
||||
}
|
||||
}
|
||||
Label {
|
||||
Text {
|
||||
id: toolText
|
||||
Layout.fillWidth: true
|
||||
text: block.blockContent
|
||||
textFormat: Text.PlainText
|
||||
wrapMode: Text.Wrap
|
||||
font.family: "monospace"
|
||||
font.pixelSize: Qt.application.font.pixelSize * 0.85
|
||||
opacity: 0.4
|
||||
opacity: 0.7
|
||||
visible: false
|
||||
maximumLineCount: 50
|
||||
color: palette.text
|
||||
maximumLineCount: 80
|
||||
elide: Text.ElideRight
|
||||
|
||||
onVisibleChanged: {
|
||||
if (visible && textFormat === Text.PlainText) {
|
||||
let content = block.blockContent
|
||||
let trimmed = content.trimStart()
|
||||
let lang = ""
|
||||
if (trimmed.startsWith("{") || trimmed.startsWith("[")) lang = "json"
|
||||
else if (trimmed.startsWith("---") || trimmed.startsWith("diff ")) lang = "diff"
|
||||
|
||||
if (lang === "json") {
|
||||
try {
|
||||
let obj = JSON.parse(content)
|
||||
let pretty = JSON.stringify(obj, null, 2)
|
||||
text = chatModel.highlightedHtml(pretty, "json")
|
||||
} catch(e) {
|
||||
text = chatModel.highlightedHtml(content, "json")
|
||||
}
|
||||
textFormat = Text.RichText
|
||||
} else if (lang) {
|
||||
text = chatModel.highlightedHtml(content, lang)
|
||||
textFormat = Text.RichText
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in New Issue