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