2 * Copyright (C) 2009 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 FILE_LICENCE ( GPL2_OR_LATER );
31 #include <ipxe/console.h>
32 #include <ipxe/settings.h>
33 #include <ipxe/editbox.h>
34 #include <ipxe/keys.h>
35 #include <ipxe/ansicol.h>
36 #include <ipxe/login_ui.h>
39 #define USERNAME_LABEL_ROW ( ( LINES / 2U ) - 4U )
40 #define USERNAME_ROW ( ( LINES / 2U ) - 2U )
41 #define PASSWORD_LABEL_ROW ( ( LINES / 2U ) + 2U )
42 #define PASSWORD_ROW ( ( LINES / 2U ) + 4U )
43 #define LABEL_COL ( ( COLS / 2U ) - 4U )
44 #define EDITBOX_COL ( ( COLS / 2U ) - 10U )
45 #define EDITBOX_WIDTH 20U
47 int login_ui ( void ) {
50 struct edit_box username_box;
51 struct edit_box password_box;
52 struct edit_box *current_box = &username_box;
54 int rc = -EINPROGRESS;
56 /* Fetch current setting values */
57 fetch_string_setting ( NULL, &username_setting, username,
58 sizeof ( username ) );
59 fetch_string_setting ( NULL, &password_setting, password,
60 sizeof ( password ) );
65 init_editbox ( &username_box, username, sizeof ( username ), NULL,
66 USERNAME_ROW, EDITBOX_COL, EDITBOX_WIDTH, 0 );
67 init_editbox ( &password_box, password, sizeof ( password ), NULL,
68 PASSWORD_ROW, EDITBOX_COL, EDITBOX_WIDTH,
72 color_set ( CPAIR_NORMAL, NULL );
75 mvprintw ( USERNAME_LABEL_ROW, LABEL_COL, "Username:" );
76 mvprintw ( PASSWORD_LABEL_ROW, LABEL_COL, "Password:" );
78 color_set ( CPAIR_EDIT, NULL );
79 draw_editbox ( &username_box );
80 draw_editbox ( &password_box );
83 while ( rc == -EINPROGRESS ) {
85 draw_editbox ( current_box );
90 current_box = &password_box;
93 current_box = &username_box;
96 current_box = ( ( current_box == &username_box ) ?
97 &password_box : &username_box );
100 if ( current_box == &username_box ) {
101 current_box = &password_box;
111 edit_editbox ( current_box, key );
117 color_set ( CPAIR_NORMAL, NULL );
125 if ( ( rc = store_setting ( NULL, &username_setting, username,
126 strlen ( username ) ) ) != 0 )
128 if ( ( rc = store_setting ( NULL, &password_setting, password,
129 strlen ( password ) ) ) != 0 )