]> git.ozlabs.org Git - petitboot/blob - ui/ncurses/nc-scr.h
0658dd06139844bf2c90887d4b21a25f28d5767c
[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 #include <ncurses.h>
24
25 #ifdef DEBUG
26 #define DBG(fmt, args...) pb_log("DBG: " fmt, ## args)
27 #define DBGS(fmt, args...) \
28         pb_log("DBG:%s:%d: " fmt, __func__, __LINE__, ## args)
29 #else
30 #define DBG(fmt, args...)
31 #define DBGS(fmt, args...)
32 #endif
33
34
35 enum pb_nc_sig {
36         pb_cui_sig         = 111,
37         pb_pmenu_sig       = 222,
38         pb_item_sig        = 333,
39         pb_boot_editor_sig = 444,
40         pb_removed_sig     = -555,
41 };
42
43 void nc_start(void);
44 void nc_atexit(void);
45
46 static inline void nc_flush_keys(void)
47 {
48         while (getch() != ERR)
49                 (void)0;
50 }
51
52 enum nc_scr_pos {
53         nc_scr_pos_title = 0,
54         nc_scr_pos_title_sep = 1,
55         nc_scr_pos_sub = 2,
56
57         nc_scr_pos_help_sep = 3,
58         nc_scr_pos_help = 2,
59         nc_scr_pos_status = 1,
60
61         nc_scr_frame_lines = 5,
62 };
63
64 struct nc_frame {
65         char *title;
66         char *help;
67         char *status;
68 };
69
70 struct nc_scr {
71         enum pb_nc_sig sig;
72         struct nc_frame frame;
73         WINDOW *main_ncw;
74         WINDOW *sub_ncw;
75         void *ui_ctx;
76         int (*post)(struct nc_scr *scr);
77         int (*unpost)(struct nc_scr *scr);
78         void (*process_key)(struct nc_scr *scr);
79         void (*resize)(struct nc_scr *scr);
80 };
81
82 int nc_scr_init(struct nc_scr *scr, enum pb_nc_sig sig, int begin_x,
83         void *ui_ctx,
84         void (*process_key)(struct nc_scr *),
85         int (*post)(struct nc_scr *),
86         int (*unpost)(struct nc_scr *),
87         void (*resize)(struct nc_scr *));
88 void nc_scr_status_free(struct nc_scr *scr);
89 void nc_scr_status_printf(struct nc_scr *scr, const char *format, ...);
90 void nc_scr_frame_draw(struct nc_scr *scr);
91
92 #endif