Parcourir la source

[mucurses] Use centralised concept of colour pairs

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown il y a 11 ans
Parent
révision
259858950a

+ 8
- 6
src/hci/mucurses/ansi_screen.c Voir le fichier

@@ -1,5 +1,6 @@
1 1
 #include <stdio.h>
2 2
 #include <curses.h>
3
+#include <ipxe/ansicol.h>
3 4
 #include <ipxe/console.h>
4 5
 
5 6
 FILE_LICENCE ( GPL2_OR_LATER );
@@ -14,14 +15,13 @@ static unsigned int saved_usage;
14 15
 static void ansiscr_attrs ( struct _curses_screen *scr, attr_t attrs ) {
15 16
 	int bold = ( attrs & A_BOLD );
16 17
 	attr_t cpair = PAIR_NUMBER ( attrs );
17
-	short fcol;
18
-	short bcol;
19 18
 
20 19
 	if ( scr->attrs != attrs ) {
21 20
 		scr->attrs = attrs;
22
-		pair_content ( cpair, &fcol, &bcol );
23
-		/* ANSI escape sequence to update character attributes */
24
-		printf ( "\033[0;%d;3%d;4%dm", ( bold ? 1 : 22 ), fcol, bcol );
21
+		/* Reset attributes and set/clear bold as appropriate */
22
+		printf ( "\033[0;%dm", ( bold ? 1 : 22 ) );
23
+		/* Set foreground and background colours */
24
+		ansicol_set_pair ( cpair );
25 25
 	}
26 26
 }
27 27
 
@@ -30,7 +30,9 @@ static void ansiscr_reset ( struct _curses_screen *scr ) {
30 30
 	scr->attrs = 0;
31 31
 	scr->curs_x = 0;
32 32
 	scr->curs_y = 0;
33
-	printf ( "\033[0m\033[2J" );
33
+	printf ( "\0330m" );
34
+	ansicol_set_pair ( CPAIR_DEFAULT );
35
+	printf ( "\033[2J" );
34 36
 }
35 37
 
36 38
 static void ansiscr_init ( struct _curses_screen *scr ) {

+ 1
- 7
src/hci/tui/login_ui.c Voir le fichier

@@ -32,12 +32,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
32 32
 #include <ipxe/settings.h>
33 33
 #include <ipxe/editbox.h>
34 34
 #include <ipxe/keys.h>
35
+#include <ipxe/ansicol.h>
35 36
 #include <ipxe/login_ui.h>
36
-#include <config/colour.h>
37
-
38
-/* Colour pairs */
39
-#define CPAIR_NORMAL		1
40
-#define CPAIR_EDIT		2
41 37
 
42 38
 /* Screen layout */
43 39
 #define USERNAME_LABEL_ROW	( ( LINES / 2U ) - 4U )
@@ -66,8 +62,6 @@ int login_ui ( void ) {
66 62
 	/* Initialise UI */
67 63
 	initscr();
68 64
 	start_color();
69
-	init_pair ( CPAIR_NORMAL, COLOR_NORMAL_FG, COLOR_NORMAL_BG );
70
-	init_pair ( CPAIR_EDIT, COLOR_EDIT_FG, COLOR_EDIT_BG );
71 65
 	init_editbox ( &username_box, username, sizeof ( username ), NULL,
72 66
 		       USERNAME_ROW, EDITBOX_COL, EDITBOX_WIDTH, 0 );
73 67
 	init_editbox ( &password_box, password, sizeof ( password ), NULL,

+ 1
- 9
src/hci/tui/menu_ui.c Voir le fichier

@@ -31,13 +31,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
31 31
 #include <ipxe/keys.h>
32 32
 #include <ipxe/timer.h>
33 33
 #include <ipxe/console.h>
34
+#include <ipxe/ansicol.h>
34 35
 #include <ipxe/menu.h>
35
-#include <config/colour.h>
36
-
37
-/* Colour pairs */
38
-#define CPAIR_NORMAL	1
39
-#define CPAIR_SELECT	2
40
-#define CPAIR_SEPARATOR	3
41 36
 
42 37
 /* Screen layout */
43 38
 #define TITLE_ROW	1U
@@ -345,9 +340,6 @@ int show_menu ( struct menu *menu, unsigned long timeout,
345 340
 	/* Initialise screen */
346 341
 	initscr();
347 342
 	start_color();
348
-	init_pair ( CPAIR_NORMAL, COLOR_NORMAL_FG, COLOR_NORMAL_BG );
349
-	init_pair ( CPAIR_SELECT, COLOR_SELECT_FG, COLOR_SELECT_BG );
350
-	init_pair ( CPAIR_SEPARATOR, COLOR_SEPARATOR_FG, COLOR_SEPARATOR_BG );
351 343
 	color_set ( CPAIR_NORMAL, NULL );
352 344
 	curs_set ( 0 );
353 345
 	erase();

+ 1
- 13
src/hci/tui/settings_ui.c Voir le fichier

@@ -28,8 +28,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
28 28
 #include <ipxe/settings.h>
29 29
 #include <ipxe/editbox.h>
30 30
 #include <ipxe/keys.h>
31
+#include <ipxe/ansicol.h>
31 32
 #include <ipxe/settings_ui.h>
32
-#include <config/colour.h>
33 33
 
34 34
 /** @file
35 35
  *
@@ -37,13 +37,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
37 37
  *
38 38
  */
39 39
 
40
-/* Colour pairs */
41
-#define CPAIR_NORMAL	1
42
-#define CPAIR_SELECT	2
43
-#define CPAIR_EDIT	3
44
-#define CPAIR_ALERT	4
45
-#define CPAIR_URL	5
46
-
47 40
 /* Screen layout */
48 41
 #define TITLE_ROW		1U
49 42
 #define SETTINGS_LIST_ROW	3U
@@ -598,11 +591,6 @@ int settings_ui ( struct settings *settings ) {
598 591
 
599 592
 	initscr();
600 593
 	start_color();
601
-	init_pair ( CPAIR_NORMAL, COLOR_NORMAL_FG, COLOR_NORMAL_BG );
602
-	init_pair ( CPAIR_SELECT, COLOR_SELECT_FG, COLOR_SELECT_BG );
603
-	init_pair ( CPAIR_EDIT, COLOR_EDIT_FG, COLOR_EDIT_BG );
604
-	init_pair ( CPAIR_ALERT, COLOR_ALERT_FG, COLOR_ALERT_BG );
605
-	init_pair ( CPAIR_URL, COLOR_URL_FG, COLOR_URL_BG );
606 594
 	color_set ( CPAIR_NORMAL, NULL );
607 595
 	curs_set ( 0 );
608 596
 	erase();

+ 3
- 8
src/usr/pxemenu.c Voir le fichier

@@ -32,6 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
32 32
 #include <ipxe/keys.h>
33 33
 #include <ipxe/timer.h>
34 34
 #include <ipxe/uri.h>
35
+#include <ipxe/ansicol.h>
35 36
 #include <usr/dhcpmgmt.h>
36 37
 #include <usr/autoboot.h>
37 38
 
@@ -41,10 +42,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
41 42
  *
42 43
  */
43 44
 
44
-/* Colour pairs */
45
-#define CPAIR_NORMAL	1
46
-#define CPAIR_SELECT	2
47
-
48 45
 /** A PXE boot menu item */
49 46
 struct pxe_menu_item {
50 47
 	/** Boot Server type */
@@ -204,7 +201,7 @@ static void pxe_menu_draw_item ( struct pxe_menu *menu,
204 201
 
205 202
 	/* Draw row */
206 203
 	row = ( LINES - menu->num_items + index );
207
-	color_set ( ( selected ? CPAIR_SELECT : CPAIR_NORMAL ), NULL );
204
+	color_set ( ( selected ? CPAIR_PXE : CPAIR_DEFAULT ), NULL );
208 205
 	mvprintw ( row, 0, "%s", buf );
209 206
 	move ( row, 1 );
210 207
 }
@@ -224,9 +221,7 @@ static int pxe_menu_select ( struct pxe_menu *menu ) {
224 221
 	/* Initialise UI */
225 222
 	initscr();
226 223
 	start_color();
227
-	init_pair ( CPAIR_NORMAL, COLOR_WHITE, COLOR_BLACK );
228
-	init_pair ( CPAIR_SELECT, COLOR_BLACK, COLOR_WHITE );
229
-	color_set ( CPAIR_NORMAL, NULL );
224
+	color_set ( CPAIR_DEFAULT, NULL );
230 225
 
231 226
 	/* Draw initial menu */
232 227
 	for ( i = 0 ; i < menu->num_items ; i++ )

Chargement…
Annuler
Enregistrer