iPXE
Data Structures | Macros | Functions
form_ui.c File Reference

Text widget forms. More...

#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ipxe/ansicol.h>
#include <ipxe/dynui.h>
#include <ipxe/jumpscroll.h>
#include <ipxe/settings.h>
#include <ipxe/editbox.h>
#include <ipxe/message.h>

Go to the source code of this file.

Data Structures

struct  form
 A form. More...
 
struct  form_control
 A form control. More...
 

Macros

#define TITLE_ROW   1U
 Form title row. More...
 
#define START_ROW   3U
 Starting control row. More...
 
#define END_ROW   ( LINES - 3U )
 Ending control row. More...
 
#define INSTRUCTION_ROW   ( LINES - 2U )
 Instructions row. More...
 
#define INSTRUCTION_PAD   " "
 Padding between instructions. More...
 
#define INPUT_WIDTH   ( COLS / 2U )
 Input field width. More...
 
#define INPUT_COL   ( ( COLS - INPUT_WIDTH ) / 2U )
 Input field column. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static struct formalloc_form (struct dynamic_ui *dynui)
 Allocate form. More...
 
static void free_form (struct form *form)
 Free form. More...
 
static int layout_form (struct form *form)
 Assign form rows. More...
 
static void draw_form (struct form *form)
 Draw form. More...
 
static void draw_errors (struct form *form)
 Draw (or clear) error messages. More...
 
static int parse_names (struct form *form)
 Parse setting names. More...
 
static void load_values (struct form *form)
 Load current input values. More...
 
static int save_values (struct form *form)
 Store current input values. More...
 
static int submit_form (struct form *form)
 Submit form. More...
 
static int form_loop (struct form *form)
 Form main loop. More...
 
int show_form (struct dynamic_ui *dynui)
 Show form. More...
 

Detailed Description

Text widget forms.

Definition in file form_ui.c.

Macro Definition Documentation

◆ TITLE_ROW

#define TITLE_ROW   1U

Form title row.

Definition at line 43 of file form_ui.c.

◆ START_ROW

#define START_ROW   3U

Starting control row.

Definition at line 46 of file form_ui.c.

◆ END_ROW

#define END_ROW   ( LINES - 3U )

Ending control row.

Definition at line 49 of file form_ui.c.

◆ INSTRUCTION_ROW

#define INSTRUCTION_ROW   ( LINES - 2U )

Instructions row.

Definition at line 52 of file form_ui.c.

◆ INSTRUCTION_PAD

#define INSTRUCTION_PAD   " "

Padding between instructions.

Definition at line 55 of file form_ui.c.

◆ INPUT_WIDTH

#define INPUT_WIDTH   ( COLS / 2U )

Input field width.

Definition at line 58 of file form_ui.c.

◆ INPUT_COL

#define INPUT_COL   ( ( COLS - INPUT_WIDTH ) / 2U )

Input field column.

Definition at line 61 of file form_ui.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ alloc_form()

static struct form* alloc_form ( struct dynamic_ui dynui)
static

Allocate form.

Parameters
dynuiDynamic user interface
Return values
formForm, or NULL on error

Definition at line 99 of file form_ui.c.

99  {
100  struct form *form;
101  struct form_control *control;
102  struct dynamic_item *item;
103  char *name;
104  size_t len;
105 
106  /* Calculate total length */
107  len = sizeof ( *form );
108  list_for_each_entry ( item, &dynui->items, list ) {
109  len += sizeof ( *control );
110  if ( item->name )
111  len += ( strlen ( item->name ) + 1 /* NUL */ );
112  }
113 
114  /* Allocate and initialise structure */
115  form = zalloc ( len );
116  if ( ! form )
117  return NULL;
118  control = ( ( ( void * ) form ) + sizeof ( *form ) );
119  name = ( ( ( void * ) control ) +
120  ( dynui->count * sizeof ( *control ) ) );
121  form->dynui = dynui;
122  form->controls = control;
123  list_for_each_entry ( item, &dynui->items, list ) {
124  control->item = item;
125  if ( item->name ) {
126  control->name = name;
127  name = ( stpcpy ( name, item->name ) + 1 /* NUL */ );
128  }
129  control++;
130  }
131  assert ( ( ( void * ) name ) == ( ( ( void * ) form ) + len ) );
132 
133  return form;
134 }
const char * name
Definition: ath9k_hw.c:1984
A dynamic user interface item.
Definition: dynui.h:29
unsigned int count
Number of user interface items.
Definition: dynui.h:25
char * stpcpy(char *dest, const char *src)
Copy string.
Definition: string.c:326
A form.
Definition: form_ui.c:64
struct list_head items
Dynamic user interface items.
Definition: dynui.h:23
const char * name
Name.
Definition: dynui.h:33
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
uint32_t control
Control.
Definition: myson.h:14
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
A form control.
Definition: form_ui.c:74
struct form_control * controls
Array of form controls.
Definition: form_ui.c:70
struct dynamic_ui * dynui
Dynamic user interface.
Definition: form_ui.c:66
struct list_head list
List of dynamic user interface items.
Definition: dynui.h:31
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), control, form::controls, dynamic_ui::count, form::dynui, dynamic_ui::items, len, dynamic_item::list, list_for_each_entry, dynamic_item::name, name, NULL, stpcpy(), strlen(), and zalloc().

Referenced by show_form().

◆ free_form()

static void free_form ( struct form form)
static

Free form.

Parameters
formForm

Definition at line 141 of file form_ui.c.

141  {
142  unsigned int i;
143 
144  /* Free input value buffers */
145  for ( i = 0 ; i < form->dynui->count ; i++ )
146  free ( form->controls[i].value );
147 
148  /* Free form */
149  free ( form );
150 }
unsigned int count
Number of user interface items.
Definition: dynui.h:25
A form.
Definition: form_ui.c:64
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct form_control * controls
Array of form controls.
Definition: form_ui.c:70
struct dynamic_ui * dynui
Dynamic user interface.
Definition: form_ui.c:66
char * value
Modifiable setting value.
Definition: form_ui.c:88

References form::controls, dynamic_ui::count, form::dynui, free, and form_control::value.

Referenced by show_form().

◆ layout_form()

static int layout_form ( struct form form)
static

Assign form rows.

Parameters
formForm
Return values
rcReturn status code

Definition at line 158 of file form_ui.c.

158  {
159  struct form_control *control;
160  struct dynamic_item *item;
161  unsigned int labels = 0;
162  unsigned int inputs = 0;
163  unsigned int pad_control = 0;
164  unsigned int pad_label = 0;
165  unsigned int minimum;
166  unsigned int remaining;
167  unsigned int between;
168  unsigned int row;
169  unsigned int flags;
170  unsigned int i;
171 
172  /* Count labels and inputs */
173  for ( i = 0 ; i < form->dynui->count ; i++ ) {
174  control = &form->controls[i];
175  item = control->item;
176  if ( item->text[0] )
177  labels++;
178  if ( item->name ) {
179  if ( ! inputs )
180  form->scroll.current = i;
181  inputs++;
182  if ( item->flags & DYNUI_DEFAULT )
183  form->scroll.current = i;
184  form->scroll.count = ( i + 1 );
185  }
186  }
188  DBGC ( form, "FORM %p has %d controls (%d labels, %d inputs)\n",
189  form, form->dynui->count, labels, inputs );
190 
191  /* Refuse to create forms with no inputs */
192  if ( ! inputs )
193  return -EINVAL;
194 
195  /* Calculate minimum number of rows */
196  minimum = ( labels + ( inputs * 2 /* edit box and error message */ ) );
197  remaining = ( END_ROW - START_ROW );
198  DBGC ( form, "FORM %p has %d (of %d) usable rows\n",
199  form, remaining, LINES );
200  if ( minimum > remaining )
201  return -ERANGE;
202  remaining -= minimum;
203 
204  /* Insert blank row between controls, if space exists */
205  between = ( form->dynui->count - 1 );
206  if ( between <= remaining ) {
207  pad_control = 1;
208  remaining -= between;
209  DBGC ( form, "FORM %p padding between controls\n", form );
210  }
211 
212  /* Insert blank row after label, if space exists */
213  if ( labels <= remaining ) {
214  pad_label = 1;
215  remaining -= labels;
216  DBGC ( form, "FORM %p padding after labels\n", form );
217  }
218 
219  /* Centre on screen */
220  DBGC ( form, "FORM %p has %d spare rows\n", form, remaining );
221  row = ( START_ROW + ( remaining / 2 ) );
222 
223  /* Position each control */
224  for ( i = 0 ; i < form->dynui->count ; i++ ) {
225  control = &form->controls[i];
226  item = control->item;
227  if ( item->text[0] ) {
228  control->row = row;
229  row++; /* Label text */
230  row += pad_label;
231  }
232  if ( item->name ) {
233  flags = ( ( item->flags & DYNUI_SECRET ) ?
234  WIDGET_SECRET : 0 );
235  init_editbox ( &control->editbox, row, INPUT_COL,
236  INPUT_WIDTH, flags, &control->value );
237  row++; /* Edit box */
238  row++; /* Error message (if any) */
239  }
240  row += pad_control;
241  }
242  assert ( row <= END_ROW );
243 
244  return 0;
245 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
A dynamic user interface item.
Definition: dynui.h:29
Widget contains a secret.
Definition: widget.h:34
#define DBGC(...)
Definition: compiler.h:505
#define LINES(...)
Define inline lines.
Definition: linebuf_test.c:44
unsigned int count
Number of user interface items.
Definition: dynui.h:25
A form.
Definition: form_ui.c:64
#define START_ROW
Starting control row.
Definition: form_ui.c:46
const char * name
Name.
Definition: dynui.h:33
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int count
Total number of items.
Definition: jumpscroll.h:19
uint8_t flags
Flags.
Definition: ena.h:18
#define ERANGE
Result too large.
Definition: errno.h:639
#define INPUT_COL
Input field column.
Definition: form_ui.c:61
uint32_t control
Control.
Definition: myson.h:14
A form control.
Definition: form_ui.c:74
struct jump_scroller scroll
Jump scroller.
Definition: form_ui.c:68
static void init_editbox(struct edit_box *box, unsigned int row, unsigned int col, unsigned int width, unsigned int flags, char **buf)
Initialise text box widget.
Definition: editbox.h:39
struct form_control * controls
Array of form controls.
Definition: form_ui.c:70
const char * text
Text.
Definition: dynui.h:35
#define DYNUI_DEFAULT
Dynamic user interface item is default selection.
Definition: dynui.h:45
unsigned int rows
Maximum number of visible rows.
Definition: jumpscroll.h:17
#define INPUT_WIDTH
Input field width.
Definition: form_ui.c:58
struct dynamic_ui * dynui
Dynamic user interface.
Definition: form_ui.c:66
unsigned int flags
Flags.
Definition: dynui.h:39
unsigned int current
Currently selected item.
Definition: jumpscroll.h:21
#define DYNUI_SECRET
Dynamic user interface item represents a secret.
Definition: dynui.h:48
#define END_ROW
Ending control row.
Definition: form_ui.c:49

References assert(), control, form::controls, jump_scroller::count, dynamic_ui::count, jump_scroller::current, DBGC, form::dynui, DYNUI_DEFAULT, DYNUI_SECRET, EINVAL, END_ROW, ERANGE, flags, dynamic_item::flags, init_editbox(), INPUT_COL, INPUT_WIDTH, LINES, dynamic_item::name, jump_scroller::rows, form::scroll, START_ROW, dynamic_item::text, and WIDGET_SECRET.

Referenced by show_form().

◆ draw_form()

static void draw_form ( struct form form)
static

Draw form.

Parameters
formForm

Definition at line 252 of file form_ui.c.

252  {
253  struct form_control *control;
254  unsigned int i;
255 
256  /* Clear screen */
258  erase();
259 
260  /* Draw title, if any */
261  attron ( A_BOLD );
262  if ( form->dynui->title )
263  msg ( TITLE_ROW, "%s", form->dynui->title );
264  attroff ( A_BOLD );
265 
266  /* Draw controls */
267  for ( i = 0 ; i < form->dynui->count ; i++ ) {
268  control = &form->controls[i];
269 
270  /* Draw label, if any */
271  if ( control->row )
272  msg ( control->row, "%s", control->item->text );
273 
274  /* Draw input, if any */
275  if ( control->name )
276  draw_widget ( &control->editbox.widget );
277  }
278 
279  /* Draw instructions */
280  msg ( INSTRUCTION_ROW, "%s", "Ctrl-X - save changes"
281  INSTRUCTION_PAD "Ctrl-C - discard changes" );
282 }
const char * title
Title.
Definition: dynui.h:21
static void draw_widget(struct widget *widget)
Draw text widget.
Definition: widget.h:86
void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: message.c:61
int erase(void)
Completely clear the screen.
Definition: clear.c:97
#define TITLE_ROW
Form title row.
Definition: form_ui.c:43
static int attroff(int attrs)
Definition: curses.h:508
#define INSTRUCTION_ROW
Instructions row.
Definition: form_ui.c:52
unsigned int count
Number of user interface items.
Definition: dynui.h:25
#define CPAIR_NORMAL
Normal text.
Definition: ansicol.h:40
A form.
Definition: form_ui.c:64
uint32_t control
Control.
Definition: myson.h:14
A form control.
Definition: form_ui.c:74
struct form_control * controls
Array of form controls.
Definition: form_ui.c:70
#define INSTRUCTION_PAD
Padding between instructions.
Definition: form_ui.c:55
#define color_set(cpno, opts)
Definition: curses.h:240
#define A_BOLD
Definition: curses.h:138
struct dynamic_ui * dynui
Dynamic user interface.
Definition: form_ui.c:66
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static int attron(int attrs)
Definition: curses.h:512

References A_BOLD, attroff(), attron(), color_set, control, form::controls, dynamic_ui::count, CPAIR_NORMAL, draw_widget(), form::dynui, erase(), INSTRUCTION_PAD, INSTRUCTION_ROW, msg(), NULL, dynamic_ui::title, and TITLE_ROW.

Referenced by show_form().

◆ draw_errors()

static void draw_errors ( struct form form)
static

Draw (or clear) error messages.

Parameters
formForm

Definition at line 289 of file form_ui.c.

289  {
290  struct form_control *control;
291  unsigned int row;
292  unsigned int i;
293 
294  /* Draw (or clear) errors */
295  for ( i = 0 ; i < form->dynui->count ; i++ ) {
296  control = &form->controls[i];
297 
298  /* Skip non-input controls */
299  if ( ! control->name )
300  continue;
301 
302  /* Draw or clear error message as appropriate */
303  row = ( control->editbox.widget.row + 1 );
304  if ( control->rc != 0 ) {
306  msg ( row, " %s ", strerror ( control->rc ) );
308  } else {
309  clearmsg ( row );
310  }
311  }
312 }
void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: message.c:61
void clearmsg(unsigned int row)
Clear message on specified row.
Definition: message.c:74
unsigned int count
Number of user interface items.
Definition: dynui.h:25
#define CPAIR_NORMAL
Normal text.
Definition: ansicol.h:40
A form.
Definition: form_ui.c:64
#define CPAIR_ALERT
Error text.
Definition: ansicol.h:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
uint32_t control
Control.
Definition: myson.h:14
A form control.
Definition: form_ui.c:74
unsigned int row
Label row.
Definition: form_ui.c:82
struct form_control * controls
Array of form controls.
Definition: form_ui.c:70
#define color_set(cpno, opts)
Definition: curses.h:240
struct dynamic_ui * dynui
Dynamic user interface.
Definition: form_ui.c:66
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References clearmsg(), color_set, control, form::controls, dynamic_ui::count, CPAIR_ALERT, CPAIR_NORMAL, form::dynui, msg(), NULL, form_control::row, and strerror().

Referenced by submit_form().

◆ parse_names()

static int parse_names ( struct form form)
static

Parse setting names.

Parameters
formForm
Return values
rcReturn status code

Definition at line 320 of file form_ui.c.

320  {
321  struct form_control *control;
322  unsigned int i;
323  int rc;
324 
325  /* Parse all setting names */
326  for ( i = 0 ; i < form->dynui->count ; i++ ) {
327  control = &form->controls[i];
328 
329  /* Skip labels */
330  if ( ! control->name ) {
331  DBGC ( form, "FORM %p item %d is a label\n", form, i );
332  continue;
333  }
334 
335  /* Parse setting name */
336  DBGC ( form, "FORM %p item %d is for %s\n",
337  form, i, control->name );
338  if ( ( rc = parse_setting_name ( control->name,
340  &control->settings,
341  &control->setting ) ) != 0 )
342  return rc;
343 
344  /* Apply default type if necessary */
345  if ( ! control->setting.type )
346  control->setting.type = &setting_type_string;
347  }
348 
349  return 0;
350 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
unsigned int count
Number of user interface items.
Definition: dynui.h:25
A form.
Definition: form_ui.c:64
struct settings * autovivify_child_settings(struct settings *parent, const char *name)
Find or create child settings block.
Definition: settings.c:306
uint32_t control
Control.
Definition: myson.h:14
A form control.
Definition: form_ui.c:74
struct form_control * controls
Array of form controls.
Definition: form_ui.c:70
struct dynamic_ui * dynui
Dynamic user interface.
Definition: form_ui.c:66
int parse_setting_name(char *name, get_child_settings_t get_child, struct settings **settings, struct setting *setting)
Parse setting name.
Definition: settings.c:1528

References autovivify_child_settings(), control, form::controls, dynamic_ui::count, DBGC, form::dynui, parse_setting_name(), and rc.

Referenced by show_form().

◆ load_values()

static void load_values ( struct form form)
static

Load current input values.

Parameters
formForm

Definition at line 357 of file form_ui.c.

357  {
358  struct form_control *control;
359  unsigned int i;
360 
361  /* Fetch all current setting values */
362  for ( i = 0 ; i < form->dynui->count ; i++ ) {
363  control = &form->controls[i];
364  if ( ! control->name )
365  continue;
366  fetchf_setting_copy ( control->settings, &control->setting,
367  NULL, &control->setting,
368  &control->value );
369  }
370 }
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
unsigned int count
Number of user interface items.
Definition: dynui.h:25
A form.
Definition: form_ui.c:64
uint32_t control
Control.
Definition: myson.h:14
A form control.
Definition: form_ui.c:74
struct form_control * controls
Array of form controls.
Definition: form_ui.c:70
struct dynamic_ui * dynui
Dynamic user interface.
Definition: form_ui.c:66
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References control, form::controls, dynamic_ui::count, form::dynui, fetchf_setting_copy(), and NULL.

Referenced by show_form().

◆ save_values()

static int save_values ( struct form form)
static

Store current input values.

Parameters
formForm
Return values
rcReturn status code

Definition at line 378 of file form_ui.c.

378  {
379  struct form_control *control;
380  unsigned int i;
381  int rc = 0;
382 
383  /* Store all current setting values */
384  for ( i = 0 ; i < form->dynui->count ; i++ ) {
385  control = &form->controls[i];
386  if ( ! control->name )
387  continue;
388  control->rc = storef_setting ( control->settings,
389  &control->setting,
390  control->value );
391  if ( control->rc != 0 )
392  rc = control->rc;
393  }
394 
395  return rc;
396 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int count
Number of user interface items.
Definition: dynui.h:25
A form.
Definition: form_ui.c:64
int storef_setting(struct settings *settings, const struct setting *setting, const char *value)
Store formatted value of setting.
Definition: settings.c:1319
uint32_t control
Control.
Definition: myson.h:14
A form control.
Definition: form_ui.c:74
struct form_control * controls
Array of form controls.
Definition: form_ui.c:70
struct dynamic_ui * dynui
Dynamic user interface.
Definition: form_ui.c:66

References control, form::controls, dynamic_ui::count, form::dynui, rc, and storef_setting().

Referenced by submit_form().

◆ submit_form()

static int submit_form ( struct form form)
static

Submit form.

Parameters
formForm
Return values
rcReturn status code

Definition at line 404 of file form_ui.c.

404  {
405  int rc;
406 
407  /* Attempt to save values */
408  rc = save_values ( form );
409 
410  /* Draw (or clear) errors */
411  draw_errors ( form );
412 
413  return rc;
414 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int save_values(struct form *form)
Store current input values.
Definition: form_ui.c:378
A form.
Definition: form_ui.c:64
static void draw_errors(struct form *form)
Draw (or clear) error messages.
Definition: form_ui.c:289

References draw_errors(), rc, and save_values().

Referenced by form_loop().

◆ form_loop()

static int form_loop ( struct form form)
static

Form main loop.

Parameters
formForm
Return values
rcReturn status code

Definition at line 422 of file form_ui.c.

422  {
423  struct jump_scroller *scroll = &form->scroll;
424  struct form_control *control;
425  struct dynamic_item *item;
426  unsigned int move;
427  unsigned int i;
428  int key;
429  int rc;
430 
431  /* Main loop */
432  while ( 1 ) {
433 
434  /* Draw current input */
435  control = &form->controls[scroll->current];
436  draw_widget ( &control->editbox.widget );
437 
438  /* Process keypress */
439  key = edit_widget ( &control->editbox.widget, getkey ( 0 ) );
440 
441  /* Handle scroll keys */
443 
444  /* Handle special keys */
445  switch ( key ) {
446  case CTRL_C:
447  case ESC:
448  /* Cancel form */
449  return -ECANCELED;
450  case KEY_ENTER:
451  /* Attempt to do the most intuitive thing when
452  * Enter is pressed. If we are on the last
453  * input, then submit the form. If we are
454  * editing an input which failed, then
455  * resubmit the form. Otherwise, move to the
456  * next input.
457  */
458  if ( ( control->rc == 0 ) &&
459  ( scroll->current < ( scroll->count - 1 ) ) ) {
460  move = SCROLL_DOWN;
461  break;
462  }
463  /* fall through */
464  case CTRL_X:
465  /* Submit form */
466  if ( ( rc = submit_form ( form ) ) == 0 )
467  return 0;
468  /* If current input is not the problem, move
469  * to the first input that needs fixing.
470  */
471  if ( control->rc == 0 ) {
472  for ( i = 0 ; i < form->dynui->count ; i++ ) {
473  if ( form->controls[i].rc != 0 ) {
474  scroll->current = i;
475  break;
476  }
477  }
478  }
479  break;
480  default:
481  /* Move to input with matching shortcut key, if any */
482  item = dynui_shortcut ( form->dynui, key );
483  if ( item ) {
484  scroll->current = item->index;
485  if ( ! item->name )
486  move = SCROLL_DOWN;
487  }
488  break;
489  }
490 
491  /* Move selection, if applicable */
492  while ( move ) {
494  control = &form->controls[scroll->current];
495  if ( control->name )
496  break;
497  }
498  }
499 }
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
A dynamic user interface item.
Definition: dynui.h:29
static void draw_widget(struct widget *widget)
Draw text widget.
Definition: widget.h:86
unsigned int count
Number of user interface items.
Definition: dynui.h:25
A jump scroller.
Definition: jumpscroll.h:15
#define ECANCELED
Operation canceled.
Definition: errno.h:343
int rc
Most recent error in saving.
Definition: form_ui.c:90
#define CTRL_X
Definition: keys.h:41
A form.
Definition: form_ui.c:64
const char * name
Name.
Definition: dynui.h:33
struct dynamic_item * dynui_shortcut(struct dynamic_ui *dynui, int key)
Find dynamic user interface item by shortcut key.
Definition: dynui.c:211
unsigned int count
Total number of items.
Definition: jumpscroll.h:19
#define CTRL_C
Definition: keys.h:20
#define ESC
Escape character.
Definition: ansiesc.h:92
unsigned int jump_scroll_move(struct jump_scroller *scroll, unsigned int move)
Move scroller.
Definition: jumpscroll.c:92
uint32_t control
Control.
Definition: myson.h:14
A form control.
Definition: form_ui.c:74
struct jump_scroller scroll
Jump scroller.
Definition: form_ui.c:68
#define SCROLL_DOWN
Scroll down by one line.
Definition: jumpscroll.h:53
struct form_control * controls
Array of form controls.
Definition: form_ui.c:70
static int submit_form(struct form *form)
Submit form.
Definition: form_ui.c:404
static int move(int y, int x)
Definition: curses.h:593
struct dynamic_ui * dynui
Dynamic user interface.
Definition: form_ui.c:66
unsigned int current
Currently selected item.
Definition: jumpscroll.h:21
unsigned int index
Index.
Definition: dynui.h:37
unsigned int jump_scroll_key(struct jump_scroller *scroll, int key)
Jump scrolling.
Definition: jumpscroll.c:42
static int edit_widget(struct widget *widget, int key)
Edit text widget.
Definition: widget.h:103
union @383 key
Sense key.
Definition: scsi.h:18

References control, form::controls, jump_scroller::count, dynamic_ui::count, CTRL_C, CTRL_X, jump_scroller::current, draw_widget(), form::dynui, dynui_shortcut(), ECANCELED, edit_widget(), ESC, getkey(), dynamic_item::index, jump_scroll_key(), jump_scroll_move(), key, KEY_ENTER, move(), dynamic_item::name, form_control::rc, rc, form::scroll, SCROLL_DOWN, and submit_form().

Referenced by show_form().

◆ show_form()

int show_form ( struct dynamic_ui dynui)

Show form.

Parameters
dynuiDynamic user interface
Return values
rcReturn status code

Definition at line 507 of file form_ui.c.

507  {
508  struct form *form;
509  int rc;
510 
511  /* Allocate and initialise structure */
512  form = alloc_form ( dynui );
513  if ( ! form ) {
514  rc = -ENOMEM;
515  goto err_alloc;
516  }
517 
518  /* Parse setting names and load current values */
519  if ( ( rc = parse_names ( form ) ) != 0 )
520  goto err_parse_names;
521  load_values ( form );
522 
523  /* Lay out form on screen */
524  if ( ( rc = layout_form ( form ) ) != 0 )
525  goto err_layout;
526 
527  /* Draw initial form */
528  initscr();
529  start_color();
530  draw_form ( form );
531 
532  /* Run main loop */
533  if ( ( rc = form_loop ( form ) ) != 0 )
534  goto err_loop;
535 
536  err_loop:
538  endwin();
539  err_layout:
540  err_parse_names:
541  free_form ( form );
542  err_alloc:
543  return rc;
544 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void draw_form(struct form *form)
Draw form.
Definition: form_ui.c:252
static int parse_names(struct form *form)
Parse setting names.
Definition: form_ui.c:320
#define start_color()
Definition: curses.h:396
int endwin(void)
Finalise console environment.
Definition: wininit.c:31
static int layout_form(struct form *form)
Assign form rows.
Definition: form_ui.c:158
#define CPAIR_NORMAL
Normal text.
Definition: ansicol.h:40
#define ENOMEM
Not enough space.
Definition: errno.h:534
A form.
Definition: form_ui.c:64
static void free_form(struct form *form)
Free form.
Definition: form_ui.c:141
WINDOW * initscr(void)
Initialise console environment.
Definition: wininit.c:17
static void load_values(struct form *form)
Load current input values.
Definition: form_ui.c:357
static struct form * alloc_form(struct dynamic_ui *dynui)
Allocate form.
Definition: form_ui.c:99
static int form_loop(struct form *form)
Form main loop.
Definition: form_ui.c:422
#define color_set(cpno, opts)
Definition: curses.h:240
struct dynamic_ui * dynui
Dynamic user interface.
Definition: form_ui.c:66
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References alloc_form(), color_set, CPAIR_NORMAL, draw_form(), form::dynui, endwin(), ENOMEM, form_loop(), free_form(), initscr(), layout_form(), load_values(), NULL, parse_names(), rc, and start_color.

Referenced by login_ui(), and present_exec().