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

Option configuration console. More...

#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.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/jumpscroll.h>
#include <ipxe/settings_ui.h>
#include <config/branding.h>

Go to the source code of this file.

Data Structures

struct  settings_ui_row
 A settings user interface row. More...
 
struct  settings_ui
 A settings user interface. More...
 

Macros

#define TITLE_ROW   1U
 
#define SETTINGS_LIST_ROW   3U
 
#define SETTINGS_LIST_COL   1U
 
#define SETTINGS_LIST_ROWS   ( LINES - 6U - SETTINGS_LIST_ROW )
 
#define INFO_ROW   ( LINES - 5U )
 
#define ALERT_ROW   ( LINES - 2U )
 
#define INSTRUCTION_ROW   ( LINES - 2U )
 
#define INSTRUCTION_PAD   " "
 
#define SETTING_ROW_TEXT(cols)
 Layout of text within a setting row. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static unsigned int select_setting_row (struct settings_ui *ui, unsigned int index)
 Select a setting. More...
 
static size_t string_copy (char *dest, const char *src, size_t len)
 Copy string without NUL termination. More...
 
static void draw_setting_row (struct settings_ui *ui)
 Draw setting row. More...
 
static int edit_setting (struct settings_ui *ui, int key)
 Edit setting ui. More...
 
static int save_setting (struct settings_ui *ui)
 Save setting ui value back to configuration settings. More...
 
static void vmsg (unsigned int row, const char *fmt, va_list args)
 Print message centred on specified row. More...
 
static void msg (unsigned int row, const char *fmt,...)
 Print message centred on specified row. More...
 
static void clearmsg (unsigned int row)
 Clear message on specified row. More...
 
static void valert (const char *fmt, va_list args)
 Print alert message. More...
 
static void alert (const char *fmt,...)
 Print alert message. More...
 
static void draw_title_row (struct settings_ui *ui)
 Draw title row. More...
 
static void draw_info_row (struct settings_ui *ui)
 Draw information row. More...
 
static void draw_instruction_row (struct settings_ui *ui)
 Draw instruction row. More...
 
static void draw_setting_rows (struct settings_ui *ui)
 Draw the current block of setting rows. More...
 
static void select_settings (struct settings_ui *ui, struct settings *settings)
 Select settings block. More...
 
static int main_loop (struct settings *settings)
 
int settings_ui (struct settings *settings)
 

Detailed Description

Option configuration console.

Definition in file settings_ui.c.

Macro Definition Documentation

◆ TITLE_ROW

#define TITLE_ROW   1U

Definition at line 47 of file settings_ui.c.

◆ SETTINGS_LIST_ROW

#define SETTINGS_LIST_ROW   3U

Definition at line 48 of file settings_ui.c.

◆ SETTINGS_LIST_COL

#define SETTINGS_LIST_COL   1U

Definition at line 49 of file settings_ui.c.

◆ SETTINGS_LIST_ROWS

#define SETTINGS_LIST_ROWS   ( LINES - 6U - SETTINGS_LIST_ROW )

Definition at line 50 of file settings_ui.c.

◆ INFO_ROW

#define INFO_ROW   ( LINES - 5U )

Definition at line 51 of file settings_ui.c.

◆ ALERT_ROW

#define ALERT_ROW   ( LINES - 2U )

Definition at line 52 of file settings_ui.c.

◆ INSTRUCTION_ROW

#define INSTRUCTION_ROW   ( LINES - 2U )

Definition at line 53 of file settings_ui.c.

◆ INSTRUCTION_PAD

#define INSTRUCTION_PAD   " "

Definition at line 54 of file settings_ui.c.

◆ SETTING_ROW_TEXT

#define SETTING_ROW_TEXT (   cols)
Value:
struct { \
char start[0]; \
char pad1[1]; \
union { \
char settings[ cols - 1 - 1 - 1 - 1 ]; \
struct { \
char name[15]; \
char pad2[1]; \
char value[ cols - 1 - 15 - 1 - 1 - 1 - 1 ]; \
} setting; \
} u; \
char pad3[1]; \
char nul; \
} __attribute__ (( packed ))
#define __attribute__(x)
Definition: compiler.h:10
const char * name
Definition: ath9k_hw.c:1984
uint32_t start
Starting offset.
Definition: netvsc.h:12
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
union @16 u
uint16_t pad1
Unused.
Definition: bzimage.h:53
uint8_t pad2[3]
Unused.
Definition: bzimage.h:63

Layout of text within a setting row.

Definition at line 57 of file settings_ui.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ select_setting_row()

static unsigned int select_setting_row ( struct settings_ui ui,
unsigned int  index 
)
static

Select a setting.

Parameters
uiSettings user interface
indexIndex of setting row
Return values
countNumber of setting rows

Definition at line 116 of file settings_ui.c.

117  {
118  SETTING_ROW_TEXT ( COLS ) *text;
119  struct settings *settings;
120  struct setting *setting;
121  struct setting *previous = NULL;
122  unsigned int count = 0;
123 
124  /* Initialise structure */
125  memset ( &ui->row, 0, sizeof ( ui->row ) );
126  ui->row.row = ( SETTINGS_LIST_ROW + index - ui->scroll.first );
127 
128  /* Include parent settings block, if applicable */
129  if ( ui->settings->parent && ( count++ == index ) ) {
130  ui->row.settings = ui->settings->parent;
131  snprintf ( ui->row.value, sizeof ( ui->row.value ),
132  "../" );
133  }
134 
135  /* Include any child settings blocks, if applicable */
136  list_for_each_entry ( settings, &ui->settings->children, siblings ) {
137  if ( count++ == index ) {
138  ui->row.settings = settings;
139  snprintf ( ui->row.value, sizeof ( ui->row.value ),
140  "%s/", settings->name );
141  }
142  }
143 
144  /* Include any applicable settings */
146 
147  /* Skip inapplicable settings */
148  if ( ! setting_applies ( ui->settings, setting ) )
149  continue;
150 
151  /* Skip duplicate settings */
152  if ( previous && ( setting_cmp ( setting, previous ) == 0 ) )
153  continue;
154  previous = setting;
155 
156  /* Read current setting value and origin */
157  if ( count++ == index ) {
159  &ui->row.setting, ui->row.value,
160  sizeof ( ui->row.value ) );
161  }
162  }
163 
164  /* Initialise edit box */
165  init_editbox ( &ui->row.editbox, ui->row.value,
166  sizeof ( ui->row.value ), NULL, ui->row.row,
168  offsetof ( typeof ( *text ), u.setting.value ) ),
169  sizeof ( text->u.setting.value ), 0 );
170 
171  return count;
172 }
int fetchf_setting(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, char *buf, size_t len)
Fetch formatted value of setting.
Definition: settings.c:1233
struct settings * parent
Parent settings block.
Definition: settings.h:138
struct settings_ui_row row
Current row.
Definition: settings_ui.c:106
#define SETTINGS_LIST_ROW
Definition: settings_ui.c:48
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
struct settings * origin
Configuration setting origin.
Definition: settings_ui.c:83
#define SETTINGS
Configuration setting table.
Definition: settings.h:53
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
unsigned int first
First visible item.
Definition: jumpscroll.h:21
struct settings * settings
Target configuration settings block.
Definition: settings_ui.c:78
struct settings * settings
Settings block.
Definition: settings_ui.c:102
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
int setting_applies(struct settings *settings, const struct setting *setting)
Check applicability of setting.
Definition: settings.c:573
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
A settings block.
Definition: settings.h:132
const char * name
Name.
Definition: settings.h:136
#define COLS
Definition: curses.h:111
A setting.
Definition: settings.h:23
char value[256]
Buffer for setting's value.
Definition: settings_ui.c:96
unsigned int row
Screen row.
Definition: settings_ui.c:90
struct setting setting
Configuration setting.
Definition: settings_ui.c:88
uint16_t count
Number of entries.
Definition: ena.h:22
struct jump_scroller scroll
Jump scroller.
Definition: settings_ui.c:104
struct edit_box editbox
Edit box widget used for editing setting.
Definition: settings_ui.c:92
#define SETTINGS_LIST_COL
Definition: settings_ui.c:49
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
struct list_head children
Child settings blocks.
Definition: settings.h:142
union @16 u
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
int setting_cmp(const struct setting *a, const struct setting *b)
Compare two settings.
Definition: settings.c:1124
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define SETTING_ROW_TEXT(cols)
Layout of text within a setting row.
Definition: settings_ui.c:57
void * memset(void *dest, int character, size_t len) __nonnull

References settings::children, COLS, count, settings_ui_row::editbox, fetchf_setting(), jump_scroller::first, for_each_table_entry, index, init_editbox(), list_for_each_entry, memset(), settings::name, NULL, offsetof, settings_ui_row::origin, settings::parent, settings_ui_row::row, settings_ui::row, settings_ui::scroll, settings_ui_row::setting, setting_applies(), setting_cmp(), SETTING_ROW_TEXT, SETTINGS, settings_ui_row::settings, settings_ui::settings, SETTINGS_LIST_COL, SETTINGS_LIST_ROW, snprintf(), u, and settings_ui_row::value.

Referenced by draw_setting_rows(), main_loop(), and select_settings().

◆ string_copy()

static size_t string_copy ( char *  dest,
const char *  src,
size_t  len 
)
static

Copy string without NUL termination.

Parameters
destDestination
srcSource
lenMaximum length of destination
Return values
lenLength of (unterminated) string

Definition at line 182 of file settings_ui.c.

182  {
183  size_t src_len;
184 
185  src_len = strlen ( src );
186  if ( len > src_len )
187  len = src_len;
188  memcpy ( dest, src, len );
189  return len;
190 }
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static void * dest
Definition: strings.h:176
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
size_t strlen(const char *src)
Get length of string.
Definition: string.c:228
uint32_t len
Length.
Definition: ena.h:14

References dest, len, memcpy(), src, and strlen().

Referenced by draw_setting_row().

◆ draw_setting_row()

static void draw_setting_row ( struct settings_ui ui)
static

Draw setting row.

Parameters
uiSettings UI

Definition at line 197 of file settings_ui.c.

197  {
198  SETTING_ROW_TEXT ( COLS ) text;
199  unsigned int curs_offset;
200  char *value;
201 
202  /* Fill row with spaces */
203  memset ( &text, ' ', sizeof ( text ) );
204  text.nul = '\0';
205 
206  /* Construct row content */
207  if ( ui->row.settings ) {
208 
209  /* Construct space-padded name */
210  curs_offset = ( offsetof ( typeof ( text ), u.settings ) +
211  string_copy ( text.u.settings,
212  ui->row.value,
213  sizeof ( text.u.settings ) ) );
214 
215  } else {
216 
217  /* Construct dot-padded name */
218  memset ( text.u.setting.name, '.',
219  sizeof ( text.u.setting.name ) );
220  string_copy ( text.u.setting.name, ui->row.setting.name,
221  sizeof ( text.u.setting.name ) );
222 
223  /* Construct space-padded value */
224  value = ui->row.value;
225  if ( ! *value )
226  value = "<not specified>";
227  curs_offset = ( offsetof ( typeof ( text ), u.setting.value ) +
228  string_copy ( text.u.setting.value, value,
229  sizeof ( text.u.setting.value )));
230  }
231 
232  /* Print row */
233  if ( ( ui->row.origin == ui->settings ) || ( ui->row.settings != NULL ))
234  attron ( A_BOLD );
235  mvprintw ( ui->row.row, SETTINGS_LIST_COL, "%s", text.start );
236  attroff ( A_BOLD );
237  move ( ui->row.row, ( SETTINGS_LIST_COL + curs_offset ) );
238 }
static int attroff(int attrs)
Definition: curses.h:508
struct settings_ui_row row
Current row.
Definition: settings_ui.c:106
#define mvprintw(y, x, fmt,...)
Definition: curses.h:648
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
struct settings * origin
Configuration setting origin.
Definition: settings_ui.c:83
const char * name
Name.
Definition: settings.h:28
struct settings * settings
Target configuration settings block.
Definition: settings_ui.c:78
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
struct settings * settings
Settings block.
Definition: settings_ui.c:102
#define COLS
Definition: curses.h:111
char value[256]
Buffer for setting's value.
Definition: settings_ui.c:96
unsigned int row
Screen row.
Definition: settings_ui.c:90
struct setting setting
Configuration setting.
Definition: settings_ui.c:88
static int move(int y, int x)
Definition: curses.h:593
#define SETTINGS_LIST_COL
Definition: settings_ui.c:49
union @16 u
#define A_BOLD
Definition: curses.h:138
static size_t string_copy(char *dest, const char *src, size_t len)
Copy string without NUL termination.
Definition: settings_ui.c:182
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define SETTING_ROW_TEXT(cols)
Layout of text within a setting row.
Definition: settings_ui.c:57
static int attron(int attrs)
Definition: curses.h:512
void * memset(void *dest, int character, size_t len) __nonnull

References A_BOLD, attroff(), attron(), COLS, memset(), move(), mvprintw, setting::name, NULL, offsetof, settings_ui_row::origin, settings_ui_row::row, settings_ui::row, settings_ui_row::setting, SETTING_ROW_TEXT, settings_ui_row::settings, settings_ui::settings, SETTINGS_LIST_COL, string_copy(), u, value, and settings_ui_row::value.

Referenced by draw_setting_rows(), and main_loop().

◆ edit_setting()

static int edit_setting ( struct settings_ui ui,
int  key 
)
static

Edit setting ui.

Parameters
uiSettings UI
keyKey pressed by user
Return values
keyKey returned to application, or zero

Definition at line 247 of file settings_ui.c.

247  {
248  assert ( ui->row.setting.name != NULL );
249  ui->row.editing = 1;
250  return edit_editbox ( &ui->row.editbox, key );
251 }
int editing
Editing in progress flag.
Definition: settings_ui.c:94
struct settings_ui_row row
Current row.
Definition: settings_ui.c:106
const char * name
Name.
Definition: settings.h:28
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static int edit_editbox(struct edit_box *box, int key) __nonnull
Edit text box widget.
Definition: editbox.h:57
struct setting setting
Configuration setting.
Definition: settings_ui.c:88
struct edit_box editbox
Edit box widget used for editing setting.
Definition: settings_ui.c:92
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
union @375 key
Sense key.
Definition: scsi.h:18

References assert(), edit_editbox(), settings_ui_row::editbox, settings_ui_row::editing, key, setting::name, NULL, settings_ui::row, and settings_ui_row::setting.

Referenced by main_loop().

◆ save_setting()

static int save_setting ( struct settings_ui ui)
static

Save setting ui value back to configuration settings.

Parameters
uiSettings UI

Definition at line 258 of file settings_ui.c.

258  {
259  assert ( ui->row.setting.name != NULL );
260  return storef_setting ( ui->settings, &ui->row.setting, ui->row.value );
261 }
struct settings_ui_row row
Current row.
Definition: settings_ui.c:106
const char * name
Name.
Definition: settings.h:28
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
int storef_setting(struct settings *settings, const struct setting *setting, const char *value)
Store formatted value of setting.
Definition: settings.c:1323
struct settings * settings
Settings block.
Definition: settings_ui.c:102
char value[256]
Buffer for setting's value.
Definition: settings_ui.c:96
struct setting setting
Configuration setting.
Definition: settings_ui.c:88
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References assert(), setting::name, NULL, settings_ui::row, settings_ui_row::setting, settings_ui::settings, storef_setting(), and settings_ui_row::value.

Referenced by main_loop().

◆ vmsg()

static void vmsg ( unsigned int  row,
const char *  fmt,
va_list  args 
)
static

Print message centred on specified row.

Parameters
rowRow
fmtprintf() format string
argsprintf() argument list

Definition at line 270 of file settings_ui.c.

270  {
271  char buf[COLS];
272  size_t len;
273 
274  len = vsnprintf ( buf, sizeof ( buf ), fmt, args );
275  mvprintw ( row, ( ( COLS - len ) / 2 ), "%s", buf );
276 }
#define mvprintw(y, x, fmt,...)
Definition: curses.h:648
#define COLS
Definition: curses.h:111
uint32_t len
Length.
Definition: ena.h:14
int ssize_t const char * fmt
Definition: vsprintf.h:72
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
Write a formatted string to a buffer.
Definition: vsprintf.c:351

References COLS, fmt, len, mvprintw, and vsnprintf().

Referenced by msg(), and valert().

◆ msg()

static void msg ( unsigned int  row,
const char *  fmt,
  ... 
)
static

Print message centred on specified row.

Parameters
rowRow
fmtprintf() format string
..printf() arguments

Definition at line 285 of file settings_ui.c.

285  {
286  va_list args;
287 
288  va_start ( args, fmt );
289  vmsg ( row, fmt, args );
290  va_end ( args );
291 }
#define va_end(ap)
Definition: stdarg.h:9
static void vmsg(unsigned int row, const char *fmt, va_list args)
Print message centred on specified row.
Definition: settings_ui.c:270
__builtin_va_list va_list
Definition: stdarg.h:6
int ssize_t const char * fmt
Definition: vsprintf.h:72
#define va_start(ap, last)
Definition: stdarg.h:7

References fmt, va_end, va_start, and vmsg().

Referenced by ccmp_kie_decrypt(), ccmp_kie_mic(), draw_info_row(), draw_instruction_row(), draw_title_row(), hv_post_message(), hv_wait_for_message(), igbvf_read_mbx_vf(), igbvf_read_posted_mbx(), igbvf_write_mbx_vf(), igbvf_write_posted_mbx(), intelvf_mbox_msg(), intelvf_mbox_poll(), intelvf_mbox_read(), intelvf_mbox_reset(), intelvf_mbox_set_mac(), intelvf_mbox_set_mtu(), intelvf_mbox_write(), intelxvf_mbox_queues(), intelxvf_mbox_version(), netvsc_establish_buffer(), netvsc_initialise(), netvsc_ndis_version(), netvsc_recv_data(), netvsc_revoke_buffer(), netvsc_transmit(), ntlm_data_okx(), peerblk_parse_block(), peerblk_parse_header(), peerblk_parse_iv(), peerblk_parse_useless(), peerblk_retrieval_open(), reg_delay(), rndis_rx_data(), rndis_rx_status(), rndis_tx_data(), rndis_tx_defer(), rndis_tx_halt(), rndis_tx_initialise(), rndis_tx_oid(), sis190_phy_task(), tkip_kie_decrypt(), tkip_kie_mic(), usbio_config(), usbio_control_poll(), xcm_deliver(), xenstore_request(), xenstore_response(), xsmp_chassis_name(), xsmp_rx_session(), xsmp_rx_session_confirm(), xsmp_rx_session_reject(), xsmp_rx_session_shutdown(), xsmp_rx_xve(), xsmp_rx_xve_delete(), xsmp_rx_xve_install(), xsmp_rx_xve_modify(), xsmp_rx_xve_oper_req(), xsmp_rx_xve_ready(), xsmp_rx_xve_update(), xsmp_session_name(), xsmp_tx_session(), xsmp_tx_xve(), xsmp_tx_xve_nack(), xsmp_tx_xve_notify(), and xsmp_tx_xve_params().

◆ clearmsg()

static void clearmsg ( unsigned int  row)
static

Clear message on specified row.

Parameters
rowRow

Definition at line 298 of file settings_ui.c.

298  {
299  move ( row, 0 );
300  clrtoeol();
301 }
static int clrtoeol(void)
Definition: curses.h:553
static int move(int y, int x)
Definition: curses.h:593

References clrtoeol(), and move().

Referenced by draw_info_row(), draw_instruction_row(), draw_setting_rows(), draw_title_row(), and valert().

◆ valert()

static void valert ( const char *  fmt,
va_list  args 
)
static

Print alert message.

Parameters
fmtprintf() format string
argsprintf() argument list

Definition at line 309 of file settings_ui.c.

309  {
310  clearmsg ( ALERT_ROW );
312  vmsg ( ALERT_ROW, fmt, args );
313  sleep ( 2 );
315  clearmsg ( ALERT_ROW );
316 }
static void clearmsg(unsigned int row)
Clear message on specified row.
Definition: settings_ui.c:298
#define CPAIR_NORMAL
Normal text.
Definition: ansicol.h:40
#define CPAIR_ALERT
Error text.
Definition: ansicol.h:52
#define ALERT_ROW
Definition: settings_ui.c:52
static void vmsg(unsigned int row, const char *fmt, va_list args)
Print message centred on specified row.
Definition: settings_ui.c:270
int ssize_t const char * fmt
Definition: vsprintf.h:72
#define color_set(cpno, opts)
Definition: curses.h:240
unsigned int sleep(unsigned int secs)
Sleep (interruptibly) for a fixed number of seconds.
Definition: timer.c:133
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References ALERT_ROW, clearmsg(), color_set, CPAIR_ALERT, CPAIR_NORMAL, fmt, NULL, sleep(), and vmsg().

Referenced by alert().

◆ alert()

static void alert ( const char *  fmt,
  ... 
)
static

Print alert message.

Parameters
fmtprintf() format string
...printf() arguments

Definition at line 324 of file settings_ui.c.

324  {
325  va_list args;
326 
327  va_start ( args, fmt );
328  valert ( fmt, args );
329  va_end ( args );
330 }
#define va_end(ap)
Definition: stdarg.h:9
static void valert(const char *fmt, va_list args)
Print alert message.
Definition: settings_ui.c:309
__builtin_va_list va_list
Definition: stdarg.h:6
int ssize_t const char * fmt
Definition: vsprintf.h:72
#define va_start(ap, last)
Definition: stdarg.h:7

References fmt, va_end, va_start, and valert().

Referenced by main_loop(), and tls_new_alert().

◆ draw_title_row()

static void draw_title_row ( struct settings_ui ui)
static

Draw title row.

Parameters
uiSettings UI

Definition at line 337 of file settings_ui.c.

337  {
338  const char *name;
339 
340  clearmsg ( TITLE_ROW );
341  name = settings_name ( ui->settings );
342  attron ( A_BOLD );
343  msg ( TITLE_ROW, PRODUCT_SHORT_NAME " configuration settings%s%s",
344  ( name[0] ? " - " : "" ), name );
345  attroff ( A_BOLD );
346 }
const char * name
Definition: ath9k_hw.c:1984
#define PRODUCT_SHORT_NAME
Definition: branding.h:28
static int attroff(int attrs)
Definition: curses.h:508
static void clearmsg(unsigned int row)
Clear message on specified row.
Definition: settings_ui.c:298
const char * settings_name(struct settings *settings)
Return settings block name.
Definition: settings.c:345
#define TITLE_ROW
Definition: settings_ui.c:47
struct settings * settings
Settings block.
Definition: settings_ui.c:102
#define A_BOLD
Definition: curses.h:138
static int attron(int attrs)
Definition: curses.h:512
static void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: settings_ui.c:285

References A_BOLD, attroff(), attron(), clearmsg(), msg(), name, PRODUCT_SHORT_NAME, settings_ui::settings, settings_name(), and TITLE_ROW.

Referenced by select_settings().

◆ draw_info_row()

static void draw_info_row ( struct settings_ui ui)
static

Draw information row.

Parameters
uiSettings UI

Definition at line 353 of file settings_ui.c.

353  {
354  char buf[32];
355 
356  /* Draw nothing unless this row represents a setting */
357  clearmsg ( INFO_ROW );
358  clearmsg ( INFO_ROW + 1 );
359  if ( ! ui->row.setting.name )
360  return;
361 
362  /* Determine a suitable setting name */
363  setting_name ( ( ui->row.origin ?
364  ui->row.origin : ui->settings ),
365  &ui->row.setting, buf, sizeof ( buf ) );
366 
367  /* Draw row */
368  attron ( A_BOLD );
369  msg ( INFO_ROW, "%s - %s", buf, ui->row.setting.description );
370  attroff ( A_BOLD );
371  color_set ( CPAIR_URL, NULL );
372  msg ( ( INFO_ROW + 1 ), PRODUCT_SETTING_URI, ui->row.setting.name );
374 }
static int attroff(int attrs)
Definition: curses.h:508
struct settings_ui_row row
Current row.
Definition: settings_ui.c:106
static void clearmsg(unsigned int row)
Clear message on specified row.
Definition: settings_ui.c:298
const char * description
Description.
Definition: settings.h:30
#define CPAIR_NORMAL
Normal text.
Definition: ansicol.h:40
struct settings * origin
Configuration setting origin.
Definition: settings_ui.c:83
const char * name
Name.
Definition: settings.h:28
#define PRODUCT_SETTING_URI
Definition: branding.h:170
#define CPAIR_URL
URL text.
Definition: ansicol.h:55
struct settings * settings
Settings block.
Definition: settings_ui.c:102
#define INFO_ROW
Definition: settings_ui.c:51
struct setting setting
Configuration setting.
Definition: settings_ui.c:88
#define color_set(cpno, opts)
Definition: curses.h:240
#define A_BOLD
Definition: curses.h:138
int setting_name(struct settings *settings, const struct setting *setting, char *buf, size_t len)
Return full setting name.
Definition: settings.c:1610
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
static int attron(int attrs)
Definition: curses.h:512
static void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: settings_ui.c:285

References A_BOLD, attroff(), attron(), clearmsg(), color_set, CPAIR_NORMAL, CPAIR_URL, setting::description, INFO_ROW, msg(), setting::name, NULL, settings_ui_row::origin, PRODUCT_SETTING_URI, settings_ui::row, settings_ui_row::setting, setting_name(), and settings_ui::settings.

Referenced by main_loop().

◆ draw_instruction_row()

static void draw_instruction_row ( struct settings_ui ui)
static

Draw instruction row.

Parameters
uiSettings UI

Definition at line 381 of file settings_ui.c.

381  {
382 
384  if ( ui->row.editing ) {
386  "Enter - accept changes" INSTRUCTION_PAD
387  "Ctrl-C - discard changes" );
388  } else {
390  "%sCtrl-X - exit configuration utility",
391  ( ( ui->row.origin == ui->settings ) ?
392  "Ctrl-D - delete setting" INSTRUCTION_PAD : "" ) );
393  }
394 }
int editing
Editing in progress flag.
Definition: settings_ui.c:94
struct settings_ui_row row
Current row.
Definition: settings_ui.c:106
static void clearmsg(unsigned int row)
Clear message on specified row.
Definition: settings_ui.c:298
struct settings * origin
Configuration setting origin.
Definition: settings_ui.c:83
struct settings * settings
Settings block.
Definition: settings_ui.c:102
#define INSTRUCTION_ROW
Definition: settings_ui.c:53
#define INSTRUCTION_PAD
Definition: settings_ui.c:54
static void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: settings_ui.c:285

References clearmsg(), settings_ui_row::editing, INSTRUCTION_PAD, INSTRUCTION_ROW, msg(), settings_ui_row::origin, settings_ui::row, and settings_ui::settings.

Referenced by main_loop().

◆ draw_setting_rows()

static void draw_setting_rows ( struct settings_ui ui)
static

Draw the current block of setting rows.

Parameters
uiSettings UI

Definition at line 401 of file settings_ui.c.

401  {
402  unsigned int i;
403 
404  /* Draw ellipses before and/or after the list as necessary */
406  mvaddstr ( ( SETTINGS_LIST_ROW - 1 ), ( SETTINGS_LIST_COL + 1 ),
407  jump_scroll_is_first ( &ui->scroll ) ? " " : "..." );
409  ( SETTINGS_LIST_COL + 1 ),
410  jump_scroll_is_last ( &ui->scroll ) ? " " : "..." );
412 
413  /* Draw visible settings. */
414  for ( i = 0 ; i < SETTINGS_LIST_ROWS ; i++ ) {
415  if ( ( ui->scroll.first + i ) < ui->scroll.count ) {
416  select_setting_row ( ui, ( ui->scroll.first + i ) );
417  draw_setting_row ( ui );
418  } else {
419  clearmsg ( SETTINGS_LIST_ROW + i );
420  }
421  }
422 }
static void draw_setting_row(struct settings_ui *ui)
Draw setting row.
Definition: settings_ui.c:197
static void clearmsg(unsigned int row)
Clear message on specified row.
Definition: settings_ui.c:298
#define SETTINGS_LIST_ROW
Definition: settings_ui.c:48
static unsigned int select_setting_row(struct settings_ui *ui, unsigned int index)
Select a setting.
Definition: settings_ui.c:116
#define CPAIR_NORMAL
Normal text.
Definition: ansicol.h:40
unsigned int first
First visible item.
Definition: jumpscroll.h:21
unsigned int count
Total number of items.
Definition: jumpscroll.h:17
#define CPAIR_SEPARATOR
Unselectable text (e.g.
Definition: ansicol.h:46
static int jump_scroll_is_last(struct jump_scroller *scroll)
Check if jump scroller is currently on last page.
Definition: jumpscroll.h:41
struct jump_scroller scroll
Jump scroller.
Definition: settings_ui.c:104
static int jump_scroll_is_first(struct jump_scroller *scroll)
Check if jump scroller is currently on first page.
Definition: jumpscroll.h:30
#define SETTINGS_LIST_COL
Definition: settings_ui.c:49
#define color_set(cpno, opts)
Definition: curses.h:240
#define SETTINGS_LIST_ROWS
Definition: settings_ui.c:50
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
static int mvaddstr(int y, int x, const char *str)
Definition: curses.h:617

References clearmsg(), color_set, jump_scroller::count, CPAIR_NORMAL, CPAIR_SEPARATOR, draw_setting_row(), jump_scroller::first, jump_scroll_is_first(), jump_scroll_is_last(), mvaddstr(), NULL, settings_ui::scroll, select_setting_row(), SETTINGS_LIST_COL, SETTINGS_LIST_ROW, and SETTINGS_LIST_ROWS.

Referenced by main_loop(), and select_settings().

◆ select_settings()

static void select_settings ( struct settings_ui ui,
struct settings settings 
)
static

Select settings block.

Parameters
uiSettings UI
settingsSettings block

Definition at line 430 of file settings_ui.c.

431  {
432 
434  ui->scroll.count = select_setting_row ( ui, 0 );
436  ui->scroll.current = 0;
437  ui->scroll.first = 0;
438  draw_title_row ( ui );
439  draw_setting_rows ( ui );
440  select_setting_row ( ui, 0 );
441 }
static unsigned int select_setting_row(struct settings_ui *ui, unsigned int index)
Select a setting.
Definition: settings_ui.c:116
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:552
static void draw_setting_rows(struct settings_ui *ui)
Draw the current block of setting rows.
Definition: settings_ui.c:401
unsigned int first
First visible item.
Definition: jumpscroll.h:21
unsigned int count
Total number of items.
Definition: jumpscroll.h:17
struct settings * settings
Settings block.
Definition: settings_ui.c:102
A settings block.
Definition: settings.h:132
struct jump_scroller scroll
Jump scroller.
Definition: settings_ui.c:104
unsigned int rows
Maximum number of visible rows.
Definition: jumpscroll.h:15
static void draw_title_row(struct settings_ui *ui)
Draw title row.
Definition: settings_ui.c:337
unsigned int current
Currently selected item.
Definition: jumpscroll.h:19
#define SETTINGS_LIST_ROWS
Definition: settings_ui.c:50

References jump_scroller::count, jump_scroller::current, draw_setting_rows(), draw_title_row(), jump_scroller::first, jump_scroller::rows, settings_ui::scroll, select_setting_row(), settings_ui::settings, SETTINGS_LIST_ROWS, and settings_target().

Referenced by main_loop().

◆ main_loop()

static int main_loop ( struct settings settings)
static

Definition at line 443 of file settings_ui.c.

443  {
444  struct settings_ui ui;
445  unsigned int previous;
446  int redraw = 1;
447  int move;
448  int key;
449  int rc;
450 
451  /* Print initial screen content */
453  memset ( &ui, 0, sizeof ( ui ) );
454  select_settings ( &ui, settings );
455 
456  while ( 1 ) {
457 
458  /* Redraw rows if necessary */
459  if ( redraw ) {
460  draw_info_row ( &ui );
461  draw_instruction_row ( &ui );
462  color_set ( ( ui.row.editing ?
464  draw_setting_row ( &ui );
466  curs_set ( ui.row.editing );
467  redraw = 0;
468  }
469 
470  /* Edit setting, if we are currently editing */
471  if ( ui.row.editing ) {
472 
473  /* Sanity check */
474  assert ( ui.row.setting.name != NULL );
475 
476  /* Redraw edit box */
478  draw_editbox ( &ui.row.editbox );
480 
481  /* Process keypress */
482  key = edit_setting ( &ui, getkey ( 0 ) );
483  switch ( key ) {
484  case CR:
485  case LF:
486  if ( ( rc = save_setting ( &ui ) ) != 0 )
487  alert ( " %s ", strerror ( rc ) );
488  /* Fall through */
489  case CTRL_C:
490  select_setting_row ( &ui, ui.scroll.current );
491  redraw = 1;
492  break;
493  default:
494  /* Do nothing */
495  break;
496  }
497 
498  continue;
499  }
500 
501  /* Otherwise, navigate through settings */
502  key = getkey ( 0 );
503  move = jump_scroll_key ( &ui.scroll, key );
504  if ( move ) {
505  previous = ui.scroll.current;
506  jump_scroll_move ( &ui.scroll, move );
507  if ( ui.scroll.current != previous ) {
508  draw_setting_row ( &ui );
509  redraw = 1;
510  if ( jump_scroll ( &ui.scroll ) )
511  draw_setting_rows ( &ui );
512  select_setting_row ( &ui, ui.scroll.current );
513  }
514  continue;
515  }
516 
517  /* Handle non-navigation keys */
518  switch ( key ) {
519  case CTRL_D:
520  if ( ! ui.row.setting.name )
521  break;
522  if ( ( rc = delete_setting ( ui.settings,
523  &ui.row.setting ) ) != 0 ){
524  alert ( " %s ", strerror ( rc ) );
525  }
526  select_setting_row ( &ui, ui.scroll.current );
527  redraw = 1;
528  break;
529  case CTRL_X:
530  return 0;
531  case CR:
532  case LF:
533  if ( ui.row.settings ) {
534  select_settings ( &ui, ui.row.settings );
535  redraw = 1;
536  }
537  /* Fall through */
538  default:
539  if ( ui.row.setting.name ) {
540  edit_setting ( &ui, key );
541  redraw = 1;
542  }
543  break;
544  }
545  }
546 }
int getkey(unsigned long timeout)
Get single keypress.
Definition: getkey.c:71
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void draw_setting_row(struct settings_ui *ui)
Draw setting row.
Definition: settings_ui.c:197
#define CPAIR_EDIT
Editable text.
Definition: ansicol.h:49
A settings user interface.
Definition: settings_ui.c:100
static int delete_setting(struct settings *settings, const struct setting *setting)
Delete setting.
Definition: settings.h:526
static void draw_instruction_row(struct settings_ui *ui)
Draw instruction row.
Definition: settings_ui.c:381
static unsigned int select_setting_row(struct settings_ui *ui, unsigned int index)
Select a setting.
Definition: settings_ui.c:116
#define CPAIR_NORMAL
Normal text.
Definition: ansicol.h:40
#define CTRL_X
Definition: keys.h:41
static int save_setting(struct settings_ui *ui)
Save setting ui value back to configuration settings.
Definition: settings_ui.c:258
static void draw_setting_rows(struct settings_ui *ui)
Draw the current block of setting rows.
Definition: settings_ui.c:401
static void draw_info_row(struct settings_ui *ui)
Draw information row.
Definition: settings_ui.c:353
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
int jump_scroll(struct jump_scroller *scroll)
Jump scroll to new page (if applicable)
Definition: jumpscroll.c:119
#define CTRL_C
Definition: keys.h:20
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void select_settings(struct settings_ui *ui, struct settings *settings)
Select settings block.
Definition: settings_ui.c:430
A settings block.
Definition: settings.h:132
#define LF
Definition: keys.h:47
void draw_editbox(struct edit_box *box)
Draw text box widget.
Definition: editbox.c:69
int curs_set(int visibility)
Set cursor visibility.
Definition: mucurses.c:153
static void alert(const char *fmt,...)
Print alert message.
Definition: settings_ui.c:324
static int move(int y, int x)
Definition: curses.h:593
#define CPAIR_SELECT
Highlighted text.
Definition: ansicol.h:43
int jump_scroll_key(struct jump_scroller *scroll, int key)
Jump scrolling.
Definition: jumpscroll.c:42
#define CR
Definition: keys.h:48
#define color_set(cpno, opts)
Definition: curses.h:240
#define CTRL_D
Definition: keys.h:21
static int edit_setting(struct settings_ui *ui, int key)
Edit setting ui.
Definition: settings_ui.c:247
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
union @375 key
Sense key.
Definition: scsi.h:18
int jump_scroll_move(struct jump_scroller *scroll, int move)
Move scroller.
Definition: jumpscroll.c:78
void * memset(void *dest, int character, size_t len) __nonnull

References alert(), assert(), color_set, CPAIR_EDIT, CPAIR_NORMAL, CPAIR_SELECT, CR, CTRL_C, CTRL_D, CTRL_X, jump_scroller::current, curs_set(), delete_setting(), draw_editbox(), draw_info_row(), draw_instruction_row(), draw_setting_row(), draw_setting_rows(), edit_setting(), settings_ui_row::editbox, settings_ui_row::editing, getkey(), jump_scroll(), jump_scroll_key(), jump_scroll_move(), key, LF, memset(), move(), setting::name, NULL, rc, settings_ui::row, save_setting(), settings_ui::scroll, select_setting_row(), select_settings(), settings_ui_row::setting, settings_ui_row::settings, settings_ui::settings, and strerror().

Referenced by settings_ui().

◆ settings_ui()

int settings_ui ( struct settings settings)

Definition at line 548 of file settings_ui.c.

548  {
549  int rc;
550 
551  initscr();
552  start_color();
554  curs_set ( 0 );
555  erase();
556 
557  rc = main_loop ( settings );
558 
559  endwin();
560 
561  return rc;
562 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int erase(void)
Completely clear the screen.
Definition: clear.c:97
static int main_loop(struct settings *settings)
Definition: settings_ui.c:443
#define start_color()
Definition: curses.h:396
int endwin(void)
Finalise console environment.
Definition: wininit.c:31
#define CPAIR_NORMAL
Normal text.
Definition: ansicol.h:40
WINDOW * initscr(void)
Initialise console environment.
Definition: wininit.c:17
A settings block.
Definition: settings.h:132
int curs_set(int visibility)
Set cursor visibility.
Definition: mucurses.c:153
#define color_set(cpno, opts)
Definition: curses.h:240
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References color_set, CPAIR_NORMAL, curs_set(), endwin(), erase(), initscr(), main_loop(), NULL, rc, and start_color.