iPXE
editbox.c File Reference

Editable text box widget. More...

#include <string.h>
#include <assert.h>
#include <ipxe/ansicol.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)
 FILE_SECBOOT (PERMITTED)
static void draw_editbox (struct widget *widget)
 Draw text box widget.
static int edit_editbox (struct widget *widget, int key)
 Edit text box widget.

Variables

struct widget_operations editbox_operations
 Text box widget operations.

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 38 of file editbox.c.

Referenced by draw_editbox().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ draw_editbox()

void draw_editbox ( struct widget * widget)
static

Draw text box widget.

Parameters
widgetText widget

Definition at line 45 of file editbox.c.

45 {
46 struct edit_box *box = container_of ( widget, struct edit_box, widget );
47 const char *content = *(box->string.buf);
48 size_t width = widget->width;
49 char buf[ width + 1 ];
50 signed int cursor_offset, underflow, overflow, first;
51 size_t len;
52
53 /* Adjust starting offset so that cursor remains within box */
54 cursor_offset = ( box->string.cursor - box->first );
55 underflow = ( EDITBOX_MIN_CHARS - cursor_offset );
56 overflow = ( cursor_offset - ( width - 1 ) );
57 first = box->first;
58 if ( underflow > 0 ) {
59 first -= underflow;
60 if ( first < 0 )
61 first = 0;
62 } else if ( overflow > 0 ) {
63 first += overflow;
64 }
65 box->first = first;
66 cursor_offset = ( box->string.cursor - first );
67
68 /* Construct underscore-padded string portion */
69 memset ( buf, '_', width );
70 buf[width] = '\0';
71 len = ( content ? ( strlen ( content ) - first ) : 0 );
72 if ( len > width )
73 len = width;
74 if ( widget->flags & WIDGET_SECRET ) {
75 memset ( buf, '*', len );
76 } else {
77 memcpy ( buf, ( content + first ), len );
78 }
79
80 /* Print box content and move cursor */
82 mvprintw ( widget->row, widget->col, "%s", buf );
83 move ( widget->row, ( widget->col + cursor_offset ) );
85}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
#define mvprintw(y, x, fmt,...)
Definition curses.h:649
static int move(int y, int x)
Definition curses.h:594
#define color_set(cpno, opts)
Definition curses.h:241
ring len
Length.
Definition dwmac.h:226
int box(WINDOW *win, chtype verch, chtype horch)
Draw borders from single-byte characters and renditions around a window.
Definition edging.c:22
#define EDITBOX_MIN_CHARS
Definition editbox.c:38
#define CPAIR_EDIT
Editable text.
Definition ansicol.h:50
#define CPAIR_NORMAL
Normal text.
Definition ansicol.h:41
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
uint32_t first
First block in range.
Definition pccrr.h:1
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
size_t strlen(const char *src)
Get length of string.
Definition string.c:244
An editable text box widget.
Definition editbox.h:18
A text widget.
Definition widget.h:16
unsigned int col
Starting column.
Definition widget.h:23
unsigned int width
Width.
Definition widget.h:25
unsigned int flags
Flags.
Definition widget.h:27
unsigned int row
Row.
Definition widget.h:21
@ WIDGET_SECRET
Widget contains a secret.
Definition widget.h:35

References box(), widget::col, color_set, container_of, CPAIR_EDIT, CPAIR_NORMAL, EDITBOX_MIN_CHARS, first, widget::flags, len, memcpy(), memset(), move(), mvprintw, NULL, widget::row, strlen(), WIDGET_SECRET, and widget::width.

◆ edit_editbox()

int edit_editbox ( struct widget * widget,
int key )
static

Edit text box widget.

Parameters
widgetText widget
keyKey pressed by user
Return values
keyKey returned to application, or zero

Definition at line 94 of file editbox.c.

94 {
95 struct edit_box *box = container_of ( widget, struct edit_box, widget );
96
97 return edit_string ( &box->string, key );
98}
union @162305117151260234136356364136041353210355154177 key
Sense key.
Definition scsi.h:3
int edit_string(struct edit_string *string, int key)
Edit editable string.
Definition editstring.c:256

References box(), container_of, edit_string(), and key.

Variable Documentation

◆ editbox_operations

struct widget_operations editbox_operations
Initial value:
= {
.draw = draw_editbox,
.edit = edit_editbox,
}
static void draw_editbox(struct widget *widget)
Draw text box widget.
Definition editbox.c:45
static int edit_editbox(struct widget *widget, int key)
Edit text box widget.
Definition editbox.c:94

Text box widget operations.

Definition at line 101 of file editbox.c.

101 {
102 .draw = draw_editbox,
103 .edit = edit_editbox,
104};

Referenced by init_editbox().