iPXE
Macros | Functions
login_ui.c File Reference

Login UI. More...

#include <string.h>
#include <errno.h>
#include <curses.h>
#include <ipxe/console.h>
#include <ipxe/settings.h>
#include <ipxe/editbox.h>
#include <ipxe/keys.h>
#include <ipxe/ansicol.h>
#include <ipxe/login_ui.h>

Go to the source code of this file.

Macros

#define USERNAME_LABEL_ROW   ( ( LINES / 2U ) - 4U )
 
#define USERNAME_ROW   ( ( LINES / 2U ) - 2U )
 
#define PASSWORD_LABEL_ROW   ( ( LINES / 2U ) + 2U )
 
#define PASSWORD_ROW   ( ( LINES / 2U ) + 4U )
 
#define LABEL_COL   ( ( COLS / 2U ) - 4U )
 
#define EDITBOX_COL   ( ( COLS / 2U ) - 10U )
 
#define EDITBOX_WIDTH   20U
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int login_ui (void)
 

Detailed Description

Login UI.

Definition in file login_ui.c.

Macro Definition Documentation

◆ USERNAME_LABEL_ROW

#define USERNAME_LABEL_ROW   ( ( LINES / 2U ) - 4U )

Definition at line 43 of file login_ui.c.

◆ USERNAME_ROW

#define USERNAME_ROW   ( ( LINES / 2U ) - 2U )

Definition at line 44 of file login_ui.c.

◆ PASSWORD_LABEL_ROW

#define PASSWORD_LABEL_ROW   ( ( LINES / 2U ) + 2U )

Definition at line 45 of file login_ui.c.

◆ PASSWORD_ROW

#define PASSWORD_ROW   ( ( LINES / 2U ) + 4U )

Definition at line 46 of file login_ui.c.

◆ LABEL_COL

#define LABEL_COL   ( ( COLS / 2U ) - 4U )

Definition at line 47 of file login_ui.c.

◆ EDITBOX_COL

#define EDITBOX_COL   ( ( COLS / 2U ) - 10U )

Definition at line 48 of file login_ui.c.

◆ EDITBOX_WIDTH

#define EDITBOX_WIDTH   20U

Definition at line 49 of file login_ui.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ login_ui()

int login_ui ( void  )

Definition at line 51 of file login_ui.c.

51  {
52  char username[64];
53  char password[64];
54  struct edit_box username_box;
55  struct edit_box password_box;
56  struct edit_box *current_box = &username_box;
57  int key;
58  int rc = -EINPROGRESS;
59 
60  /* Fetch current setting values */
61  fetch_string_setting ( NULL, &username_setting, username,
62  sizeof ( username ) );
63  fetch_string_setting ( NULL, &password_setting, password,
64  sizeof ( password ) );
65 
66  /* Initialise UI */
67  initscr();
68  start_color();
69  init_editbox ( &username_box, username, sizeof ( username ), NULL,
71  init_editbox ( &password_box, password, sizeof ( password ), NULL,
73  EDITBOX_STARS );
74 
75  /* Draw initial UI */
77  erase();
78  attron ( A_BOLD );
79  mvprintw ( USERNAME_LABEL_ROW, LABEL_COL, "Username:" );
80  mvprintw ( PASSWORD_LABEL_ROW, LABEL_COL, "Password:" );
81  attroff ( A_BOLD );
83  draw_editbox ( &username_box );
84  draw_editbox ( &password_box );
85 
86  /* Main loop */
87  while ( rc == -EINPROGRESS ) {
88 
89  draw_editbox ( current_box );
90 
91  key = getkey ( 0 );
92  switch ( key ) {
93  case KEY_DOWN:
94  current_box = &password_box;
95  break;
96  case KEY_UP:
97  current_box = &username_box;
98  break;
99  case TAB:
100  current_box = ( ( current_box == &username_box ) ?
101  &password_box : &username_box );
102  break;
103  case KEY_ENTER:
104  if ( current_box == &username_box ) {
105  current_box = &password_box;
106  } else {
107  rc = 0;
108  }
109  break;
110  case CTRL_C:
111  case ESC:
112  rc = -ECANCELED;
113  break;
114  default:
115  edit_editbox ( current_box, key );
116  break;
117  }
118  }
119 
120  /* Terminate UI */
122  erase();
123  endwin();
124 
125  if ( rc != 0 )
126  return rc;
127 
128  /* Store settings */
129  if ( ( rc = store_setting ( NULL, &username_setting, username,
130  strlen ( username ) ) ) != 0 )
131  return rc;
132  if ( ( rc = store_setting ( NULL, &password_setting, password,
133  strlen ( password ) ) ) != 0 )
134  return rc;
135 
136  return 0;
137 }
int getkey(unsigned long timeout)
Get single keypress.
Definition: getkey.c:71
#define KEY_ENTER
Definition: keys.h:88
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int erase(void)
Completely clear the screen.
Definition: clear.c:97
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
int store_setting(struct settings *settings, const struct setting *setting, const void *data, size_t len)
Store value of setting.
Definition: settings.c:618
#define EDITBOX_WIDTH
Definition: login_ui.c:49
#define ECANCELED
Operation canceled.
Definition: errno.h:343
#define CPAIR_NORMAL
Normal text.
Definition: ansicol.h:40
#define PASSWORD_ROW
Definition: login_ui.c:46
#define KEY_DOWN
Down arrow.
Definition: keys.h:66
#define KEY_UP
Up arrow.
Definition: keys.h:65
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
int fetch_string_setting(struct settings *settings, const struct setting *setting, char *data, size_t len)
Fetch value of string setting.
Definition: settings.c:845
#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
void init_editbox(struct edit_box *box, char *buf, size_t len, WINDOW *win, unsigned int row, unsigned int col, unsigned int width, unsigned int flags)
Initialise text box widget.
Definition: editbox.c:50
#define EDITBOX_COL
Definition: login_ui.c:48
size_t strlen(const char *src)
Get length of string.
Definition: string.c:228
#define USERNAME_ROW
Definition: login_ui.c:44
void draw_editbox(struct edit_box *box)
Draw text box widget.
Definition: editbox.c:69
Show stars instead of contents (for password widgets)
Definition: editbox.h:36
#define PASSWORD_LABEL_ROW
Definition: login_ui.c:45
#define USERNAME_LABEL_ROW
Definition: login_ui.c:43
#define color_set(cpno, opts)
Definition: curses.h:240
#define LABEL_COL
Definition: login_ui.c:47
#define A_BOLD
Definition: curses.h:138
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
union @376 key
Sense key.
Definition: scsi.h:18
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, fetch_string_setting(), getkey(), init_editbox(), initscr(), key, KEY_DOWN, KEY_ENTER, KEY_UP, LABEL_COL, mvprintw, NULL, PASSWORD_LABEL_ROW, PASSWORD_ROW, rc, start_color, store_setting(), strlen(), TAB, USERNAME_LABEL_ROW, and USERNAME_ROW.

Referenced by login_exec().