diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/InlayScratchFileRenderer.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/InlayScratchFileRenderer.kt index b200b102b5b..a2d002759ba 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/InlayScratchFileRenderer.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/InlayScratchFileRenderer.kt @@ -21,7 +21,7 @@ class InlayScratchFileRenderer(val text: String, private val outputType: Scratch private fun getFontInfo(editor: Editor): FontInfo { val colorsScheme = editor.colorsScheme val fontPreferences = colorsScheme.fontPreferences - val attributes = getAttributes() + val attributes = getAttributesForOutputType(outputType) val fontStyle = attributes.fontType return ComplementaryFontsRegistry.getFontAbleToDisplay( 'a'.toInt(), fontStyle, fontPreferences, FontInfo.getFontRenderContext(editor.contentComponent) @@ -34,7 +34,7 @@ class InlayScratchFileRenderer(val text: String, private val outputType: Scratch } override fun paint(editor: Editor, g: Graphics, r: Rectangle, textAttributes: TextAttributes) { - val attributes = getAttributes() + val attributes = getAttributesForOutputType(outputType) val fgColor = attributes.foregroundColor ?: return g.color = fgColor val fontInfo = getFontInfo(editor) @@ -43,36 +43,7 @@ class InlayScratchFileRenderer(val text: String, private val outputType: Scratch g.drawString(text, r.x, r.y + metrics.ascent) } - private fun getAttributes(): TextAttributes { - return when (outputType) { - ScratchOutputType.OUTPUT -> userOutputAttributes - ScratchOutputType.RESULT -> normalAttributes - ScratchOutputType.ERROR -> errorAttributes - } - } - override fun toString(): String { return "${text.takeWhile { it.isWhitespace() }}${outputType.name}: ${text.trim()}" } - - companion object { - private val normalAttributes = TextAttributes( - JBColor.GRAY, - null, null, null, - Font.ITALIC - ) - - private val errorAttributes = TextAttributes( - JBColor(Colors.DARK_RED, Colors.DARK_RED), - null, null, null, - Font.ITALIC - ) - - private val userOutputColor = Color(0x5C5CFF) - private val userOutputAttributes = TextAttributes( - JBColor(userOutputColor, userOutputColor), - null, null, null, - Font.ITALIC - ) - } -} \ No newline at end of file +} diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/outputStylingUtils.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/outputStylingUtils.kt new file mode 100644 index 00000000000..df7ff00506b --- /dev/null +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/output/outputStylingUtils.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.scratch.output + +import com.intellij.openapi.editor.markup.TextAttributes +import com.intellij.ui.Colors +import com.intellij.ui.JBColor +import java.awt.Color +import java.awt.Font + +fun getAttributesForOutputType(outputType: ScratchOutputType): TextAttributes { + return when (outputType) { + ScratchOutputType.OUTPUT -> userOutputAttributes + ScratchOutputType.RESULT -> normalAttributes + ScratchOutputType.ERROR -> errorAttributes + } +} + +private val userOutputColor = Color(0x5C5CFF) + +private val normalAttributes = TextAttributes().apply { + foregroundColor = JBColor.GRAY + fontType = Font.ITALIC +} + +private val errorAttributes = TextAttributes().apply { + foregroundColor = JBColor(Colors.DARK_RED, Colors.DARK_RED) + fontType = Font.ITALIC +} + +private val userOutputAttributes = TextAttributes().apply { + foregroundColor = JBColor(userOutputColor, userOutputColor) + fontType = Font.ITALIC +}