Skip to content

Commit

Permalink
feat(ext-terminal): introduce NewTerminalUiUtil class and refactor su…
Browse files Browse the repository at this point in the history
…ggestCommand method to support new UI context #135
  • Loading branch information
phodal committed Apr 4, 2024
1 parent 34ca497 commit 3533b1d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
@@ -0,0 +1,11 @@
package cc.unitmesh.terminal

import com.intellij.openapi.util.registry.Registry
import com.intellij.ui.NewUI
import org.jetbrains.plugins.terminal.LocalBlockTerminalRunner.Companion.BLOCK_TERMINAL_REGISTRY

class NewTerminalUiUtil {
fun isNewTerminal(): Boolean {
return NewUI.isEnabled() && !Registry.`is`(BLOCK_TERMINAL_REGISTRY, false)
}
}
Expand Up @@ -19,7 +19,6 @@ import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.ui.popup.JBPopupListener
import com.intellij.openapi.ui.popup.LightweightWindowEvent
import com.intellij.openapi.wm.IdeFocusManager
import com.intellij.terminal.JBTerminalWidget
import com.intellij.ui.DocumentAdapter
import com.intellij.ui.awt.RelativePoint
import com.intellij.ui.components.JBLabel
Expand Down Expand Up @@ -48,11 +47,13 @@ class ShellCommandSuggestAction : AnAction() {

showContentRenamePopup(contextComponent, getPreferredPopupPoint(e)) { data ->
val widget = TerminalUtil.getCurrentTerminalWidget(project) ?: return@showContentRenamePopup
suggestCommand(widget, data, project)
suggestCommand(data, project) { string ->
widget.terminalStarter?.sendString(string, true)
}
}
}

private fun suggestCommand(widget: JBTerminalWidget, data: String, project: Project) {
open fun suggestCommand(data: String, project: Project, function: (str: String) -> Unit?) {
val templateRender = TemplateRender(GENIUS_PRACTISES)
val template = templateRender.getTemplate("shell-suggest.vm")

Expand All @@ -77,7 +78,7 @@ class ShellCommandSuggestAction : AnAction() {
throw Exception("Shell command suggestion failed")
}

widget.terminalStarter?.sendString(it, true)
function(it)
}
} finally {
AutoDevStatusService.notifyApplication(AutoDevStatus.Ready)
Expand Down

0 comments on commit 3533b1d

Please sign in to comment.