Hello everybody,
I have sent this to the list about two month ago, but as the last patch was
neither committed nor commented I am resending.
This truncates menu title when it is longer than menu width. Otherwise no
title is displayed at all in this case.
This has been reworked to not touch the menu code but handle the truncation
within ui code instead.
--
main(a,b){char*/* Schoene Gruesse */c="B?IJj;M"
"EHCX:;";for(a/* Chris get my mail address: */=0;b=c[a++];)
putchar(b-1/(/* gcc -o sig sig.c && ./sig */b/42*2-3)*42);}
diff --git a/src/hci/tui/menu_ui.c b/src/hci/tui/menu_ui.c
index 2457a82..ecab0c2 100644
--- a/src/hci/tui/menu_ui.c
+++ b/src/hci/tui/menu_ui.c
@@ -306,6 +306,9 @@ int show_menu ( struct menu *menu, unsigned int timeout_ms,
struct menu_item **selected ) {
struct menu_item *item;
struct menu_ui ui;
+ size_t max_len;
+ size_t len;
+ char buf[ MENU_COLS + 1 /* NUL */ ];
int labelled_count = 0;
int rc;
@@ -342,8 +345,15 @@ int show_menu ( struct menu *menu, unsigned int timeout_ms,
/* Draw initial content */
attron ( A_BOLD );
- mvprintw ( TITLE_ROW, ( ( COLS - strlen ( ui.menu->title ) ) / 2 ),
- "%s", ui.menu->title );
+ memset ( buf, ' ', ( sizeof ( buf ) - 1 ) );
+ buf[ sizeof ( buf ) -1 ] = '\0';
+ len = strlen ( ui.menu->title );
+ max_len = ( sizeof ( buf ) - 1 /* NUL */ );
+ if ( len > max_len )
+ len = max_len;
+ memcpy ( buf, ui.menu->title, len );
+ mvprintw ( TITLE_ROW, ( ( COLS - len ) / 2 ),
+ "%s", buf );
attroff ( A_BOLD );
draw_menu_items ( &ui );
draw_menu_item ( &ui, ui.selected );
_______________________________________________
ipxe-devel mailing list
[email protected]
https://lists.ipxe.org/mailman/listinfo.cgi/ipxe-devel