[cli-repl] More accurate line breaks handling
This commit is contained in:
committed by
Pavel V. Talanov
parent
18304c7d7b
commit
cc2e320228
@@ -54,11 +54,11 @@ public class ReplSystemInWrapper(
|
||||
|
||||
byteBuilder.write(stdin.read())
|
||||
|
||||
if (byteBuilder.toString().endsWith(END_LINE)) {
|
||||
if (byteBuilder.toString().endsWith('\n')) {
|
||||
isXmlIncomplete = false
|
||||
isLastByteProcessed = false
|
||||
|
||||
inputByteArray = unescapedInput().toByteArray()
|
||||
inputByteArray = parseInput().toByteArray()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,16 +67,9 @@ public class ReplSystemInWrapper(
|
||||
return nextByte
|
||||
}
|
||||
|
||||
private fun unescapedInput(): String {
|
||||
private fun parseInput(): String {
|
||||
val xmlInput = byteBuilder.toString()
|
||||
val unescapedXml = parseXml(xmlInput)
|
||||
|
||||
val inputMessage = if (isReplScriptExecuting)
|
||||
IdeLinebreaksUnescaper.unescapeFromDiez(unescapedXml)
|
||||
else
|
||||
"$unescapedXml$END_LINE"
|
||||
|
||||
return inputMessage
|
||||
return "${parseXml(xmlInput)}$END_LINE"
|
||||
}
|
||||
|
||||
private fun resetBufferIfNeeded() {
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.messages
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.util.LineSeparator
|
||||
import java.io.PrintStream
|
||||
|
||||
public val END_LINE: String = "\n"
|
||||
|
||||
private val XML_PREAMBLE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
val END_LINE: String = LineSeparator.getSystemLineSeparator().separatorString
|
||||
val XML_PREAMBLE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
|
||||
public class ReplSystemOutWrapper(private val ideMode: Boolean, standardOut: PrintStream) : PrintStream(standardOut, true) {
|
||||
private enum class EscapeType {
|
||||
@@ -46,7 +46,7 @@ public class ReplSystemOutWrapper(private val ideMode: Boolean, standardOut: Pri
|
||||
override fun print(x: String) = printWithEscaping(x)
|
||||
override fun print(x: Any?) = printWithEscaping(x.toString())
|
||||
|
||||
private fun printlnWithEscaping(text: String, escapeType: EscapeType = EscapeType.USER_OUTPUT) = printWithEscaping("$text$END_LINE", escapeType)
|
||||
private fun printlnWithEscaping(text: String, escapeType: EscapeType = EscapeType.USER_OUTPUT) = printWithEscaping("$text\n", escapeType)
|
||||
|
||||
private fun printWithEscaping(text: String, escapeType: EscapeType = EscapeType.USER_OUTPUT) {
|
||||
if (ideMode)
|
||||
|
||||
@@ -34,9 +34,5 @@ fun parseXml(inputMessage: String): String {
|
||||
val input = docBuilder.parse(strToSource(inputMessage))
|
||||
|
||||
val root = input.firstChild as Element
|
||||
return root.textContent
|
||||
}
|
||||
|
||||
public object IdeLinebreaksUnescaper {
|
||||
@JvmStatic fun unescapeFromDiez(inputMessage: String) = StringUtil.replace(inputMessage, XML_REPLACEMENTS, SOURCE_CHARS)
|
||||
return StringUtil.replace(root.textContent, XML_REPLACEMENTS, SOURCE_CHARS)
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class KotlinConsoleExecutor(
|
||||
val xmlRes = "$XML_PREAMBLE" +
|
||||
"<input>" +
|
||||
"${StringUtil.escapeXml(
|
||||
StringUtil.replace("$command\n", SOURCE_CHARS, XML_REPLACEMENTS)
|
||||
StringUtil.replace(command, SOURCE_CHARS, XML_REPLACEMENTS)
|
||||
)}" +
|
||||
"</input>"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user