]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[console] Add concept of a "magic" colour
authorMichael Brown <mcb30@ipxe.org>
Mon, 9 Dec 2013 15:30:59 +0000 (15:30 +0000)
committerMichael Brown <mcb30@ipxe.org>
Mon, 9 Dec 2013 15:34:14 +0000 (15:34 +0000)
The magic basic colour can be remapped at runtime from COLOR_NORMAL_BG
(usually blue) to COLOR_DEFAULT (which will be transparent as a
background colour on the framebuffer console).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/ansicoldef.c
src/include/ipxe/ansicol.h

index 561356114d3801dd3d74e9f74fbbfa11aeeab622..dd89f3b70d6bc4bc9fda1017aa5ba480857a1573 100644 (file)
@@ -86,9 +86,14 @@ FILE_LICENCE ( GPL2_OR_LATER );
  * @v basic            Basic colour
  * @ret ansicol                ANSI colour definition
  *
- * Colours default to being just a basic colour.
+ * Colours default to being just a basic colour.  If the colour
+ * matches the normal UI text background colour, then its basic colour
+ * value is set to @c ANSICOL_MAGIC.
  */
-#define ANSICOL_DEFAULT( basic ) ANSICOL_DEFINE ( (basic), ANSICOL_NO_RGB )
+#define ANSICOL_DEFAULT( basic )                                       \
+       ANSICOL_DEFINE ( ( ( (basic) == COLOR_NORMAL_BG ) ?             \
+                          ANSICOL_MAGIC : (basic) ),                   \
+                        ANSICOL_NO_RGB )
 
 /** ANSI colour definitions */
 static uint32_t ansicols[] = {
@@ -102,6 +107,9 @@ static uint32_t ansicols[] = {
        [COLOR_WHITE]   = ANSICOL_DEFAULT ( COLOR_WHITE ),
 };
 
+/** Magic basic colour */
+static uint8_t ansicol_magic = COLOR_NORMAL_BG;
+
 /**
  * Define ANSI colour
  *
@@ -145,10 +153,10 @@ void ansicol_set ( unsigned int colour, unsigned int which ) {
                ansicol = ANSICOL_DEFINE ( COLOUR_DEFAULT, ANSICOL_NO_RGB );
        }
 
-       /* If basic colour is out of range, use the default colour */
+       /* If basic colour is out of range, use the magic colour */
        basic = ANSICOL_BASIC ( ansicol );
        if ( basic >= 10 )
-               basic = COLOR_DEFAULT;
+               basic = ansicol_magic;
 
        /* Set basic colour first */
        printf ( CSI "%c%dm", which, basic );
@@ -159,3 +167,25 @@ void ansicol_set ( unsigned int colour, unsigned int which ) {
                         ANSICOL_GREEN ( ansicol ), ANSICOL_BLUE ( ansicol ) );
        }
 }
+
+/**
+ * Reset magic colour
+ *
+ */
+void ansicol_reset_magic ( void ) {
+
+       /* Set to the compile-time default background colour */
+       ansicol_magic = COLOR_NORMAL_BG;
+}
+
+/**
+ * Set magic colour to transparent
+ *
+ */
+void ansicol_set_magic_transparent ( void ) {
+
+       /* Set to the console default colour (which will give a
+        * transparent background on the framebuffer console).
+        */
+       ansicol_magic = COLOR_DEFAULT;
+}
index 2fa0846260027c3af133214351ebf2879790201a..707d1599da89c2ce96495fc7978d5d50bac753ee 100644 (file)
@@ -16,6 +16,15 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #define COLOUR_DEFAULT 9
 #define COLOR_DEFAULT COLOUR_DEFAULT
 
+/** Magic colour
+ *
+ * The magic basic colour is automatically remapped to the colour
+ * stored in @c ansicol_magic.  This is used to allow the UI
+ * background to automatically become transparent when a background
+ * picture is used.
+ */
+#define ANSICOL_MAGIC 15
+
 /** RGB value for "not defined" */
 #define ANSICOL_NO_RGB 0x01000000
 
@@ -66,6 +75,8 @@ extern int ansicol_define_pair ( unsigned int cpair, unsigned int foreground,
 /* ansicoldef.c */
 extern int ansicol_define ( unsigned int colour, unsigned int ansi,
                            uint32_t rgb );
+extern void ansicol_reset_magic ( void );
+extern void ansicol_set_magic_transparent ( void );
 
 /* Function provided by ansicol.c but overridden by ansicoldef.c, if present */
 extern void ansicol_set ( unsigned int colour, unsigned int which );