[PATCH 1/4] ply-text-display: support bright colors

Jan Engelhardt jengelh at inai.de
Sun Jul 29 11:32:52 PDT 2012


---
 src/libply-splash-core/ply-terminal.h          |   10 +++++++++-
 src/libply-splash-core/ply-text-display.c      |   21 +++++++++++++++++++--
 src/libply-splash-core/ply-text-progress-bar.c |    4 ++--
 src/plugins/splash/text/plugin.c               |    2 +-
 4 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/src/libply-splash-core/ply-terminal.h b/src/libply-splash-core/ply-terminal.h
index 8b4b017..bf572cc 100644
--- a/src/libply-splash-core/ply-terminal.h
+++ b/src/libply-splash-core/ply-terminal.h
@@ -44,8 +44,16 @@ typedef enum
   PLY_TERMINAL_COLOR_BLUE,
   PLY_TERMINAL_COLOR_MAGENTA,
   PLY_TERMINAL_COLOR_CYAN,
+  PLY_TERMINAL_COLOR_GRAY,
+  PLY_TERMINAL_COLOR_DARKGRAY,
+  PLY_TERMINAL_COLOR_BRIGHTRED,
+  PLY_TERMINAL_COLOR_BRIGHTGREEN,
+  PLY_TERMINAL_COLOR_YELLOW,
+  PLY_TERMINAL_COLOR_BRIGHTBLUE,
+  PLY_TERMINAL_COLOR_BRIGHTMAGENTA,
+  PLY_TERMINAL_COLOR_BRIGHTCYAN,
   PLY_TERMINAL_COLOR_WHITE,
-  PLY_TERMINAL_COLOR_DEFAULT = PLY_TERMINAL_COLOR_WHITE + 2
+  PLY_TERMINAL_COLOR_DEFAULT,
 } ply_terminal_color_t;
 
 typedef enum
diff --git a/src/libply-splash-core/ply-text-display.c b/src/libply-splash-core/ply-text-display.c
index 7cabd98..c538c59 100644
--- a/src/libply-splash-core/ply-text-display.c
+++ b/src/libply-splash-core/ply-text-display.c
@@ -25,6 +25,7 @@
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -178,6 +179,12 @@ void
 ply_text_display_set_background_color (ply_text_display_t   *display,
                                        ply_terminal_color_t  color)
 {
+  /* Generally no support for bright backgrounds by hardware */
+  assert(!(color >= PLY_TERMINAL_COLOR_DARKGRAY &&
+         color <= PLY_TERMINAL_COLOR_WHITE));
+
+  if (color == PLY_TERMINAL_COLOR_DEFAULT)
+		color = 9;
 
   ply_terminal_write (display->terminal,
                       COLOR_SEQUENCE_FORMAT,
@@ -190,9 +197,19 @@ void
 ply_text_display_set_foreground_color (ply_text_display_t       *display,
                                        ply_terminal_color_t  color)
 {
+  bool hi = false;
+
+  if (color >= PLY_TERMINAL_COLOR_DARKGRAY &&
+      color <= PLY_TERMINAL_COLOR_WHITE) {
+		color -= PLY_TERMINAL_COLOR_DARKGRAY;
+		hi = true;
+  } else if (color == PLY_TERMINAL_COLOR_DEFAULT) {
+		color = 9;
+  }
   ply_terminal_write (display->terminal,
-                      COLOR_SEQUENCE_FORMAT,
-                      FOREGROUND_COLOR_BASE + color);
+                      "\x1b\x5b""%d;%u;%um", hi,
+                      FOREGROUND_COLOR_BASE + color,
+                      BACKGROUND_COLOR_BASE + display->background_color);
 
   display->foreground_color = color;
 }
diff --git a/src/libply-splash-core/ply-text-progress-bar.c b/src/libply-splash-core/ply-text-progress-bar.c
index 7c9d688..0f4d74e 100644
--- a/src/libply-splash-core/ply-text-progress-bar.c
+++ b/src/libply-splash-core/ply-text-progress-bar.c
@@ -190,7 +190,7 @@ ply_text_progress_bar_draw (ply_text_progress_bar_t *progress_bar)
         f = (double) i / (double) width;
         if (f < white_fraction)
             ply_text_display_set_background_color (progress_bar->display,
-                                                   PLY_TERMINAL_COLOR_WHITE);
+                                                   PLY_TERMINAL_COLOR_GRAY);
         else if (f < blue_fraction)
             ply_text_display_set_background_color (progress_bar->display,
                                              PLY_TERMINAL_COLOR_BLUE);
@@ -209,7 +209,7 @@ ply_text_progress_bar_draw (ply_text_progress_bar_t *progress_bar)
     if (brown_fraction > 0.5) {
         if (white_fraction > 0.875)
             ply_text_display_set_foreground_color (progress_bar->display,
-                                                   PLY_TERMINAL_COLOR_WHITE);
+                                                   PLY_TERMINAL_COLOR_GRAY);
         else if (blue_fraction > 0.66)
             ply_text_display_set_foreground_color (progress_bar->display,
                                                    PLY_TERMINAL_COLOR_BLUE);
diff --git a/src/plugins/splash/text/plugin.c b/src/plugins/splash/text/plugin.c
index 50059be..78feb59 100644
--- a/src/plugins/splash/text/plugin.c
+++ b/src/plugins/splash/text/plugin.c
@@ -179,7 +179,7 @@ view_start_animation (view_t *view)
                                     PLY_TERMINAL_COLOR_BLACK,
                                     0x000000);
   ply_terminal_set_color_hex_value (terminal,
-                                    PLY_TERMINAL_COLOR_WHITE,
+                                    PLY_TERMINAL_COLOR_GRAY,
                                     0xffffff);
   ply_terminal_set_color_hex_value (terminal,
                                     PLY_TERMINAL_COLOR_BLUE,
-- 
1.7.7



More information about the plymouth mailing list