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