iPXE
Macros | Functions | Variables
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)
 
static void draw_editbox (struct widget *widget)
 Draw text box widget. More...
 
static int edit_editbox (struct widget *widget, int key)
 Edit text box widget. More...
 

Variables

struct widget_operations editbox_operations
 Text box widget operations. 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 37 of file editbox.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ draw_editbox()

static void draw_editbox ( struct widget widget)
static

Draw text box widget.

Parameters
widgetText widget

Definition at line 44 of file editbox.c.

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

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()

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

93  {
94  struct edit_box *box = container_of ( widget, struct edit_box, widget );
95 
96  return edit_string ( &box->string, key );
97 }
int box(WINDOW *win, chtype verch, chtype horch)
Draw borders from single-byte characters and renditions around a window.
Definition: edging.c:22
int edit_string(struct edit_string *string, int key)
Edit editable string.
Definition: editstring.c:255
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
An editable text box widget.
Definition: editbox.h:17
A text widget.
Definition: widget.h:15
union @383 key
Sense key.
Definition: scsi.h:18

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:44
static int edit_editbox(struct widget *widget, int key)
Edit text box widget.
Definition: editbox.c:93

Text box widget operations.

Definition at line 100 of file editbox.c.

Referenced by init_editbox().