]> git.ozlabs.org Git - petitboot/blob - ui/ncurses/nc-scr.h
discover/device-handler: Treat empty boot order as 'boot any'
[petitboot] / ui / ncurses / nc-scr.h
1 /*
2  *  Copyright (C) 2009 Sony Computer Entertainment Inc.
3  *  Copyright 2009 Sony Corp.
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; version 2 of the License.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #if !defined(_PB_NC_SCR_H)
20 #define _PB_NC_SCR_H
21
22 #include <linux/input.h> /* This must be included before ncurses.h */
23 #if defined HAVE_NCURSESW_CURSES_H
24 #  include <ncursesw/curses.h>
25 #elif defined HAVE_NCURSESW_H
26 #  include <ncursesw.h>
27 #elif defined HAVE_NCURSES_CURSES_H
28 #  include <ncurses/curses.h>
29 #elif defined HAVE_NCURSES_H
30 #  include <ncurses.h>
31 #elif defined HAVE_CURSES_H
32 #  include <curses.h>
33 #else
34 #  error "Curses header file not found."
35 #endif
36
37 #define DBG(fmt, args...) pb_debug("DBG: " fmt, ## args)
38 #define DBGS(fmt, args...) \
39         pb_debug("DBG:%s:%d: " fmt, __func__, __LINE__, ## args)
40
41
42 enum pb_nc_sig {
43         pb_cui_sig              = 111,
44         pb_pmenu_sig            = 222,
45         pb_item_sig             = 333,
46         pb_boot_editor_sig      = 444,
47         pb_text_screen_sig      = 555,
48         pb_config_screen_sig    = 666,
49         pb_lang_screen_sig      = 777,
50         pb_add_url_screen_sig   = 888,
51         pb_subset_screen_sig    = 101,
52         pb_plugin_screen_sig    = 202,
53         pb_removed_sig          = -999,
54 };
55
56 static inline void nc_flush_keys(void)
57 {
58         while (getch() != ERR)
59                 (void)0;
60 }
61
62 enum nc_scr_pos {
63         nc_scr_pos_title = 0,
64         nc_scr_pos_title_sep = 1,
65         nc_scr_pos_lrtitle_space = 2,
66         nc_scr_pos_sub = 2,
67
68         nc_scr_pos_help_sep = 3,
69         nc_scr_pos_help = 2,
70         nc_scr_pos_status = 1,
71
72         nc_scr_frame_lines = 5,
73         nc_scr_frame_cols = 1,
74 };
75
76 struct nc_frame {
77         char *ltitle;
78         char *rtitle;
79         char *help;
80         char *status;
81 };
82
83 struct nc_scr {
84         enum pb_nc_sig sig;
85         struct nc_frame frame;
86         WINDOW *main_ncw;
87         WINDOW *sub_ncw;
88         void *ui_ctx;
89         int (*post)(struct nc_scr *scr);
90         int (*unpost)(struct nc_scr *scr);
91         void (*process_key)(struct nc_scr *scr, int key);
92         void (*resize)(struct nc_scr *scr);
93 };
94
95 int nc_scr_init(struct nc_scr *scr, enum pb_nc_sig sig, int begin_x,
96         void *ui_ctx,
97         void (*process_key)(struct nc_scr *, int),
98         int (*post)(struct nc_scr *),
99         int (*unpost)(struct nc_scr *),
100         void (*resize)(struct nc_scr *));
101 void nc_scr_status_free(struct nc_scr *scr);
102 void nc_scr_status_printf(struct nc_scr *scr, const char *format, ...);
103 void nc_scr_frame_draw(struct nc_scr *scr);
104
105 int nc_scr_post(struct nc_scr *src);
106 int nc_scr_unpost(struct nc_scr *src);
107
108 #endif