mirror of https://github.com/ipxe/ipxe.git
[hci] Remove the generalised widget user interface abstraction
Remove the now-unused generalised text widget user interface, along with the associated concept of a widget set and the implementation of a read-only label widget. Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/1243/head
parent
162cc51b6d
commit
821bb326f8
|
@ -1,74 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2024 Michael Brown <mbrown@fensystems.co.uk>.
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2 of the
|
|
||||||
* License, or any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
||||||
* 02110-1301, USA.
|
|
||||||
*
|
|
||||||
* You can also choose to distribute this program under the terms of
|
|
||||||
* the Unmodified Binary Distribution Licence (as given in the file
|
|
||||||
* COPYING.UBDL), provided that you have satisfied its requirements.
|
|
||||||
*/
|
|
||||||
|
|
||||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <ipxe/label.h>
|
|
||||||
|
|
||||||
/** @file
|
|
||||||
*
|
|
||||||
* Text label widget
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Draw text label widget
|
|
||||||
*
|
|
||||||
* @v widget Text widget
|
|
||||||
*/
|
|
||||||
static void draw_label ( struct widget *widget ) {
|
|
||||||
struct label *label = container_of ( widget, struct label, widget );
|
|
||||||
unsigned int width = widget->width;
|
|
||||||
unsigned int col = widget->col;
|
|
||||||
const char *text = label->text;
|
|
||||||
|
|
||||||
/* Centre label if width is non-zero */
|
|
||||||
if ( width )
|
|
||||||
col += ( ( width - strlen ( text ) ) / 2 );
|
|
||||||
|
|
||||||
/* Print label content */
|
|
||||||
attron ( A_BOLD );
|
|
||||||
mvprintw ( widget->row, col, "%s", text );
|
|
||||||
attroff ( A_BOLD );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Edit text label widget
|
|
||||||
*
|
|
||||||
* @v widget Text widget
|
|
||||||
* @v key Key pressed by user
|
|
||||||
* @ret key Key returned to application, or zero
|
|
||||||
*/
|
|
||||||
static int edit_label ( struct widget *widget __unused, int key ) {
|
|
||||||
|
|
||||||
/* Cannot be edited */
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Text label widget operations */
|
|
||||||
struct widget_operations label_operations = {
|
|
||||||
.draw = draw_label,
|
|
||||||
.edit = edit_label,
|
|
||||||
};
|
|
|
@ -109,8 +109,6 @@ struct settings_ui {
|
||||||
struct jump_scroller scroll;
|
struct jump_scroller scroll;
|
||||||
/** Current row */
|
/** Current row */
|
||||||
struct settings_ui_row row;
|
struct settings_ui_row row;
|
||||||
/** Widget set used for editing setting */
|
|
||||||
struct widgets widgets;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -389,7 +387,6 @@ static int main_loop ( struct settings *settings ) {
|
||||||
/* Print initial screen content */
|
/* Print initial screen content */
|
||||||
color_set ( CPAIR_NORMAL, NULL );
|
color_set ( CPAIR_NORMAL, NULL );
|
||||||
memset ( &ui, 0, sizeof ( ui ) );
|
memset ( &ui, 0, sizeof ( ui ) );
|
||||||
init_widgets ( &ui.widgets );
|
|
||||||
select_settings ( &ui, settings );
|
select_settings ( &ui, settings );
|
||||||
|
|
||||||
while ( 1 ) {
|
while ( 1 ) {
|
||||||
|
|
|
@ -1,143 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2024 Michael Brown <mbrown@fensystems.co.uk>.
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2 of the
|
|
||||||
* License, or any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
||||||
* 02110-1301, USA.
|
|
||||||
*
|
|
||||||
* You can also choose to distribute this program under the terms of
|
|
||||||
* the Unmodified Binary Distribution Licence (as given in the file
|
|
||||||
* COPYING.UBDL), provided that you have satisfied its requirements.
|
|
||||||
*/
|
|
||||||
|
|
||||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|
||||||
|
|
||||||
/** @file
|
|
||||||
*
|
|
||||||
* Text widget UI
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <curses.h>
|
|
||||||
#include <ipxe/ansicol.h>
|
|
||||||
#include <ipxe/widget.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find editable widget in widget set
|
|
||||||
*
|
|
||||||
* @v widgets Text widget set
|
|
||||||
* @v index Editable widget index
|
|
||||||
* @ret widget Editable widget, or NULL
|
|
||||||
*/
|
|
||||||
static struct widget * find_widget ( struct widgets *widgets,
|
|
||||||
unsigned int index ) {
|
|
||||||
struct widget *widget;
|
|
||||||
|
|
||||||
list_for_each_entry ( widget, &widgets->list, list ) {
|
|
||||||
if ( ! ( widget->flags & WIDGET_EDITABLE ) )
|
|
||||||
continue;
|
|
||||||
if ( index-- == 0 )
|
|
||||||
return widget;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Text widget user interface main loop
|
|
||||||
*
|
|
||||||
* @v widgets Text widget set
|
|
||||||
* @ret rc Return status code
|
|
||||||
*/
|
|
||||||
static int widget_ui_loop ( struct widgets *widgets ) {
|
|
||||||
struct widget *widget;
|
|
||||||
unsigned int current;
|
|
||||||
unsigned int count;
|
|
||||||
int key;
|
|
||||||
|
|
||||||
/* Draw all widgets */
|
|
||||||
list_for_each_entry ( widget, &widgets->list, list )
|
|
||||||
draw_widget ( widget );
|
|
||||||
|
|
||||||
/* Count editable widgets */
|
|
||||||
count = 0;
|
|
||||||
while ( find_widget ( widgets, count ) != NULL )
|
|
||||||
count++;
|
|
||||||
|
|
||||||
/* Main loop */
|
|
||||||
current = 0;
|
|
||||||
while ( 1 ) {
|
|
||||||
|
|
||||||
/* Identify current widget */
|
|
||||||
widget = find_widget ( widgets, current );
|
|
||||||
if ( ! widget )
|
|
||||||
return -ENOENT;
|
|
||||||
|
|
||||||
/* Redraw current widget */
|
|
||||||
draw_widget ( widget );
|
|
||||||
|
|
||||||
/* Process keypress */
|
|
||||||
key = edit_widget ( widget, getkey ( 0 ) );
|
|
||||||
switch ( key ) {
|
|
||||||
case KEY_UP:
|
|
||||||
if ( current > 0 )
|
|
||||||
current--;
|
|
||||||
break;
|
|
||||||
case KEY_DOWN:
|
|
||||||
if ( ++current == count )
|
|
||||||
current--;
|
|
||||||
break;
|
|
||||||
case TAB:
|
|
||||||
if ( ++current == count )
|
|
||||||
current = 0;
|
|
||||||
break;
|
|
||||||
case KEY_ENTER:
|
|
||||||
current++;
|
|
||||||
if ( current >= count )
|
|
||||||
return 0;
|
|
||||||
break;
|
|
||||||
case CTRL_C:
|
|
||||||
case ESC:
|
|
||||||
return -ECANCELED;
|
|
||||||
default:
|
|
||||||
/* Do nothing for unrecognised keys or edit errors */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Present text widget user interface
|
|
||||||
*
|
|
||||||
* @v widgets Text widget set
|
|
||||||
* @ret rc Return status code
|
|
||||||
*/
|
|
||||||
int widget_ui ( struct widgets *widgets ) {
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
/* Initialise UI */
|
|
||||||
initscr();
|
|
||||||
start_color();
|
|
||||||
color_set ( CPAIR_NORMAL, NULL );
|
|
||||||
erase();
|
|
||||||
|
|
||||||
/* Run main loop */
|
|
||||||
rc = widget_ui_loop ( widgets );
|
|
||||||
|
|
||||||
/* Terminate UI */
|
|
||||||
color_set ( CPAIR_NORMAL, NULL );
|
|
||||||
endwin();
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
|
|
@ -10,18 +10,9 @@
|
||||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||||
|
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <ipxe/list.h>
|
|
||||||
|
|
||||||
/** A text widget set */
|
|
||||||
struct widgets {
|
|
||||||
/** List of widgets (in tab order) */
|
|
||||||
struct list_head list;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** A text widget */
|
/** A text widget */
|
||||||
struct widget {
|
struct widget {
|
||||||
/** List of widgets (in tab order) */
|
|
||||||
struct list_head list;
|
|
||||||
/** Widget operations */
|
/** Widget operations */
|
||||||
struct widget_operations *op;
|
struct widget_operations *op;
|
||||||
|
|
||||||
|
@ -65,17 +56,6 @@ struct widget_operations {
|
||||||
int ( * edit ) ( struct widget *widget, int key );
|
int ( * edit ) ( struct widget *widget, int key );
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialise text widget set
|
|
||||||
*
|
|
||||||
* @v widgets Text widget set
|
|
||||||
*/
|
|
||||||
static inline __attribute__ (( always_inline )) void
|
|
||||||
init_widgets ( struct widgets *widgets ) {
|
|
||||||
|
|
||||||
INIT_LIST_HEAD ( &widgets->list );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise text widget
|
* Initialise text widget
|
||||||
*
|
*
|
||||||
|
@ -97,18 +77,6 @@ init_widget ( struct widget *widget, struct widget_operations *op,
|
||||||
widget->flags = flags;
|
widget->flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Append text widget
|
|
||||||
*
|
|
||||||
* @v widgets Text widget set
|
|
||||||
* @v widget Text widget
|
|
||||||
*/
|
|
||||||
static inline __attribute__ (( always_inline )) void
|
|
||||||
add_widget ( struct widgets *widgets, struct widget *widget ) {
|
|
||||||
|
|
||||||
list_add_tail ( &widget->list, &widgets->list );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw text widget
|
* Draw text widget
|
||||||
*
|
*
|
||||||
|
@ -137,6 +105,4 @@ edit_widget ( struct widget *widget, int key ) {
|
||||||
return widget->op->edit ( widget, key );
|
return widget->op->edit ( widget, key );
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int widget_ui ( struct widgets *widgets );
|
|
||||||
|
|
||||||
#endif /* _IPXE_WIDGET_H */
|
#endif /* _IPXE_WIDGET_H */
|
||||||
|
|
Loading…
Reference in New Issue