Skip to content

Commit 7b8a7dc

Browse files
Improve User Interface
- Render ANSI output properly and make output none editable - Use proper icons
1 parent 3862c41 commit 7b8a7dc

File tree

6 files changed

+81
-35
lines changed

6 files changed

+81
-35
lines changed

build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ version = "1.0-SNAPSHOT"
99

1010
repositories {
1111
mavenCentral()
12+
maven {
13+
url = uri("https://jitpack.io")
14+
}
1215
}
1316

1417
dependencies {
18+
implementation("com.github.Osiris-Team:jansi:2.4.6")
1519
implementation("org.eclipse.lsp4j:org.eclipse.lsp4j:0.23.1")
1620
implementation("org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc:0.23.1")
21+
implementation("org.jsoup:jsoup:1.18.3")
1722
}
1823

1924
// Configure Gradle IntelliJ Plugin

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ class ConnectToPeerAction : AnAction() {
1010
override fun actionPerformed(e: AnActionEvent) {
1111
val project = e.project ?: return
1212

13-
val address = Messages.showInputDialog(project, "Provide ethersync peer address", "Peer address", null)
13+
val address = Messages.showInputDialog(
14+
project,
15+
"Provide ethersync peer address",
16+
"Peer Address",
17+
Icons.PluginIcon
18+
)
19+
1420
if (address != null) {
1521
val service = project.service<EthersyncService>()
1622

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

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.github.ethersync
2+
3+
import com.intellij.openapi.util.IconLoader
4+
5+
object Icons {
6+
@JvmField
7+
val PluginIcon = IconLoader.getIcon("/META-INF/pluginIcon.svg", javaClass)
8+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package io.github.ethersync
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+
import org.fusesource.jansi.utils.UtilsAnsiHtml
8+
import org.jsoup.Jsoup
9+
import javax.swing.JEditorPane
10+
import javax.swing.JScrollPane
11+
12+
class ToolWindowFactory : ToolWindowFactory {
13+
14+
override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
15+
val logTextArea = JEditorPane()
16+
logTextArea.contentType = "text/html"
17+
logTextArea.isEditable = false
18+
19+
val utilsAnsiHtml = UtilsAnsiHtml()
20+
// TODO: the font-family doesn't have an effect
21+
val document = Jsoup.parse("""
22+
<html>
23+
<head>
24+
<style>
25+
body {
26+
font-family: 'Courier New', Courier, monospace;
27+
}
28+
</style>
29+
</head>
30+
<body></body>
31+
</html>
32+
""".trimIndent())
33+
val body = document.getElementsByTag("body")
34+
35+
project.messageBus.connect().subscribe(
36+
DaemonOutputNotifier.CHANGE_ACTION_TOPIC,
37+
object : DaemonOutputNotifier {
38+
override fun logOutput(line: String) {
39+
body.append(utilsAnsiHtml.convertAnsiToHtml(line))
40+
body.append("<br>")
41+
logTextArea.text = document.html()
42+
}
43+
}
44+
)
45+
46+
val content = ContentFactory.getInstance().createContent(JScrollPane(logTextArea), "Daemon Log", false)
47+
toolWindow.contentManager.addContent(content)
48+
}
49+
}

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<idea-plugin>
22
<id>io.github.ethersync</id>
33

4-
<name>ethersync</name>
5-
<vendor url="https://ethersync.github.io/ethersync/">Ethersync GitHub org</vendor>
4+
<name>Ethersync</name>
5+
<vendor url="https://ethersync.github.io/ethersync/">Ethersync GitHub Org</vendor>
66

77
<description><![CDATA[
88
Ethersync enables real-time co-editing of local text files. You can use it for pair programming or note-taking, for example! Think Google Docs, but from the comfort of your favorite text editor!
@@ -15,12 +15,19 @@
1515
serviceInterface="io.github.ethersync.EthersyncService"
1616
serviceImplementation="io.github.ethersync.EthersyncServiceImpl"/>
1717

18-
<toolWindow id="Ethersync Daemon Output" factoryClass="io.github.ethersync.DaemonToolWindowFactory" />
18+
<toolWindow
19+
id="Ethersync"
20+
factoryClass="io.github.ethersync.ToolWindowFactory"
21+
icon="io.github.ethersync.Icons.PluginIcon" />
1922
</extensions>
2023

2124
<actions>
22-
<action id="ConnectToPeerAction" class="io.github.ethersync.ConnectToPeerAction"
23-
text="Connect to ethersync peer" description="Connect to a running ethersync daemon">
25+
<action
26+
id="ConnectToPeerAction"
27+
class="io.github.ethersync.ConnectToPeerAction"
28+
text="Connect to Ethersync Peer"
29+
description="Connect to a running ethersync daemon"
30+
icon="io.github.ethersync.Icons.PluginIcon">
2431
<add-to-group group-id="ToolsMenu" anchor="first"/>
2532
</action>
2633
</actions>

0 commit comments

Comments
 (0)