@@ -3,6 +3,7 @@ package cc.unitmesh.terminal.sketch
3
3
import cc.unitmesh.devti.AutoDevBundle
4
4
import cc.unitmesh.devti.AutoDevIcons
5
5
import cc.unitmesh.devti.AutoDevNotifications
6
+ import cc.unitmesh.devti.settings.coder.coderSetting
6
7
import cc.unitmesh.devti.sketch.SketchToolWindow
7
8
import cc.unitmesh.devti.sketch.run.ProcessExecutor
8
9
import cc.unitmesh.devti.sketch.run.UIUpdatingWriter
@@ -17,6 +18,7 @@ import com.intellij.openapi.actionSystem.ActionManager
17
18
import com.intellij.openapi.actionSystem.AnAction
18
19
import com.intellij.openapi.actionSystem.AnActionEvent
19
20
import com.intellij.openapi.actionSystem.DefaultActionGroup
21
+ import com.intellij.openapi.actionSystem.DataContext
20
22
import com.intellij.openapi.application.ApplicationManager
21
23
import com.intellij.openapi.fileEditor.FileEditorManager
22
24
import com.intellij.openapi.project.Project
@@ -52,6 +54,8 @@ class TerminalSketchProvider : LanguageSketchProvider {
52
54
53
55
54
56
class TerminalLangSketch (val project : Project , var content : String ) : ExtensionLangSketch {
57
+ val enableAutoRunTerminal = project.coderSetting.state.enableAutoRunTerminal
58
+
55
59
var terminalWidget: JBTerminalWidget ? = null
56
60
var mainPanel: JPanel ? = null
57
61
val actionGroup = DefaultActionGroup (createConsoleActions())
@@ -68,7 +72,6 @@ class TerminalLangSketch(val project: Project, var content: String) : ExtensionL
68
72
add(codeSketch.getComponent(), BorderLayout .CENTER )
69
73
}
70
74
71
- // Add result display component
72
75
val resultSketch = CodeHighlightSketch (project, " " , CodeFence .findLanguage(" bash" ))
73
76
val resultPanel = JPanel (BorderLayout ()).apply {
74
77
add(resultSketch.getComponent(), BorderLayout .CENTER )
@@ -88,12 +91,14 @@ class TerminalLangSketch(val project: Project, var content: String) : ExtensionL
88
91
it.border = JBUI .Borders .customLine(UIUtil .getBoundsColor(), 1 , 1 , 1 , 1 )
89
92
}
90
93
94
+ private lateinit var executeAction: TerminalExecuteAction
95
+
91
96
init {
92
97
val projectDir = project.guessProjectDir()?.path
93
98
val terminalRunner = LocalTerminalDirectRunner .createTerminalRunner(project)
94
99
95
100
terminalWidget = terminalRunner.createTerminalWidget(this , projectDir, true ).also {
96
- it.preferredSize = Dimension (it.preferredSize.width, 120 )
101
+ it.preferredSize = Dimension (it.preferredSize.width, 80 )
97
102
}
98
103
99
104
codeSketch.getComponent().border = JBUI .Borders .empty()
@@ -113,7 +118,7 @@ class TerminalLangSketch(val project: Project, var content: String) : ExtensionL
113
118
}
114
119
115
120
fun createConsoleActions (): List <AnAction > {
116
- val executeAction = TerminalExecuteAction ()
121
+ executeAction = TerminalExecuteAction ()
117
122
118
123
val copyAction = object :
119
124
AnAction (" Copy" , AutoDevBundle .message(" sketch.terminal.copy.text" ), AllIcons .Actions .Copy ) {
@@ -203,8 +208,20 @@ class TerminalLangSketch(val project: Project, var content: String) : ExtensionL
203
208
204
209
override fun onDoneStream (allText : String ) {
205
210
if (content.lines().size > 1 ) return
211
+
206
212
ApplicationManager .getApplication().invokeLater {
207
213
terminalWidget!! .terminalStarter?.sendString(content, false )
214
+
215
+ if (enableAutoRunTerminal && ::executeAction.isInitialized) {
216
+ executeAction.actionPerformed(
217
+ AnActionEvent .createFromAnAction(
218
+ executeAction,
219
+ null ,
220
+ " AutoExecuteTerminal" ,
221
+ DataContext .EMPTY_CONTEXT
222
+ )
223
+ )
224
+ }
208
225
}
209
226
}
210
227
0 commit comments