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
27 #include "talloc/talloc.h"
33 initscr(); /* Initialize ncurses. */
34 cbreak(); /* Disable line buffering. */
35 noecho(); /* Disable getch() echo. */
36 keypad(stdscr, TRUE); /* Enable num keypad keys. */
37 nonl(); /* Disable new-line translation. */
38 intrflush(stdscr, FALSE); /* Disable interrupt flush. */
39 curs_set(0); /* Make cursor invisible */
40 nodelay(stdscr, TRUE); /* Enable non-blocking getch() */
42 /* We may be operating with an incorrect $TERM type; in this case
43 * the keymappings will be slightly broken. We want at least
44 * backspace to work though, so we'll define both DEL and ^H to
46 define_key("\x7f", KEY_BACKSPACE);
47 define_key("\x08", KEY_BACKSPACE);
49 while (getch() != ERR) /* flush stdin */
60 static void nc_scr_status_clear(struct nc_scr *scr)
62 mvwhline(scr->main_ncw, LINES - nc_scr_pos_status, 0, ' ', COLS);
65 static void nc_scr_status_draw(struct nc_scr *scr)
67 mvwaddstr(scr->main_ncw, LINES - nc_scr_pos_status, 1,
71 void nc_scr_frame_draw(struct nc_scr *scr)
73 DBGS("title '%s'\n", scr->frame.title);
74 DBGS("help '%s'\n", scr->frame.help);
75 DBGS("status '%s'\n", scr->frame.status);
77 mvwaddstr(scr->main_ncw, nc_scr_pos_title, 1, scr->frame.title);
78 mvwhline(scr->main_ncw, nc_scr_pos_title_sep, 1, ACS_HLINE, COLS - 2);
80 mvwhline(scr->main_ncw, LINES - nc_scr_pos_help_sep, 1, ACS_HLINE,
82 mvwaddstr(scr->main_ncw, LINES - nc_scr_pos_help, 1, scr->frame.help);
83 nc_scr_status_draw(scr);
86 void nc_scr_status_free(struct nc_scr *scr)
88 talloc_free(scr->frame.status);
89 scr->frame.status = NULL;
90 nc_scr_status_clear(scr);
94 * nc_scr_status_printf - Set the text of the scr status using sprintf.
95 * @scr: The scr to opperate on.
96 * @text: The status text.
98 * The caller is reponsible for calling scr_draw() to update the display.
101 void nc_scr_status_printf(struct nc_scr *scr, const char *format, ...)
105 nc_scr_status_free(scr);
107 va_start(ap, format);
108 scr->frame.status = talloc_vasprintf(scr, format, ap);
111 nc_scr_status_draw(scr);
112 wrefresh(scr->main_ncw);
115 int nc_scr_init(struct nc_scr *scr, enum pb_nc_sig sig, int begin_x,
117 void (*process_key)(struct nc_scr *, int),
118 int (*post)(struct nc_scr *),
119 int (*unpost)(struct nc_scr *),
120 void (*resize)(struct nc_scr *))
123 scr->ui_ctx = ui_ctx;
124 scr->process_key = process_key;
126 scr->unpost = unpost;
127 scr->resize = resize;
129 scr->main_ncw = newwin(LINES, COLS, 0, 0);
131 scr->sub_ncw = derwin(scr->main_ncw,
132 LINES - nc_scr_frame_lines,
137 assert(scr->main_ncw);
138 assert(scr->sub_ncw);
140 return scr->main_ncw && scr->sub_ncw;