From 4b2a67a76bea22cf9ca0f6bb832c0741f6a6cd51 Mon Sep 17 00:00:00 2001 From: Christian Bovey Date: Tue, 3 Dec 2013 22:29:31 +0100 Subject: [PATCH] Added now optional option to login command: Title --- src/hci/commands/login_cmd.c | 13 +++++++++++-- src/hci/tui/login_ui.c | 12 ++++++++++-- src/include/ipxe/login_ui.h | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/hci/commands/login_cmd.c b/src/hci/commands/login_cmd.c index f5db427..062ab7b 100644 --- a/src/hci/commands/login_cmd.c +++ b/src/hci/commands/login_cmd.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -39,7 +40,8 @@ static struct option_descriptor login_opts[] = {}; /** "login" command descriptor */ static struct command_descriptor login_cmd = - COMMAND_DESC ( struct login_options, login_opts, 0, 0, NULL ); + COMMAND_DESC ( struct login_options, login_opts, 0, MAX_ARGUMENTS, + "[]" ); /** * "login" command @@ -50,14 +52,21 @@ static struct command_descriptor login_cmd = */ static int login_exec ( int argc, char **argv ) { struct login_options opts; + char *title; int rc; /* Parse options */ if ( ( rc = parse_options ( argc, argv, &login_cmd, &opts ) ) != 0 ) return rc; + /* Parse title */ + title = concat_args ( &argv[optind] ); + if ( ! title ) { + title = ""; + } + /* Show login UI */ - if ( ( rc = login_ui() ) != 0 ) { + if ( ( rc = login_ui( title ) ) != 0 ) { printf ( "Could not set credentials: %s\n", strerror ( rc ) ); return rc; diff --git a/src/hci/tui/login_ui.c b/src/hci/tui/login_ui.c index 52ab0e3..93a0b44 100644 --- a/src/hci/tui/login_ui.c +++ b/src/hci/tui/login_ui.c @@ -40,6 +40,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #define CPAIR_EDIT 2 /* Screen layout */ +#define TITLE_ROW 1 #define USERNAME_LABEL_ROW 8 #define USERNAME_ROW 10 #define PASSWORD_LABEL_ROW 14 @@ -48,12 +49,13 @@ FILE_LICENCE ( GPL2_OR_LATER ); #define EDITBOX_COL 30 #define EDITBOX_WIDTH 20 -int login_ui ( void ) { +int login_ui ( const char *title ) { char username[64]; char password[64]; struct edit_box username_box; struct edit_box password_box; struct edit_box *current_box = &username_box; + char buf[ COLS + 1 /* NUL */ ]; int key; int rc = -EINPROGRESS; @@ -77,10 +79,16 @@ int login_ui ( void ) { /* Draw initial UI */ color_set ( CPAIR_NORMAL, NULL ); erase(); + attron ( A_BOLD ); + snprintf ( buf, sizeof ( buf ), "%s", title ); + mvprintw ( TITLE_ROW, ( ( COLS - strlen ( buf ) ) / 2 ), "%s", buf ); + attroff ( A_BOLD ); + + //attron ( A_BOLD ); mvprintw ( USERNAME_LABEL_ROW, LABEL_COL, "Username:" ); mvprintw ( PASSWORD_LABEL_ROW, LABEL_COL, "Password:" ); - attroff ( A_BOLD ); + //attroff ( A_BOLD ); color_set ( CPAIR_EDIT, NULL ); draw_editbox ( &username_box ); draw_editbox ( &password_box ); diff --git a/src/include/ipxe/login_ui.h b/src/include/ipxe/login_ui.h index 01e5479..91ab680 100644 --- a/src/include/ipxe/login_ui.h +++ b/src/include/ipxe/login_ui.h @@ -9,6 +9,6 @@ FILE_LICENCE ( GPL2_OR_LATER ); -extern int login_ui ( void ); +extern int login_ui ( const char *title ); #endif /* _IPXE_LOGIN_UI_H */ -- 1.8.1.2