--- plymouth-0.9.2/src/libply/ply-terminal-session.c
+++ plymouth-0.9.2/src/libply/ply-terminal-session.c	2017-01-18 12:13:22.232318860 +0000
@@ -65,6 +65,190 @@ static bool ply_terminal_session_execute
 static void ply_terminal_session_start_logging (ply_terminal_session_t *session);
 static void ply_terminal_session_stop_logging (ply_terminal_session_t *session);
 
+enum {
+  ESnormal,
+  ESesc,
+  ESsquare,
+  ESgetpars,
+  ESgotpars,
+  ESfunckey,
+  EShash,
+  ESsetG0,
+  ESsetG1,
+  ESpercent,
+  ESignore,
+  ESnonstd,
+  ESpalette
+};
+
+#define NPAR 16
+static unsigned int state = ESnormal;
+static int npar;
+
+static uint8_t color_code[10] = {'\033', '[', 0, 0, 0, 0, 0, 0, 0, 0};
+static unsigned int color_index = 2;
+static uint8_t color_seperator = 0;
+
+static unsigned int ply_terminal_strip_control_codes(ply_logger_t *logger,
+                                                 uint8_t* buf, size_t s)
+{
+  uint8_t c;
+  size_t r = s;
+  ssize_t up;
+  uint8_t result[6] = {0, 0, 0, 0, 0, 0};
+  unsigned int index = 0;
+
+  while (r > 0) {
+    c = (unsigned char)*buf;
+
+    switch (state) {
+    case ESnormal:
+    default:
+      state = ESnormal;
+      switch (c) {
+      case '\033':
+        state = ESesc;
+        break;
+      case 128 + 27:
+        state = ESsquare;
+        break;
+      case 14:
+      case 15:
+      case 24:
+      case 26:
+        break;
+      case 0 ... 8:
+      case 16 ... 23:
+      case 25:
+      case 28 ... 31:
+        result [0] = '^';
+        result [1] = c + 64;
+        ply_logger_inject_bytes (logger, result, 2);
+        index += 2;
+        break;
+      case 127:
+        result [0] = '^';
+        result [1] = '?';
+        ply_logger_inject_bytes (logger, result, 2);
+        index += 2;
+        break;
+      case 128 ... 128+26:
+      case 128+28 ... 159:
+        up = snprintf((char*)result, sizeof(result), "\\%03o", c);
+        if (up > 0) {
+            ply_logger_inject_bytes (logger, result, up);
+            index += up;
+        }
+        break;
+      case '\t': 
+      case '\r': 
+      case '\n':
+      default:
+        result [0] = c;
+        ply_logger_inject_bytes (logger, result, 1);
+        index++;
+        break;
+      }
+      break;
+    case ESesc:
+      state = ESnormal;
+      switch ((unsigned char)c) {
+      case '[':
+        state = ESsquare;
+        break;
+      case ']':
+        state = ESnonstd;
+        break;
+      case '%':
+        state = ESpercent;
+        break;
+      case '(':
+        state = ESsetG0;
+        break;
+      case ')':
+        state = ESsetG1;
+        break;
+      case '#':
+        state = EShash;
+        break;
+      default:
+        break;
+      }
+      break;
+    case ESnonstd:
+      if (c == 'P') {
+        npar = 0;
+        state = ESpalette;
+      } else if (c == 'R')
+        state = ESnormal;
+      else
+        state = ESnormal;
+      break;
+    case ESpalette:
+      if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') ||
+          (c >= 'a' && c <= 'f')) {
+        npar++;
+        if (npar == 7)
+          state = ESnormal;
+      } else
+        state = ESnormal;
+      break;
+    case ESsquare:
+      npar = 0;
+      state = ESgetpars;
+      if (c == '[') {
+        state = ESfunckey;
+        break;
+      }
+      if (c == '?')
+        break;
+    case ESgetpars:
+      if (c == ';' && npar < NPAR - 1) {
+          if (color_index > 1 && color_index < 7) {
+              color_seperator = 1;
+              color_code [color_index++] = c;
+          }
+        npar++;
+        break;
+      } else if (c >= '0' && c <= '9') {
+        if (color_index < 7) {
+            if (!color_seperator && color_index >= 4)
+                break;
+
+            color_code [color_index++] = c;
+        }
+        break;
+      } else {
+          if (c == 'm' && color_index <=7) {
+            color_code [color_index++] = c;
+            ply_logger_inject_bytes (logger, color_code, color_index);
+            index += color_index;
+          }
+        state = ESgotpars;
+      }
+    case ESgotpars:
+      memset(color_code+2, 0, 5);
+      color_index = 2;
+      color_seperator = 0;
+      state = ESnormal;
+      break;
+    case ESpercent:
+      state = ESnormal;
+      break;
+    case ESfunckey:
+    case EShash:
+    case ESsetG0:
+    case ESsetG1:
+      state = ESnormal;
+      break;
+    }
+    buf++;
+    r--;
+  }
+
+  return index;
+}
+
 static bool
 ply_terminal_session_open_console (ply_terminal_session_t *session)
 {
@@ -432,23 +616,6 @@ ply_terminal_session_get_fd (ply_termina
 }
 
 static void
-ply_terminal_session_log_bytes (ply_terminal_session_t *session,
-                                const uint8_t          *bytes,
-                                size_t                  number_of_bytes)
-{
-        assert (session != NULL);
-        assert (session->logger != NULL);
-        assert (bytes != NULL);
-        assert (number_of_bytes != 0);
-
-        ply_logger_inject_bytes (session->logger, bytes, number_of_bytes);
-
-        if (session->output_handler != NULL)
-                session->output_handler (session->user_data,
-                                         bytes, number_of_bytes, session);
-}
-
-static void
 ply_terminal_session_on_new_data (ply_terminal_session_t *session,
                                   int                     session_fd)
 {
@@ -460,8 +627,15 @@ ply_terminal_session_on_new_data (ply_te
 
         bytes_read = read (session_fd, buffer, sizeof(buffer));
 
-        if (bytes_read > 0)
-                ply_terminal_session_log_bytes (session, buffer, bytes_read);
+        if (bytes_read > 0) {
+
+            if (session->output_handler != NULL)
+                session->output_handler (session->user_data,
+                                         buffer, bytes_read, session);
+
+            if (session->logger)
+                (void) ply_terminal_strip_control_codes(session->logger, buffer, bytes_read);
+        }
 
         ply_logger_flush (session->logger);
 }
