[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
@@ -54,10 +54,16 @@ public class ReplFromTerminal {
String replIdeMode = System.getProperty("repl.ideMode");
ideMode = replIdeMode != null && replIdeMode.equals("true");
// wrapper for `out` is required to escape every input in [ideMode];
// if [ideMode == false] then just redirects all input to [System.out]
// if user calls [System.setOut(...)] then undefined behaviour
replWriter = new ReplSystemOutWrapper(ideMode, System.out);
System.setOut(replWriter);
// wrapper for `in` is required to give user possibility of calling
// [readLine] from ide-console repl
if (ideMode) {
replReader = new ReplSystemInWrapper(System.in);
replReader = new ReplSystemInWrapper(System.in, replWriter);
System.setIn(replReader);
}
@@ -76,12 +82,6 @@ public class ReplFromTerminal {
}
}.start();
// wrapper for `out` is required to escape every input in [ideMode];
// if [ideMode == false] then just redirects all input to [System.out]
// if user calls [System.setOut(...)] then undefined behaviour
replWriter = new ReplSystemOutWrapper(ideMode, System.out);
System.setOut(replWriter);
try {
OutputStream outStream = System.out;
if (ideMode) {
@@ -19,7 +19,10 @@ package org.jetbrains.kotlin.cli.jvm.repl.messages
import java.io.ByteArrayOutputStream
import java.io.InputStream
public class ReplSystemInWrapper(private val stdin: InputStream) : InputStream() {
public class ReplSystemInWrapper(
private val stdin: InputStream,
private val replWriter: ReplSystemOutWrapper
) : InputStream() {
private var isXmlIncomplete = true
private var isLastScriptByteProcessed = false
private var byteBuilder = ByteArrayOutputStream()
@@ -30,6 +33,14 @@ public class ReplSystemInWrapper(private val stdin: InputStream) : InputStream()
get() = curBytePos == inputByteArray.size()
var isReplScriptExecuting = false
set(value) {
if (value)
replWriter.printlnReadLineStart()
else
replWriter.printlnReadLineEnd()
$isReplScriptExecuting = value
}
override synchronized fun read(): Int {
if (isLastScriptByteProcessed && isReplScriptExecuting) {
@@ -29,6 +29,8 @@ public class ReplSystemOutWrapper(private val ideMode: Boolean, standardOut: Pri
HELP_PROMPT,
USER_OUTPUT,
REPL_RESULT,
READLINE_START,
READLINE_END,
REPL_INCOMPLETE,
COMPILE_ERROR,
RUNTIME_ERROR,
@@ -61,6 +63,8 @@ public class ReplSystemOutWrapper(private val ideMode: Boolean, standardOut: Pri
fun printlnInit(x: String) = printlnWithEscaping(x, EscapeType.INITIAL_PROMPT)
fun printlnHelp(x: String) = printlnWithEscaping(x, EscapeType.HELP_PROMPT)
fun printlnResult(x: Any?) = printlnWithEscaping(x.toString(), EscapeType.REPL_RESULT)
fun printlnReadLineStart() = printlnWithEscaping("", EscapeType.READLINE_START)
fun printlnReadLineEnd() = printlnWithEscaping("", EscapeType.READLINE_END)
fun printlnIncomplete() = printlnWithEscaping("", EscapeType.REPL_INCOMPLETE)
fun printlnCompileError(x: String) = printlnWithEscaping(x, EscapeType.COMPILE_ERROR)
fun printlnRuntimeError(x: String) = printlnWithEscaping(x, EscapeType.RUNTIME_ERROR)