[ide-console][cli-repl] Add more icons for readLine commands

This commit is contained in:
Dmitry Kovanikov
2015-09-04 16:19:40 +03:00
committed by Pavel V. Talanov
parent 724b208a5d
commit b4224bf9f3
8 changed files with 64 additions and 16 deletions
@@ -26,10 +26,9 @@ private val XML_PREAMBLE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
public class KotlinConsoleExecutor(
private val runner: KotlinConsoleRunner,
private val historyManager: KotlinConsoleHistoryManager
private val historyManager: KotlinConsoleHistoryManager,
private val historyHighlighter: KotlinHistoryHighlighter
) {
private val historyHighlighter = KotlinHistoryHighlighter(runner)
fun executeCommand() = WriteCommandAction.runWriteCommandAction(runner.project) {
val consoleView = runner.consoleView
val document = consoleView.editorDocument
@@ -34,11 +34,13 @@ import org.jetbrains.kotlin.console.actions.KtExecuteCommandAction
import org.jetbrains.kotlin.console.gutter.KotlinConsoleGutterContentProvider
import org.jetbrains.kotlin.console.gutter.KotlinConsoleIndicatorRenderer
import org.jetbrains.kotlin.console.gutter.ReplIcons
import org.jetbrains.kotlin.console.highlight.KotlinHistoryHighlighter
import org.jetbrains.kotlin.console.highlight.KotlinReplOutputHighlighter
import org.jetbrains.kotlin.console.highlight.ReplColors
import org.jetbrains.kotlin.idea.JetLanguage
import java.awt.Color
import java.awt.Font
import java.util.concurrent.ConcurrentHashMap
import javax.swing.Icon
import kotlin.properties.Delegates
@@ -51,10 +53,12 @@ public class KotlinConsoleRunner(
title: String,
path: String?
) : AbstractConsoleRunnerWithHistory<LanguageConsoleView>(myProject, title, path) {
private val editorToHighlighter = ConcurrentHashMap<EditorEx, RangeHighlighter>()
private val historyManager = KotlinConsoleHistoryManager(this)
private val historyHighlighter = KotlinHistoryHighlighter(this)
private var disposableDescriptor: RunContentDescriptor by Delegates.notNull()
val executor = KotlinConsoleExecutor(this, historyManager)
val executor = KotlinConsoleExecutor(this, historyManager, historyHighlighter)
var compilerHelper: KotlinConsoleCompilerHelper by Delegates.notNull()
override fun createProcess() = cmdLine.createProcess()
@@ -79,7 +83,10 @@ public class KotlinConsoleRunner(
override fun createProcessHandler(process: Process): OSProcessHandler {
val processHandler = KotlinReplOutputHandler(
KotlinReplOutputHighlighter(this, historyManager, testMode, previousCompilationFailed), process, cmdLine.commandLineString
historyHighlighter,
KotlinReplOutputHighlighter(this, historyManager, testMode, previousCompilationFailed),
process,
cmdLine.commandLineString
)
val consoleFile = consoleView.virtualFile
val keeper = KotlinConsoleKeeper.getInstance(project)
@@ -162,9 +169,15 @@ public class KotlinConsoleRunner(
0, editor.document.textLength, HighlighterLayer.LAST, null, HighlighterTargetArea.LINES_IN_RANGE
)
editorToHighlighter[editor] = indicatorHighlighter
indicatorHighlighter.gutterIconRenderer = indicator
}
fun changeConsoleEditorIndicator(newIcon: Icon) {
val editorHighlighter = editorToHighlighter[consoleView.consoleEditor]
editorHighlighter?.gutterIconRenderer = KotlinConsoleIndicatorRenderer(newIcon)
}
// this method shouldn't be called in normal usage; it is for test purpose only
fun dispose() {
processHandler.destroyProcess()
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.Key
import com.intellij.openapi.util.TextRange
import com.intellij.openapi.util.text.StringUtil
import org.jetbrains.kotlin.console.actions.logError
import org.jetbrains.kotlin.console.highlight.KotlinHistoryHighlighter
import org.jetbrains.kotlin.console.highlight.KotlinReplOutputHighlighter
import org.jetbrains.kotlin.diagnostics.Severity
import org.w3c.dom.Element
@@ -37,6 +38,7 @@ public val SOURCE_CHARS: Array<String> = arrayOf("\n", "#")
data class SeverityDetails(val severity: Severity, val description: String, val range: TextRange)
public class KotlinReplOutputHandler(
private val historyHighlighter: KotlinHistoryHighlighter,
private val outputHighlighter: KotlinReplOutputHighlighter,
process: Process,
commandLine: String
@@ -61,6 +63,8 @@ public class KotlinReplOutputHandler(
"HELP_PROMPT" -> outputHighlighter.printHelp(content)
"USER_OUTPUT" -> outputHighlighter.printUserOutput(content)
"REPL_RESULT" -> outputHighlighter.printResultWithGutterIcon(content)
"READLINE_START" -> historyHighlighter.isReadLineMode = true
"READLINE_END" -> historyHighlighter.isReadLineMode = false
"REPL_INCOMPLETE",
"COMPILE_ERROR" -> outputHighlighter.highlightCompilerErrors(createCompilerMessages(content))
"RUNTIME_ERROR" -> outputHighlighter.printRuntimeError(content)
@@ -21,11 +21,12 @@ import org.jetbrains.kotlin.idea.JetIcons
import javax.swing.Icon
public object ReplIcons {
public val BUILD_WARNING_INDICATOR: Icon = AllIcons.General.Information
public val BUILD_WARNING_INDICATOR: Icon = AllIcons.Ide.Warning_notifications
public val HISTORY_INDICATOR: Icon = AllIcons.General.MessageHistory
public val EDITOR_INDICATOR: Icon = JetIcons.LAUNCH
public val INCOMPLETE_INDICATOR: Icon = AllIcons.Nodes.Desktop
public val EDITOR_READLINE_INDICATOR: Icon = AllIcons.General.Balloon
public val COMMAND_MARKER: Icon = AllIcons.General.Run
public val READLINE_MARKER: Icon = AllIcons.Icons.Ide.SpeedSearchPrompt
// command result icons
public val SYSTEM_HELP: Icon = AllIcons.Actions.Menu_help
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.console.highlight
import com.intellij.execution.console.LanguageConsoleImpl
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.editor.ex.util.EditorUtil
import com.intellij.openapi.editor.markup.HighlighterLayer
@@ -29,6 +30,18 @@ import org.jetbrains.kotlin.console.gutter.ReplIcons
public class KotlinHistoryHighlighter(private val runner: KotlinConsoleRunner ) {
private val consoleView: LanguageConsoleImpl by lazy { runner.consoleView as LanguageConsoleImpl }
var isReadLineMode: Boolean = false
set(value) {
WriteCommandAction.runWriteCommandAction(runner.project) {
if (value)
runner.changeConsoleEditorIndicator(ReplIcons.EDITOR_READLINE_INDICATOR)
else
runner.changeConsoleEditorIndicator(ReplIcons.EDITOR_INDICATOR)
}
$isReadLineMode = value
}
fun printNewCommandInHistory(trimmedCommandText: String) {
val historyEditor = consoleView.historyViewer
@@ -50,11 +63,14 @@ public class KotlinHistoryHighlighter(private val runner: KotlinConsoleRunner )
historyEditor.markupModel let {
it.addRangeHighlighter(startOffset, endOffset, HighlighterLayer.LAST, null, HighlighterTargetArea.EXACT_RANGE)
} apply {
gutterIconRenderer = KotlinConsoleIndicatorRenderer(ReplIcons.COMMAND_MARKER)
val historyMarker = if (isReadLineMode) ReplIcons.READLINE_MARKER else ReplIcons.COMMAND_MARKER
gutterIconRenderer = KotlinConsoleIndicatorRenderer(historyMarker)
}
}
private fun addLineBreakIfNeeded(historyEditor: EditorEx) {
if (isReadLineMode) return
val historyDocument = historyEditor.document
val historyText = historyDocument.text
val textLength = historyText.length()