Skip to content

Commit b8cc0e6

Browse files
committed
fix(terminal): handle terminal text retrieval with reflection
Use reflection to safely retrieve text from terminalWidget and handle potential exceptions. Notify user if the operation fails.
1 parent 065c149 commit b8cc0e6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

exts/ext-terminal/src/main/kotlin/cc/unitmesh/terminal/sketch/TerminalLangSketchProvider.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,13 @@ class TerminalLangSketchProvider : LanguageSketchProvider {
7070
val sendButton = JButton("Send to Sketch").apply {
7171
addMouseListener(object : MouseAdapter() {
7272
override fun mouseClicked(e: MouseEvent?) {
73-
val output = terminalWidget!!.text
74-
sendToSketch(project, output)
73+
try {
74+
val output = terminalWidget!!::class.java.getMethod("getText")
75+
.invoke(terminalWidget) as String
76+
sendToSketch(project, output)
77+
} catch (e: Exception) {
78+
AutoDevNotifications.notify(project, "Failed to send to Sketch")
79+
}
7580
}
7681
})
7782
}

0 commit comments

Comments
 (0)