소스 검색

HUE-2864 [livy] Strip out ASCI color codes from the R output

Erick Tryzelaar 10 년 전
부모
커밋
b6d6bb872c
1개의 변경된 파일10개의 추가작업 그리고 3개의 파일을 삭제
  1. 10 3
      apps/spark/java/livy-repl/src/main/scala/com/cloudera/hue/livy/repl/sparkr/SparkRInterpreter.scala

+ 10 - 3
apps/spark/java/livy-repl/src/main/scala/com/cloudera/hue/livy/repl/sparkr/SparkRInterpreter.scala

@@ -30,7 +30,7 @@ import scala.io.Source
 
 private object SparkRInterpreter {
   val LIVY_END_MARKER = "# ----LIVY_END_OF_COMMAND----"
-  val EXPECTED_OUTPUT = f"\n> $LIVY_END_MARKER"
+  val EXPECTED_OUTPUT = f"> $LIVY_END_MARKER"
 }
 
 private class SparkRInterpreter(process: Process)
@@ -63,11 +63,13 @@ private class SparkRInterpreter(process: Process)
       readTo(EXPECTED_OUTPUT)
     }.last match {
       case (true, output) =>
+        val data = (output + takeErrorLines())
+
         Some(parse(write(Map(
           "status" -> "ok",
           "execution_count" -> (executionCount - 1),
           "data" -> Map(
-            "text/plain" -> (output + takeErrorLines())
+            "text/plain" -> data
           )
         ))))
       case (false, output) =>
@@ -91,7 +93,12 @@ private class SparkRInterpreter(process: Process)
       output.append(char.toChar)
       if (output.endsWith(marker)) {
         val result = output.toString()
-        (true, result.substring(0, result.length - marker.length).stripPrefix("\n"))
+        (
+          true,
+          result.substring(0, result.length - marker.length)
+            .replaceAll("\033\\[[0-9;]*[mG]", "") // Remove any ANSI color codes
+            .stripPrefix("\n")
+            .stripSuffix("\n"))
       } else {
         readTo(marker, output)
       }