Browse Source

[mucurses] Use centralised concept of colour pairs

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 years ago
parent
commit
259858950a
5 changed files with 14 additions and 43 deletions
  1. 8
    6
      src/hci/mucurses/ansi_screen.c
  2. 1
    7
      src/hci/tui/login_ui.c
  3. 1
    9
      src/hci/tui/menu_ui.c
  4. 1
    13
      src/hci/tui/settings_ui.c
  5. 3
    8
      src/usr/pxemenu.c

+ 8
- 6
src/hci/mucurses/ansi_screen.c View File

1
 #include <stdio.h>
1
 #include <stdio.h>
2
 #include <curses.h>
2
 #include <curses.h>
3
+#include <ipxe/ansicol.h>
3
 #include <ipxe/console.h>
4
 #include <ipxe/console.h>
4
 
5
 
5
 FILE_LICENCE ( GPL2_OR_LATER );
6
 FILE_LICENCE ( GPL2_OR_LATER );
14
 static void ansiscr_attrs ( struct _curses_screen *scr, attr_t attrs ) {
15
 static void ansiscr_attrs ( struct _curses_screen *scr, attr_t attrs ) {
15
 	int bold = ( attrs & A_BOLD );
16
 	int bold = ( attrs & A_BOLD );
16
 	attr_t cpair = PAIR_NUMBER ( attrs );
17
 	attr_t cpair = PAIR_NUMBER ( attrs );
17
-	short fcol;
18
-	short bcol;
19
 
18
 
20
 	if ( scr->attrs != attrs ) {
19
 	if ( scr->attrs != attrs ) {
21
 		scr->attrs = attrs;
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
 	scr->attrs = 0;
30
 	scr->attrs = 0;
31
 	scr->curs_x = 0;
31
 	scr->curs_x = 0;
32
 	scr->curs_y = 0;
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
 static void ansiscr_init ( struct _curses_screen *scr ) {
38
 static void ansiscr_init ( struct _curses_screen *scr ) {

+ 1
- 7
src/hci/tui/login_ui.c View File

32
 #include <ipxe/settings.h>
32
 #include <ipxe/settings.h>
33
 #include <ipxe/editbox.h>
33
 #include <ipxe/editbox.h>
34
 #include <ipxe/keys.h>
34
 #include <ipxe/keys.h>
35
+#include <ipxe/ansicol.h>
35
 #include <ipxe/login_ui.h>
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
 /* Screen layout */
38
 /* Screen layout */
43
 #define USERNAME_LABEL_ROW	( ( LINES / 2U ) - 4U )
39
 #define USERNAME_LABEL_ROW	( ( LINES / 2U ) - 4U )
66
 	/* Initialise UI */
62
 	/* Initialise UI */
67
 	initscr();
63
 	initscr();
68
 	start_color();
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
 	init_editbox ( &username_box, username, sizeof ( username ), NULL,
65
 	init_editbox ( &username_box, username, sizeof ( username ), NULL,
72
 		       USERNAME_ROW, EDITBOX_COL, EDITBOX_WIDTH, 0 );
66
 		       USERNAME_ROW, EDITBOX_COL, EDITBOX_WIDTH, 0 );
73
 	init_editbox ( &password_box, password, sizeof ( password ), NULL,
67
 	init_editbox ( &password_box, password, sizeof ( password ), NULL,

+ 1
- 9
src/hci/tui/menu_ui.c View File

31
 #include <ipxe/keys.h>
31
 #include <ipxe/keys.h>
32
 #include <ipxe/timer.h>
32
 #include <ipxe/timer.h>
33
 #include <ipxe/console.h>
33
 #include <ipxe/console.h>
34
+#include <ipxe/ansicol.h>
34
 #include <ipxe/menu.h>
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
 /* Screen layout */
37
 /* Screen layout */
43
 #define TITLE_ROW	1U
38
 #define TITLE_ROW	1U
345
 	/* Initialise screen */
340
 	/* Initialise screen */
346
 	initscr();
341
 	initscr();
347
 	start_color();
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
 	color_set ( CPAIR_NORMAL, NULL );
343
 	color_set ( CPAIR_NORMAL, NULL );
352
 	curs_set ( 0 );
344
 	curs_set ( 0 );
353
 	erase();
345
 	erase();

+ 1
- 13
src/hci/tui/settings_ui.c View File

28
 #include <ipxe/settings.h>
28
 #include <ipxe/settings.h>
29
 #include <ipxe/editbox.h>
29
 #include <ipxe/editbox.h>
30
 #include <ipxe/keys.h>
30
 #include <ipxe/keys.h>
31
+#include <ipxe/ansicol.h>
31
 #include <ipxe/settings_ui.h>
32
 #include <ipxe/settings_ui.h>
32
-#include <config/colour.h>
33
 
33
 
34
 /** @file
34
 /** @file
35
  *
35
  *
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
 /* Screen layout */
40
 /* Screen layout */
48
 #define TITLE_ROW		1U
41
 #define TITLE_ROW		1U
49
 #define SETTINGS_LIST_ROW	3U
42
 #define SETTINGS_LIST_ROW	3U
598
 
591
 
599
 	initscr();
592
 	initscr();
600
 	start_color();
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
 	color_set ( CPAIR_NORMAL, NULL );
594
 	color_set ( CPAIR_NORMAL, NULL );
607
 	curs_set ( 0 );
595
 	curs_set ( 0 );
608
 	erase();
596
 	erase();

+ 3
- 8
src/usr/pxemenu.c View File

32
 #include <ipxe/keys.h>
32
 #include <ipxe/keys.h>
33
 #include <ipxe/timer.h>
33
 #include <ipxe/timer.h>
34
 #include <ipxe/uri.h>
34
 #include <ipxe/uri.h>
35
+#include <ipxe/ansicol.h>
35
 #include <usr/dhcpmgmt.h>
36
 #include <usr/dhcpmgmt.h>
36
 #include <usr/autoboot.h>
37
 #include <usr/autoboot.h>
37
 
38
 
41
  *
42
  *
42
  */
43
  */
43
 
44
 
44
-/* Colour pairs */
45
-#define CPAIR_NORMAL	1
46
-#define CPAIR_SELECT	2
47
-
48
 /** A PXE boot menu item */
45
 /** A PXE boot menu item */
49
 struct pxe_menu_item {
46
 struct pxe_menu_item {
50
 	/** Boot Server type */
47
 	/** Boot Server type */
204
 
201
 
205
 	/* Draw row */
202
 	/* Draw row */
206
 	row = ( LINES - menu->num_items + index );
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
 	mvprintw ( row, 0, "%s", buf );
205
 	mvprintw ( row, 0, "%s", buf );
209
 	move ( row, 1 );
206
 	move ( row, 1 );
210
 }
207
 }
224
 	/* Initialise UI */
221
 	/* Initialise UI */
225
 	initscr();
222
 	initscr();
226
 	start_color();
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
 	/* Draw initial menu */
226
 	/* Draw initial menu */
232
 	for ( i = 0 ; i < menu->num_items ; i++ )
227
 	for ( i = 0 ; i < menu->num_items ; i++ )

Loading…
Cancel
Save