|
1 | 1 | package com.dprint.toolwindow |
2 | 2 |
|
3 | 3 | import com.dprint.messages.DprintMessage |
4 | | -import com.intellij.execution.impl.ConsoleViewImpl |
| 4 | +import com.intellij.execution.filters.TextConsoleBuilderFactory |
| 5 | +import com.intellij.execution.ui.ConsoleView |
5 | 6 | import com.intellij.execution.ui.ConsoleViewContentType |
| 7 | +import com.intellij.openapi.Disposable |
6 | 8 | import com.intellij.openapi.components.Service |
7 | 9 | import com.intellij.openapi.project.Project |
8 | | -import com.intellij.psi.search.GlobalSearchScope |
| 10 | +import com.intellij.openapi.util.Disposer |
9 | 11 | import java.time.LocalDateTime |
10 | 12 | import java.time.format.DateTimeFormatter |
11 | 13 |
|
12 | 14 | @Service(Service.Level.PROJECT) |
13 | 15 | class Console( |
14 | 16 | val project: Project, |
15 | | -) { |
16 | | - val consoleView = ConsoleViewImpl(project, GlobalSearchScope.allScope(project), false, false) |
| 17 | +) : Disposable { |
| 18 | + val consoleView: ConsoleView = TextConsoleBuilderFactory.getInstance().createBuilder(project).console |
| 19 | + private val connection = project.messageBus.connect(this) |
17 | 20 |
|
18 | 21 | init { |
19 | | - with(project.messageBus.connect()) { |
20 | | - subscribe( |
21 | | - DprintMessage.DPRINT_MESSAGE_TOPIC, |
22 | | - object : DprintMessage.Listener { |
23 | | - override fun info(message: String) { |
24 | | - consoleView.print(decorateText(message), ConsoleViewContentType.LOG_INFO_OUTPUT) |
25 | | - } |
26 | | - |
27 | | - override fun warn(message: String) { |
28 | | - consoleView.print(decorateText(message), ConsoleViewContentType.LOG_WARNING_OUTPUT) |
29 | | - } |
30 | | - |
31 | | - override fun error(message: String) { |
32 | | - consoleView.print(decorateText(message), ConsoleViewContentType.LOG_ERROR_OUTPUT) |
33 | | - } |
34 | | - }, |
35 | | - ) |
36 | | - } |
| 22 | + subscribe() |
| 23 | + } |
| 24 | + |
| 25 | + private fun subscribe() { |
| 26 | + connection.subscribe( |
| 27 | + DprintMessage.DPRINT_MESSAGE_TOPIC, |
| 28 | + object : DprintMessage.Listener { |
| 29 | + override fun info(message: String) { |
| 30 | + consoleView.print(decorateText(message), ConsoleViewContentType.LOG_INFO_OUTPUT) |
| 31 | + } |
| 32 | + |
| 33 | + override fun warn(message: String) { |
| 34 | + consoleView.print(decorateText(message), ConsoleViewContentType.LOG_WARNING_OUTPUT) |
| 35 | + } |
| 36 | + |
| 37 | + override fun error(message: String) { |
| 38 | + consoleView.print(decorateText(message), ConsoleViewContentType.LOG_ERROR_OUTPUT) |
| 39 | + } |
| 40 | + }, |
| 41 | + ) |
| 42 | + } |
| 43 | + |
| 44 | + override fun dispose() { |
| 45 | + Disposer.dispose(consoleView) |
37 | 46 | } |
38 | 47 |
|
39 | 48 | private fun decorateText(text: String): String = |
|
0 commit comments