Skip to content

Commit daf8213

Browse files
committed
feat: filter error output
1 parent 876d873 commit daf8213

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

src/main/kotlin/com/github/xepozz/php_dump/CompositeWindowFactory.kt

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,21 @@ open class CompositeWindowFactory : ToolWindowFactory, DumbAware {
1717
get() = PhpDumpIcons.POT
1818

1919
override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
20-
val browser = JBCefBrowser.createBuilder()
21-
.setEnableOpenDevToolsMenuItem(true)
22-
.build()
23-
24-
val consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(project).console
25-
consoleView.addMessageFilter(UrlFilter())
26-
2720
val contentFactory = ContentFactory.getInstance()
2821
val contentManager = toolWindow.contentManager
2922

30-
val opcodesDumperService = toolWindow.project.getService(OpcodesDumperService::class.java)
31-
opcodesDumperService.browser = browser
32-
opcodesDumperService.consoleView = consoleView
23+
val opcodesTerminalLayout = run {
24+
val consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(project).console
25+
26+
val opcodesDumperService = toolWindow.project.getService(OpcodesDumperService::class.java)
27+
opcodesDumperService.consoleView = consoleView
3328

3429
val terminalLayout = OpcodesTerminalPanel(consoleView.component)
30+
OpcodesTerminalPanel(consoleView.component)
31+
}
3532

3633
contentFactory.apply {
37-
this.createContent(terminalLayout, "Opcodes", false).apply {
34+
this.createContent(opcodesTerminalLayout, "Opcodes", false).apply {
3835
contentManager.addContent(
3936
this.apply {
4037
this.isPinnable = true

src/main/kotlin/com/github/xepozz/php_dump/services/OpcodesDumperService.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@ package com.github.xepozz.php_dump.services
22

33
import com.intellij.execution.configurations.GeneralCommandLine
44
import com.intellij.execution.process.KillableColoredProcessHandler
5+
import com.intellij.execution.process.ProcessAdapter
6+
import com.intellij.execution.process.ProcessEvent
7+
import com.intellij.execution.process.ProcessOutputTypes
58
import com.intellij.execution.ui.ConsoleView
9+
import com.intellij.execution.ui.ConsoleViewContentType
610
import com.intellij.openapi.Disposable
711
import com.intellij.openapi.components.Service
812
import com.intellij.openapi.project.Project
13+
import com.intellij.openapi.util.Key
914
import com.intellij.ui.jcef.JBCefBrowser
1015
import com.jetbrains.php.config.PhpProjectConfigurationFacade
1116
import com.jetbrains.php.config.interpreters.PhpInterpretersManagerImpl
1217
import kotlinx.coroutines.CoroutineScope
1318
import kotlinx.coroutines.Dispatchers
1419
import kotlinx.coroutines.launch
1520
import kotlinx.coroutines.withContext
21+
import kotlin.math.log
1622

1723
@Service(Service.Level.PROJECT)
1824
class OpcodesDumperService(var project: Project) : Disposable {
19-
var browser: JBCefBrowser? = null
2025
var consoleView: ConsoleView? = null
2126

2227
override fun dispose() {
2328
consoleView?.dispose()
24-
browser?.dispose()
2529
}
2630

2731
fun dump(file: String, callback: () -> Unit) {
@@ -66,13 +70,19 @@ class OpcodesDumperService(var project: Project) : Disposable {
6670
val command = GeneralCommandLine(commandArgs)
6771
command.withRedirectErrorStream(false)
6872

69-
val commandLine = command.commandLineString + " 1>/dev/null"
70-
val processHandler = KillableColoredProcessHandler.Silent(command.createProcess(), commandLine, command.charset, emptySet())
73+
val processHandler = KillableColoredProcessHandler.Silent(command)
7174
processHandler.setShouldKillProcessSoftly(false)
7275
processHandler.setShouldDestroyProcessRecursively(true)
76+
processHandler.addProcessListener(object : ProcessAdapter() {
77+
override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) {
78+
if (outputType == ProcessOutputTypes.STDERR) {
79+
consoleView?.print(event.text, ConsoleViewContentType.NORMAL_OUTPUT)
80+
}
81+
}
82+
})
7383

7484
consoleView?.clear()
75-
consoleView?.attachToProcess(processHandler)
85+
// consoleView?.attachToProcess(processHandler)
7686
// consoleView?.requestScrollingToEnd()
7787

7888
processHandler.startNotify()

0 commit comments

Comments
 (0)