Skip to content

Commit 2bc7072

Browse files
Fix Handling of Process Output
Make sure that the output of the ethersync daemon will be displayed in the UI.
1 parent 0b3bced commit 2bc7072

File tree

5 files changed

+64
-48
lines changed

5 files changed

+64
-48
lines changed

src/main/kotlin/io/github/ethersync/EthersyncServiceImpl.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.intellij.execution.configurations.GeneralCommandLine
44
import com.intellij.execution.process.ColoredProcessHandler
55
import com.intellij.execution.process.ProcessEvent
66
import com.intellij.execution.process.ProcessListener
7-
import com.intellij.execution.ui.ConsoleView
87
import com.intellij.openapi.application.EDT
98
import com.intellij.openapi.components.Service
109
import com.intellij.openapi.diagnostic.logger
@@ -26,6 +25,7 @@ import io.github.ethersync.protocol.*
2625
import io.github.ethersync.settings.AppSettings
2726
import io.github.ethersync.sync.Changetracker
2827
import io.github.ethersync.sync.Cursortracker
28+
import io.github.ethersync.ui.ToolWindow
2929
import kotlinx.coroutines.CoroutineScope
3030
import kotlinx.coroutines.Dispatchers
3131
import kotlinx.coroutines.launch
@@ -193,11 +193,10 @@ class EthersyncServiceImpl(
193193
}
194194
})
195195

196-
197196
val tw = ToolWindowManager.getInstance(project).getToolWindow("ethersync")!!
198-
val console = tw.contentManager.findContent("Daemon")!!.component
199-
if (console is ConsoleView) {
200-
console.attachToProcess(daemonProcess!!)
197+
val toolWindow = tw.contentManager.findContent("Daemon")!!.component
198+
if (toolWindow is ToolWindow) {
199+
toolWindow.attachToProcess(daemonProcess!!)
201200
}
202201

203202
tw.show()

src/main/kotlin/io/github/ethersync/EthersyncToolWindowFactory.kt

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.github.ethersync.ui
2+
3+
import com.intellij.openapi.project.Project
4+
import com.intellij.openapi.wm.ToolWindow
5+
import com.intellij.openapi.wm.ToolWindowFactory
6+
import com.intellij.ui.content.ContentFactory
7+
8+
9+
class EthersyncToolWindowFactory : ToolWindowFactory {
10+
11+
override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
12+
val panel = io.github.ethersync.ui.ToolWindow(project)
13+
14+
toolWindow.contentManager.addContent(ContentFactory.getInstance()
15+
.createContent(panel, "Daemon", true))
16+
}
17+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package io.github.ethersync.ui
2+
3+
import com.intellij.execution.filters.TextConsoleBuilderFactory
4+
import com.intellij.execution.process.ProcessHandler
5+
import com.intellij.execution.ui.ConsoleView
6+
import com.intellij.openapi.actionSystem.ActionGroup
7+
import com.intellij.openapi.actionSystem.ActionManager
8+
import com.intellij.openapi.actionSystem.AnAction
9+
import com.intellij.openapi.actionSystem.AnActionEvent
10+
import com.intellij.openapi.project.Project
11+
import io.github.ethersync.StartEthersyncDaemonAction
12+
import io.github.ethersync.StopEthersyncDaemonAction
13+
import java.awt.BorderLayout
14+
import javax.swing.JPanel
15+
16+
class ToolWindow(project: Project): JPanel() {
17+
18+
val console: ConsoleView
19+
20+
init {
21+
setLayout(BorderLayout())
22+
23+
console = TextConsoleBuilderFactory.getInstance()
24+
.createBuilder(project)
25+
.console
26+
27+
add(console.component, BorderLayout.CENTER)
28+
29+
val actionToolBar = ActionManager.getInstance().createActionToolbar("", object : ActionGroup() {
30+
override fun getChildren(p0: AnActionEvent?): Array<AnAction> {
31+
return arrayOf(StartEthersyncDaemonAction(), StopEthersyncDaemonAction())
32+
}
33+
}, true)
34+
35+
add(actionToolBar.component, BorderLayout.NORTH)
36+
}
37+
38+
fun attachToProcess(processHandler: ProcessHandler) {
39+
console.clear()
40+
console.attachToProcess(processHandler)
41+
}
42+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<toolWindow
2828
id="ethersync"
2929
icon="/toolbar.svg"
30-
factoryClass="io.github.ethersync.EthersyncToolWindowFactory"/>
30+
factoryClass="io.github.ethersync.ui.EthersyncToolWindowFactory"/>
3131

3232
<terminal.shellCommandHandler
3333
implementation="io.github.ethersync.StartEthersyncDaemonTerminalShellCommandHandler"/>

0 commit comments

Comments
 (0)