瀏覽代碼

[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 年之前
父節點
當前提交
f6dce77b15
共有 2 個檔案被更改,包括 45 行新增4 行删除
  1. 34
    4
      src/core/ansicoldef.c
  2. 11
    0
      src/include/ipxe/ansicol.h

+ 34
- 4
src/core/ansicoldef.c 查看文件

@@ -86,9 +86,14 @@ FILE_LICENCE ( GPL2_OR_LATER );
86 86
  * @v basic		Basic colour
87 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 98
 /** ANSI colour definitions */
94 99
 static uint32_t ansicols[] = {
@@ -102,6 +107,9 @@ static uint32_t ansicols[] = {
102 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 114
  * Define ANSI colour
107 115
  *
@@ -145,10 +153,10 @@ void ansicol_set ( unsigned int colour, unsigned int which ) {
145 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 157
 	basic = ANSICOL_BASIC ( ansicol );
150 158
 	if ( basic >= 10 )
151
-		basic = COLOR_DEFAULT;
159
+		basic = ansicol_magic;
152 160
 
153 161
 	/* Set basic colour first */
154 162
 	printf ( CSI "%c%dm", which, basic );
@@ -159,3 +167,25 @@ void ansicol_set ( unsigned int colour, unsigned int which ) {
159 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 查看文件

@@ -16,6 +16,15 @@ FILE_LICENCE ( GPL2_OR_LATER );
16 16
 #define COLOUR_DEFAULT 9
17 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 28
 /** RGB value for "not defined" */
20 29
 #define ANSICOL_NO_RGB 0x01000000
21 30
 
@@ -66,6 +75,8 @@ extern int ansicol_define_pair ( unsigned int cpair, unsigned int foreground,
66 75
 /* ansicoldef.c */
67 76
 extern int ansicol_define ( unsigned int colour, unsigned int ansi,
68 77
 			    uint32_t rgb );
78
+extern void ansicol_reset_magic ( void );
79
+extern void ansicol_set_magic_transparent ( void );
69 80
 
70 81
 /* Function provided by ansicol.c but overridden by ansicoldef.c, if present */
71 82
 extern void ansicol_set ( unsigned int colour, unsigned int which );

Loading…
取消
儲存