iPXE
Macros | Functions
editbox.c File Reference

Editable text box widget. More...

#include <string.h>
#include <assert.h>
#include <ipxe/editbox.h>

Go to the source code of this file.

Macros

#define EDITBOX_MIN_CHARS   3
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
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. More...
 
void draw_editbox (struct edit_box *box)
 Draw text box widget. More...
 

Detailed Description

Editable text box widget.

Definition in file editbox.c.

Macro Definition Documentation

◆ EDITBOX_MIN_CHARS

#define EDITBOX_MIN_CHARS   3

Definition at line 36 of file editbox.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ init_editbox()

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.

Parameters
boxEditable text box widget
bufText buffer
lenSize of text buffer
winContaining window
rowRow
colStarting column
widthWidth
flagsFlags

Definition at line 50 of file editbox.c.

52  {
53  memset ( box, 0, sizeof ( *box ) );
54  init_editstring ( &box->string, buf, len );
55  box->string.cursor = strlen ( buf );
56  box->win = ( win ? win : stdscr );
57  box->row = row;
58  box->col = col;
59  box->width = width;
60  box->flags = flags;
61 }
int box(WINDOW *win, chtype verch, chtype horch)
Draw borders from single-byte characters and renditions around a window.
Definition: edging.c:22
static void init_editstring(struct edit_string *string, char *buf, size_t len)
Initialise editable string.
Definition: editstring.h:38
#define stdscr
Definition: curses.h:110
size_t strlen(const char *src)
Get length of string.
Definition: string.c:228
uint32_t len
Length.
Definition: ena.h:14
void * memset(void *dest, int character, size_t len) __nonnull
uint8_t flags
Flags.
Definition: ena.h:18

References box(), flags, init_editstring(), len, memset(), stdscr, and strlen().

Referenced by login_ui(), and select_setting_row().

◆ draw_editbox()

void draw_editbox ( struct edit_box box)

Draw text box widget.

Parameters
boxEditable text box widget

Definition at line 69 of file editbox.c.

69  {
70  size_t width = box->width;
71  char buf[ width + 1 ];
72  signed int cursor_offset, underflow, overflow, first;
73  size_t len;
74 
75  /* Adjust starting offset so that cursor remains within box */
76  cursor_offset = ( box->string.cursor - box->first );
77  underflow = ( EDITBOX_MIN_CHARS - cursor_offset );
78  overflow = ( cursor_offset - ( width - 1 ) );
79  first = box->first;
80  if ( underflow > 0 ) {
81  first -= underflow;
82  if ( first < 0 )
83  first = 0;
84  } else if ( overflow > 0 ) {
85  first += overflow;
86  }
87  box->first = first;
88  cursor_offset = ( box->string.cursor - first );
89 
90  /* Construct underscore-padded string portion */
91  memset ( buf, '_', width );
92  buf[width] = '\0';
93  len = ( strlen ( box->string.buf ) - first );
94  if ( len > width )
95  len = width;
96  if ( box->flags & EDITBOX_STARS ) {
97  memset ( buf, '*', len );
98  } else {
99  memcpy ( buf, ( box->string.buf + first ), len );
100  }
101 
102  /* Print box content and move cursor */
103  if ( ! box->win )
104  box->win = stdscr;
105  mvwprintw ( box->win, box->row, box->col, "%s", buf );
106  wmove ( box->win, box->row, ( box->col + cursor_offset ) );
107 }
int wmove(WINDOW *win, int y, int x) __nonnull
Move a window's cursor to the specified position.
Definition: mucurses.c:135
int box(WINDOW *win, chtype verch, chtype horch)
Draw borders from single-byte characters and renditions around a window.
Definition: edging.c:22
#define mvwprintw(win, y, x, fmt,...)
Definition: curses.h:707
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define stdscr
Definition: curses.h:110
size_t strlen(const char *src)
Get length of string.
Definition: string.c:228
Show stars instead of contents (for password widgets)
Definition: editbox.h:36
uint32_t len
Length.
Definition: ena.h:14
#define EDITBOX_MIN_CHARS
Definition: editbox.c:36
uint32_t first
Length to skip in first segment.
Definition: pccrc.h:23
void * memset(void *dest, int character, size_t len) __nonnull

References box(), EDITBOX_MIN_CHARS, EDITBOX_STARS, first, len, memcpy(), memset(), mvwprintw, stdscr, strlen(), and wmove().

Referenced by login_ui(), and main_loop().