iPXE
Functions
login_ui.h File Reference

Login UI. More...

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int login_ui (void)
 

Detailed Description

Login UI.

Definition in file login_ui.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ login_ui()

int login_ui ( void  )

Definition at line 52 of file login_ui.c.

52  {
53  char *username;
54  char *password;
55  struct edit_box username_box;
56  struct edit_box password_box;
57  struct edit_box *current_box = &username_box;
58  int key;
59  int rc = -EINPROGRESS;
60 
61  /* Fetch current setting values */
62  fetchf_setting_copy ( NULL, &username_setting, NULL, NULL, &username );
63  fetchf_setting_copy ( NULL, &password_setting, NULL, NULL, &password );
64 
65  /* Initialise UI */
66  initscr();
67  start_color();
68  init_editbox ( &username_box, &username, NULL, USERNAME_ROW,
70  init_editbox ( &password_box, &password, NULL, PASSWORD_ROW,
72 
73  /* Draw initial UI */
75  erase();
76  attron ( A_BOLD );
77  mvprintw ( USERNAME_LABEL_ROW, LABEL_COL, "Username:" );
78  mvprintw ( PASSWORD_LABEL_ROW, LABEL_COL, "Password:" );
79  attroff ( A_BOLD );
81  draw_editbox ( &username_box );
82  draw_editbox ( &password_box );
83 
84  /* Main loop */
85  while ( rc == -EINPROGRESS ) {
86 
87  draw_editbox ( current_box );
88 
89  key = getkey ( 0 );
90  switch ( key ) {
91  case KEY_DOWN:
92  current_box = &password_box;
93  break;
94  case KEY_UP:
95  current_box = &username_box;
96  break;
97  case TAB:
98  current_box = ( ( current_box == &username_box ) ?
99  &password_box : &username_box );
100  break;
101  case KEY_ENTER:
102  if ( current_box == &username_box ) {
103  current_box = &password_box;
104  } else {
105  rc = 0;
106  }
107  break;
108  case CTRL_C:
109  case ESC:
110  rc = -ECANCELED;
111  break;
112  default:
113  edit_editbox ( current_box, key );
114  break;
115  }
116  }
117 
118  /* Terminate UI */
120  erase();
121  endwin();
122 
123  /* Store settings on successful completion */
124  if ( rc == 0 )
125  rc = storef_setting ( NULL, &username_setting, username );
126  if ( rc == 0 )
127  rc = storef_setting ( NULL, &password_setting, password );
128 
129  /* Free setting values */
130  free ( username );
131  free ( password );
132 
133  return rc;
134 }
int getkey(unsigned long timeout)
Get single keypress.
Definition: getkey.c:71
#define KEY_ENTER
Definition: keys.h:127
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int erase(void)
Completely clear the screen.
Definition: clear.c:97
int fetchf_setting_copy(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, char **value)
Fetch copy of formatted value of setting.
Definition: settings.c:1276
static int attroff(int attrs)
Definition: curses.h:508
#define CPAIR_EDIT
Editable text.
Definition: ansicol.h:49
#define start_color()
Definition: curses.h:396
int endwin(void)
Finalise console environment.
Definition: wininit.c:31
#define mvprintw(y, x, fmt,...)
Definition: curses.h:648
#define EDITBOX_WIDTH
Definition: login_ui.c:50
#define ECANCELED
Operation canceled.
Definition: errno.h:343
#define CPAIR_NORMAL
Normal text.
Definition: ansicol.h:40
#define PASSWORD_ROW
Definition: login_ui.c:47
#define KEY_DOWN
Down arrow.
Definition: keys.h:105
#define KEY_UP
Up arrow.
Definition: keys.h:104
void init_editbox(struct edit_box *box, char **buf, WINDOW *win, unsigned int row, unsigned int col, unsigned int width, unsigned int flags)
Initialise text box widget.
Definition: editbox.c:49
WINDOW * initscr(void)
Initialise console environment.
Definition: wininit.c:17
#define CTRL_C
Definition: keys.h:20
static int edit_editbox(struct edit_box *box, int key) __nonnull
Edit text box widget.
Definition: editbox.h:57
#define TAB
Definition: keys.h:46
#define ESC
Escape character.
Definition: ansiesc.h:92
An editable text box widget.
Definition: editbox.h:16
#define EINPROGRESS
Operation in progress.
Definition: errno.h:418
int storef_setting(struct settings *settings, const struct setting *setting, const char *value)
Store formatted value of setting.
Definition: settings.c:1319
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
#define EDITBOX_COL
Definition: login_ui.c:49
#define USERNAME_ROW
Definition: login_ui.c:45
void draw_editbox(struct edit_box *box)
Draw text box widget.
Definition: editbox.c:68
Show stars instead of contents (for password widgets)
Definition: editbox.h:36
#define PASSWORD_LABEL_ROW
Definition: login_ui.c:46
#define USERNAME_LABEL_ROW
Definition: login_ui.c:44
#define color_set(cpno, opts)
Definition: curses.h:240
#define LABEL_COL
Definition: login_ui.c:48
#define A_BOLD
Definition: curses.h:138
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
union @382 key
Sense key.
Definition: crypto.h:284
static int attron(int attrs)
Definition: curses.h:512

References A_BOLD, attroff(), attron(), color_set, CPAIR_EDIT, CPAIR_NORMAL, CTRL_C, draw_editbox(), ECANCELED, edit_editbox(), EDITBOX_COL, EDITBOX_STARS, EDITBOX_WIDTH, EINPROGRESS, endwin(), erase(), ESC, fetchf_setting_copy(), free, getkey(), init_editbox(), initscr(), key, KEY_DOWN, KEY_ENTER, KEY_UP, LABEL_COL, mvprintw, NULL, PASSWORD_LABEL_ROW, PASSWORD_ROW, rc, start_color, storef_setting(), TAB, USERNAME_LABEL_ROW, and USERNAME_ROW.

Referenced by login_exec().