2 * Copyright (C) 2009 Sony Computer Entertainment Inc.
3 * Copyright 2009 Sony Corp.
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.
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.
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
23 #include "talloc/talloc.h"
29 initscr(); /* Initialize ncurses. */
30 cbreak(); /* Disable line buffering. */
31 noecho(); /* Disable getch() echo. */
32 keypad(stdscr, TRUE); /* Enable num keypad keys. */
33 nonl(); /* Disable new-line translation. */
34 intrflush(stdscr, FALSE); /* Disable interrupt flush. */
35 curs_set(0); /* Make cursor invisible */
36 nodelay(stdscr, TRUE); /* Enable non-blocking getch() */
37 while (getch() != ERR) /* flush stdin */
48 static void nc_scr_status_clear(struct nc_scr *scr)
50 mvwhline(scr->main_ncw, LINES - nc_scr_pos_status, 0, ' ', COLS);
53 static void nc_scr_status_draw(struct nc_scr *scr)
55 mvwaddstr(scr->main_ncw, LINES - nc_scr_pos_status, 1,
59 void nc_scr_frame_draw(struct nc_scr *scr)
61 DBGS("title '%s'\n", scr->frame.title);
62 DBGS("help '%s'\n", scr->frame.help);
63 DBGS("status '%s'\n", scr->frame.status);
65 mvwaddstr(scr->main_ncw, nc_scr_pos_title, 1, scr->frame.title);
66 mvwhline(scr->main_ncw, nc_scr_pos_title_sep, 1, ACS_HLINE, COLS - 2);
68 mvwhline(scr->main_ncw, LINES - nc_scr_pos_help_sep, 1, ACS_HLINE,
70 mvwaddstr(scr->main_ncw, LINES - nc_scr_pos_help, 1, scr->frame.help);
71 nc_scr_status_draw(scr);
74 void nc_scr_status_free(struct nc_scr *scr)
76 talloc_free(scr->frame.status);
77 scr->frame.status = NULL;
78 nc_scr_status_clear(scr);
82 * nc_scr_status_printf - Set the text of the scr status using sprintf.
83 * @scr: The scr to opperate on.
84 * @text: The status text.
86 * The caller is reponsible for calling scr_draw() to update the display.
89 void nc_scr_status_printf(struct nc_scr *scr, const char *format, ...)
93 nc_scr_status_free(scr);
96 scr->frame.status = talloc_vasprintf(scr, format, ap);
99 nc_scr_status_draw(scr);
100 wrefresh(scr->main_ncw);
103 int nc_scr_init(struct nc_scr *scr, enum pb_nc_sig sig, int begin_x,
105 void (*process_key)(struct nc_scr *),
106 int (*post)(struct nc_scr *),
107 int (*unpost)(struct nc_scr *),
108 void (*resize)(struct nc_scr *))
111 scr->ui_ctx = ui_ctx;
112 scr->process_key = process_key;
114 scr->unpost = unpost;
115 scr->resize = resize;
117 scr->main_ncw = newwin(LINES, COLS, 0, 0);
119 scr->sub_ncw = derwin(scr->main_ncw,
120 LINES - nc_scr_frame_lines,
125 assert(scr->main_ncw);
126 assert(scr->sub_ncw);
128 return scr->main_ncw && scr->sub_ncw;