Browse Source

[console] Add concept of a "magic" colour

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>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
f6dce77b15
2 changed files with 45 additions and 4 deletions
  1. 34
    4
      src/core/ansicoldef.c
  2. 11
    0
      src/include/ipxe/ansicol.h

+ 34
- 4
src/core/ansicoldef.c View File

86
  * @v basic		Basic colour
86
  * @v basic		Basic colour
87
  * @ret ansicol		ANSI colour definition
87
  * @ret ansicol		ANSI colour definition
88
  *
88
  *
89
- * Colours default to being just a basic colour.
89
+ * Colours default to being just a basic colour.  If the colour
90
+ * matches the normal UI text background colour, then its basic colour
91
+ * value is set to @c ANSICOL_MAGIC.
90
  */
92
  */
91
-#define ANSICOL_DEFAULT( basic ) ANSICOL_DEFINE ( (basic), ANSICOL_NO_RGB )
93
+#define ANSICOL_DEFAULT( basic )					\
94
+	ANSICOL_DEFINE ( ( ( (basic) == COLOR_NORMAL_BG ) ?		\
95
+			   ANSICOL_MAGIC : (basic) ),			\
96
+			 ANSICOL_NO_RGB )
92
 
97
 
93
 /** ANSI colour definitions */
98
 /** ANSI colour definitions */
94
 static uint32_t ansicols[] = {
99
 static uint32_t ansicols[] = {
102
 	[COLOR_WHITE]	= ANSICOL_DEFAULT ( COLOR_WHITE ),
107
 	[COLOR_WHITE]	= ANSICOL_DEFAULT ( COLOR_WHITE ),
103
 };
108
 };
104
 
109
 
110
+/** Magic basic colour */
111
+static uint8_t ansicol_magic = COLOR_NORMAL_BG;
112
+
105
 /**
113
 /**
106
  * Define ANSI colour
114
  * Define ANSI colour
107
  *
115
  *
145
 		ansicol = ANSICOL_DEFINE ( COLOUR_DEFAULT, ANSICOL_NO_RGB );
153
 		ansicol = ANSICOL_DEFINE ( COLOUR_DEFAULT, ANSICOL_NO_RGB );
146
 	}
154
 	}
147
 
155
 
148
-	/* If basic colour is out of range, use the default colour */
156
+	/* If basic colour is out of range, use the magic colour */
149
 	basic = ANSICOL_BASIC ( ansicol );
157
 	basic = ANSICOL_BASIC ( ansicol );
150
 	if ( basic >= 10 )
158
 	if ( basic >= 10 )
151
-		basic = COLOR_DEFAULT;
159
+		basic = ansicol_magic;
152
 
160
 
153
 	/* Set basic colour first */
161
 	/* Set basic colour first */
154
 	printf ( CSI "%c%dm", which, basic );
162
 	printf ( CSI "%c%dm", which, basic );
159
 			 ANSICOL_GREEN ( ansicol ), ANSICOL_BLUE ( ansicol ) );
167
 			 ANSICOL_GREEN ( ansicol ), ANSICOL_BLUE ( ansicol ) );
160
 	}
168
 	}
161
 }
169
 }
170
+
171
+/**
172
+ * Reset magic colour
173
+ *
174
+ */
175
+void ansicol_reset_magic ( void ) {
176
+
177
+	/* Set to the compile-time default background colour */
178
+	ansicol_magic = COLOR_NORMAL_BG;
179
+}
180
+
181
+/**
182
+ * Set magic colour to transparent
183
+ *
184
+ */
185
+void ansicol_set_magic_transparent ( void ) {
186
+
187
+	/* Set to the console default colour (which will give a
188
+	 * transparent background on the framebuffer console).
189
+	 */
190
+	ansicol_magic = COLOR_DEFAULT;
191
+}

+ 11
- 0
src/include/ipxe/ansicol.h View File

16
 #define COLOUR_DEFAULT 9
16
 #define COLOUR_DEFAULT 9
17
 #define COLOR_DEFAULT COLOUR_DEFAULT
17
 #define COLOR_DEFAULT COLOUR_DEFAULT
18
 
18
 
19
+/** Magic colour
20
+ *
21
+ * The magic basic colour is automatically remapped to the colour
22
+ * stored in @c ansicol_magic.  This is used to allow the UI
23
+ * background to automatically become transparent when a background
24
+ * picture is used.
25
+ */
26
+#define ANSICOL_MAGIC 15
27
+
19
 /** RGB value for "not defined" */
28
 /** RGB value for "not defined" */
20
 #define ANSICOL_NO_RGB 0x01000000
29
 #define ANSICOL_NO_RGB 0x01000000
21
 
30
 
66
 /* ansicoldef.c */
75
 /* ansicoldef.c */
67
 extern int ansicol_define ( unsigned int colour, unsigned int ansi,
76
 extern int ansicol_define ( unsigned int colour, unsigned int ansi,
68
 			    uint32_t rgb );
77
 			    uint32_t rgb );
78
+extern void ansicol_reset_magic ( void );
79
+extern void ansicol_set_magic_transparent ( void );
69
 
80
 
70
 /* Function provided by ansicol.c but overridden by ansicoldef.c, if present */
81
 /* Function provided by ansicol.c but overridden by ansicoldef.c, if present */
71
 extern void ansicol_set ( unsigned int colour, unsigned int which );
82
 extern void ansicol_set ( unsigned int colour, unsigned int which );

Loading…
Cancel
Save