Files
lcdproc/server/drivers/curses_drv.c
T

658 lines
16 KiB
C
Raw Normal View History

/* This is the LCDproc driver for ncurses.
It displays an emulated LCD display at top left of terminal screen
using ncurses.
Copyright (C) ?????? ?????????
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 */
/*Configfile support added by Rene Wagner (C) 2001*/
/*
Different implementations of (n)curses available on:
2001-12-30 00:15:25 +00:00
OpenBSD:
http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libcurses/
ncurses
2001-12-30 00:15:25 +00:00
NetBSD:
http://cvsweb.netbsd.org/bsdweb.cgi/basesrc/lib/libcurses/
curses : does not define ACS_S3, ACS_S7, wcolor_set() or redrawwin().
2001-12-30 00:15:25 +00:00
it is possible to make a:
#define ACS_S3 (_acs_char['p'])
#define ACS_S7 (_acs_char['r'])
FreeBSD:
http://www.freebsd.org/cgi/cvsweb.cgi/src/
ncurses
RedHat, Debian, (most distros) Linux:
ncurses
SunOS (5.5.1):
curses : does not define ACS_S3, ACS_S7 or wcolor_set().
2001-12-30 00:15:25 +00:00
it is possible to make a:
#define ACS_S3 (acs_map['p'])
#define ACS_S7 (acs_map['r'])
*/
1999-12-16 09:20:22 +00:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
1999-12-09 23:15:14 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <string.h>
#include <sys/errno.h>
#include <ctype.h>
1999-12-16 09:20:22 +00:00
#ifdef HAVE_NCURSES_H
1999-12-09 23:15:14 +00:00
#include <ncurses.h>
#else
#include <curses.h>
#endif
#include "lcd.h"
#include "curses_drv.h"
2001-12-30 00:15:25 +00:00
#include "report.h"
//#include "configfile.h"
1999-12-09 23:15:14 +00:00
// ACS_S9 and ACS_S1 are defined as part of XSI Curses standard, Issue 4.
// However, ACS_S3 and ACS_S7 are not; these definitions were created to support
// commonly available graphics found in many terminfo definitions. The acsc character
// used for ACS_S3 is 'p'; the acsc character used for ACS_S7 is 'r'.
//
// Other systems may very likely support these characters; however,
// their names were invented for ncurses.
#ifndef ACS_S3
# ifdef CURSES_HAS_ACS_MAP
# define ACS_S3 (acs_map['p'])
# else
# ifdef CURSES_HAS__ACS_CHAR
# define ACS_S3 (_acs_char['p'])
# else
# define ACS_S3 ACS_S1 // Last resort
# endif
2001-12-30 00:15:25 +00:00
# endif
#endif
#ifndef ACS_S7
# ifdef CURSES_HAS_ACS_MAP
# define ACS_S7 (acs_map['r'])
# else
# ifdef CURSES_HAS__ACS_CHAR
# define ACS_S7 (_acs_char['r'])
# else
# define ACS_S7 ACS_S9 // Last resort
# endif
2001-12-30 00:15:25 +00:00
# endif
#endif
2001-09-25 05:10:19 +00:00
// Character used for title bars...
#define PAD '#'
// #define PAD ACS_BLOCK
2006-04-11 10:26:00 +00:00
/* A few different nice pairs of colors to use... */
#define DEFAULT_FOREGROUND_COLOR COLOR_CYAN
#define DEFAULT_BACKGROUND_COLOR COLOR_BLUE
2001-12-30 00:15:25 +00:00
2006-04-11 10:26:00 +00:00
/* What position (X,Y) to start the left top corner at... */
#define TOP_LEFT_X 7
#define TOP_LEFT_Y 7
typedef struct driver_private_data {
WINDOW *win;
2006-04-11 10:26:00 +00:00
int current_color_pair;
int current_border_pair;
int curses_backlight_state;
2006-04-11 10:26:00 +00:00
int width;
int height;
int cellwidth;
int cellheight;
2006-04-11 10:26:00 +00:00
int xoffs;
int yoffs;
int useACS;
} PrivateData;
// Vars for the server core
MODULE_EXPORT char *api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 1;
MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "curses_";
2006-04-11 10:26:00 +00:00
void curses_restore_screen (Driver *drvthis);
1999-12-09 23:15:14 +00:00
//////////////////////////////////////////////////////////////////////////
////////////////////// For Curses Terminal Output ////////////////////////
//////////////////////////////////////////////////////////////////////////
chtype get_color (char *colorstr) {
if (strcasecmp(colorstr, "red") == 0)
return COLOR_RED;
else if (strcasecmp(colorstr, "black") == 0)
return COLOR_BLACK;
else if (strcasecmp(colorstr, "green") == 0)
return COLOR_GREEN;
else if (strcasecmp(colorstr, "yellow") == 0)
return COLOR_YELLOW;
else if (strcasecmp(colorstr, "blue") == 0)
return COLOR_BLUE;
else if (strcasecmp(colorstr, "magenta") == 0)
return COLOR_MAGENTA;
else if (strcasecmp(colorstr, "cyan") == 0)
return COLOR_CYAN;
else if (strcasecmp(colorstr, "white") == 0)
return COLOR_WHITE;
else
return -1;
}
chtype
set_foreground_color (char * buf) {
chtype color;
if ((color = get_color(buf)) < 0)
color = DEFAULT_FOREGROUND_COLOR;
return color;
}
chtype
set_background_color (char * buf) {
chtype color;
if ((color = get_color(buf)) < 0)
color = DEFAULT_BACKGROUND_COLOR;
return color;
}
2002-02-21 22:50:12 +00:00
MODULE_EXPORT int
curses_init (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2006-04-11 10:26:00 +00:00
PrivateData *p;
char buf[256];
2006-04-08 14:49:37 +00:00
int tmp;
1999-12-09 23:15:14 +00:00
2001-09-25 05:10:19 +00:00
// Colors....
chtype back_color = DEFAULT_BACKGROUND_COLOR,
fore_color = DEFAULT_FOREGROUND_COLOR,
backlight_color = DEFAULT_BACKGROUND_COLOR;
2001-09-25 05:10:19 +00:00
// Screen position (top left)
2006-04-11 10:26:00 +00:00
/* Allocate and store private data */
p = (PrivateData *) calloc(1, sizeof(PrivateData));
if (p == NULL)
return -1;
if (drvthis->store_private_ptr(drvthis, p))
return -1;
2006-04-11 10:26:00 +00:00
/* initialize private data */
p->win = NULL;
p->current_color_pair = 2;
p->current_border_pair = 3;
p->curses_backlight_state = 0;
p->xoffs = CONF_DEF_TOP_LEFT_X,
p->yoffs = CONF_DEF_TOP_LEFT_Y;
p->cellwidth = LCD_DEFAULT_CELLWIDTH;
p->cellheight = LCD_DEFAULT_CELLHEIGHT;
2006-04-08 14:49:37 +00:00
2006-04-11 10:26:00 +00:00
/* Get settings from config file */
/* Get color settings */
/* foreground color */
2006-04-08 14:49:37 +00:00
strncpy(buf, drvthis->config_get_string(drvthis->name, "Foreground", 0, CONF_DEF_FOREGR), sizeof(buf));
buf[sizeof(buf)-1] = '\0';
fore_color = set_foreground_color(buf);
2006-04-08 14:49:37 +00:00
debug(RPT_DEBUG, "%s: using foreground color %s", drvthis->name, buf);
2006-04-11 10:26:00 +00:00
/* background color */
2006-04-08 14:49:37 +00:00
strncpy(buf, drvthis->config_get_string(drvthis->name, "Background", 0, CONF_DEF_BACKGR), sizeof(buf));
buf[sizeof(buf)-1] = '\0';
back_color = set_background_color(buf);
2006-04-08 14:49:37 +00:00
debug(RPT_DEBUG, "%s: using background color %s", drvthis->name, buf);
2006-04-11 10:26:00 +00:00
/* backlight color */
2006-04-08 14:49:37 +00:00
strncpy(buf, drvthis->config_get_string(drvthis->name, "Backlight", 0, CONF_DEF_BACKLIGHT), sizeof(buf));
buf[sizeof(buf)-1] = '\0';
backlight_color = set_background_color(buf);
2006-04-08 14:49:37 +00:00
debug(RPT_DEBUG, "%s: using backlight color %s", drvthis->name, buf);
2006-04-11 10:26:00 +00:00
/* use ACS characters? */
p->useACS = drvthis->config_get_bool(drvthis->name, "UseACS", 0, 0);
debug(RPT_DEBUG, "%s: using ACS %s", drvthis->name, (p->useACS) ? "ON" : "OFF");
2002-02-21 22:50:12 +00:00
/* Get size settings */
2006-04-08 14:49:37 +00:00
if ((drvthis->request_display_width() > 0)
&& (drvthis->request_display_height() > 0)) {
/* If this driver is secondary driver, use size from primary driver */
2006-04-11 10:26:00 +00:00
p->width = drvthis->request_display_width();
p->height = drvthis->request_display_height();
2001-12-30 00:15:25 +00:00
}
else {
2002-02-21 22:50:12 +00:00
/* Use our own size from config file */
2006-04-08 14:49:37 +00:00
strncpy(buf, drvthis->config_get_string(drvthis->name, "Size", 0, CONF_DEF_SIZE), sizeof(buf));
buf[sizeof(buf)-1] = '\0';
2006-04-11 10:26:00 +00:00
if ((sscanf(buf , "%dx%d", &p->width, &p->height) != 2)
|| (p->width <= 0) || (p->width > LCD_MAX_WIDTH)
|| (p->height <= 0) || (p->height > LCD_MAX_HEIGHT)) {
2006-04-08 14:49:37 +00:00
report(RPT_WARNING, "%s: cannot read Size: %s; using default %s",
drvthis->name, buf, CONF_DEF_SIZE);
2006-04-11 10:26:00 +00:00
sscanf(CONF_DEF_SIZE, "%dx%d", &p->width, &p->height);
2002-02-21 22:50:12 +00:00
}
2000-04-03 22:13:57 +00:00
}
/*Get position settings*/
2006-04-08 14:49:37 +00:00
tmp = drvthis->config_get_int(drvthis->name, "TopLeftX", 0, CONF_DEF_TOP_LEFT_X);
if ((tmp < 0) || (tmp > 255)) {
report(RPT_WARNING, "%s: TopLeftX must be between 0 and 255; using default %d",
drvthis->name, CONF_DEF_TOP_LEFT_X);
tmp = CONF_DEF_TOP_LEFT_X;
}
2006-04-11 10:26:00 +00:00
p->xoffs = tmp;
2006-04-08 14:49:37 +00:00
tmp = drvthis->config_get_int(drvthis->name, "TopLeftY", 0, CONF_DEF_TOP_LEFT_Y);
if ((tmp < 0) || (tmp > 255)) {
report(RPT_WARNING, "%s: TopLeftY must be between 0 and 255; using default %d",
drvthis->name, CONF_DEF_TOP_LEFT_Y);
tmp = CONF_DEF_TOP_LEFT_Y;
}
2006-04-11 10:26:00 +00:00
p->yoffs = tmp;
//debug: sleep(1);
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
// Init curses...
2006-04-08 14:49:37 +00:00
initscr();
cbreak();
noecho();
nonl();
2001-10-05 17:17:11 +00:00
2006-04-08 14:49:37 +00:00
nodelay(stdscr, TRUE);
intrflush(stdscr, FALSE);
keypad(stdscr, TRUE);
2001-10-05 17:17:11 +00:00
2006-04-11 10:26:00 +00:00
p->win = newwin(p->height + 2, /* +2 for the border */
p->width + 2, /* +2 for the border */
p->yoffs,
p->xoffs);
2001-10-05 17:17:11 +00:00
2006-04-11 10:26:00 +00:00
//nodelay(p->win, TRUE);
//intrflush(p->win, FALSE);
//keypad(p->win, TRUE);
2001-10-05 17:17:11 +00:00
2001-09-25 05:10:19 +00:00
curs_set(0);
if (has_colors()) {
start_color();
init_pair(1, back_color, fore_color);
init_pair(2, fore_color, back_color);
2001-09-25 05:10:19 +00:00
init_pair(3, COLOR_WHITE, back_color);
init_pair(4, fore_color, backlight_color);
init_pair(5, COLOR_WHITE, backlight_color);
2001-09-25 05:10:19 +00:00
}
1999-12-09 23:15:14 +00:00
curses_clear(drvthis);
1999-12-09 23:15:14 +00:00
2006-04-08 14:49:37 +00:00
report(RPT_DEBUG, "%s: init() done", drvthis->name);
2001-12-30 00:15:25 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}
2001-09-25 05:10:19 +00:00
static void
curses_wborder (Driver *drvthis)
2006-04-11 07:17:27 +00:00
{
2006-04-11 10:26:00 +00:00
PrivateData *p = drvthis->private_data;
2001-09-25 05:10:19 +00:00
#ifdef CURSES_HAS_WCOLOR_SET
2001-09-25 05:10:19 +00:00
if (has_colors()) {
2006-04-11 10:26:00 +00:00
//wattron(p->win, COLOR_PAIR(p->current_border_pair) | A_BOLD);
wcolor_set(p->win, p->current_border_pair, NULL);
wattron(p->win, A_BOLD);
2001-09-25 05:10:19 +00:00
}
#endif
2001-09-25 05:10:19 +00:00
2006-04-11 10:26:00 +00:00
box(p->win, 0, 0);
2001-09-25 05:10:19 +00:00
#ifdef CURSES_HAS_WCOLOR_SET
2001-09-25 05:10:19 +00:00
if (has_colors()) {
2006-04-11 10:26:00 +00:00
//wattron(p->win, COLOR_PAIR(p->current_color_pair));
wcolor_set(p->win, p->current_color_pair, NULL);
wattroff(p->win, A_BOLD);
2001-09-25 05:10:19 +00:00
}
#endif
2001-09-25 05:10:19 +00:00
}
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
curses_close (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2006-04-11 10:26:00 +00:00
PrivateData *p = drvthis->private_data;
2001-09-25 05:24:00 +00:00
// Note that the program leaves a screen on
// the display to be left behind after closing;
// so don't clear...
2006-04-11 10:26:00 +00:00
if (p != NULL) {
// Close curses
wrefresh(p->win);
delwin(p->win);
2001-09-25 05:10:19 +00:00
2006-04-11 10:26:00 +00:00
move(0, 0);
endwin();
curs_set(1);
free(p);
}
drvthis->store_private_ptr(drvthis, NULL);
2001-12-30 00:15:25 +00:00
}
2001-12-30 00:15:25 +00:00
/////////////////////////////////////////////////////////////////
// Returns the display width
//
MODULE_EXPORT int
curses_width (Driver *drvthis)
2001-12-30 00:15:25 +00:00
{
2006-04-11 10:26:00 +00:00
PrivateData *p = drvthis->private_data;
return p->width;
2001-12-30 00:15:25 +00:00
}
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
/////////////////////////////////////////////////////////////////
// Returns the display height
//
MODULE_EXPORT int
curses_height (Driver *drvthis)
2001-12-30 00:15:25 +00:00
{
2006-04-11 10:26:00 +00:00
PrivateData *p = drvthis->private_data;
return p->height;
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Clears the LCD screen
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
curses_clear (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2006-04-11 10:26:00 +00:00
PrivateData *p = drvthis->private_data;
wbkgdset(p->win, COLOR_PAIR(p->current_color_pair) | ' ');
curses_wborder(drvthis);
2006-04-11 10:26:00 +00:00
werase(p->win);
1999-12-09 23:15:14 +00:00
}
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
curses_backlight (Driver *drvthis, int on)
{
2006-04-11 10:26:00 +00:00
PrivateData *p = drvthis->private_data;
if (p->curses_backlight_state == on)
return;
// no backlight: pairs 2, 3
// backlight: pairs 4, 5
2006-04-11 10:26:00 +00:00
p->curses_backlight_state = on;
2001-12-30 00:15:25 +00:00
2006-04-11 10:26:00 +00:00
if (on) {
p->current_color_pair = 4;
p->current_border_pair = 5;
2001-12-30 00:15:25 +00:00
}
else {
2006-04-11 10:26:00 +00:00
p->current_color_pair = 2;
p->current_border_pair = 3;
}
curses_clear(drvthis);
}
1999-12-09 23:15:14 +00:00
/////////////////////////////////////////////////////////////////
// Prints a string on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,4).
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
curses_string (Driver *drvthis, int x, int y, char *string)
1999-12-09 23:15:14 +00:00
{
2006-04-11 10:26:00 +00:00
PrivateData *p = drvthis->private_data;
1999-12-09 23:15:14 +00:00
2006-04-11 10:26:00 +00:00
if ((x <= 0) || (y <= 0) || (x > p->width) || (y > p->height))
return;
2001-09-25 05:10:19 +00:00
2006-04-11 10:26:00 +00:00
mvwaddstr(p->win, y, x, string);
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Prints a character on the lcd display, at position (x,y). The
// upper-left is (1,1), and the lower right should be (20,4).
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
curses_chr (Driver *drvthis, int x, int y, char c)
1999-12-09 23:15:14 +00:00
{
2006-04-11 10:26:00 +00:00
PrivateData *p = drvthis->private_data;
2006-04-11 10:26:00 +00:00
if ((x <= 0) || (y <= 0) || (x > p->width) || (y > p->height))
return;
2001-09-25 05:10:19 +00:00
2006-04-11 10:26:00 +00:00
mvwaddch(p->win, y, x, c);
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Draws a vertical bar; erases entire column onscreen.
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
curses_vbar (Driver *drvthis, int x, int y, int len, int promille, int options)
1999-12-09 23:15:14 +00:00
{
2006-04-11 10:26:00 +00:00
PrivateData *p = drvthis->private_data;
// map
char ACS_map[] = { ACS_S9, ACS_S9, ACS_S7, ACS_S7, ACS_S3, ACS_S3, ACS_S1, ACS_S1 };
char ascii_map[] = { ' ', ' ', '-', '-', '=', '=', '#', '#' };
char *map = (p->useACS) ? ACS_map : ascii_map;
int pixels = ((long) 2 * len * p->cellheight) * promille / 2000;
2002-01-09 16:10:53 +00:00
int pos;
2006-04-11 10:26:00 +00:00
if ((x <= 0) || (y <= 0) || (x > p->width))
return;
2001-09-25 05:10:19 +00:00
2002-02-08 00:15:50 +00:00
/* x and y are the start position of the bar.
* The bar by default grows in the 'up' direction
* (other direction not yet implemented).
* len is the number of characters that the bar is long at 100%
* promille is the number of promilles (0..1000) that the bar should be filled.
*/
2001-09-25 05:10:19 +00:00
2006-04-11 10:26:00 +00:00
for (pos = 0; pos < len; pos++) {
2001-09-25 05:10:19 +00:00
2006-04-11 10:26:00 +00:00
if (y - pos <= 0)
return;
2001-09-25 05:10:19 +00:00
2006-04-11 10:26:00 +00:00
if (pixels >= p->cellheight) {
2002-02-08 00:15:50 +00:00
/* write a "full" block to the screen... */
curses_chr(drvthis, x, y-pos, (p->useACS) ? ACS_BLOCK : '#');
2001-09-25 05:10:19 +00:00
}
2006-04-08 14:49:37 +00:00
else if (pixels > 0) {
2001-09-25 05:10:19 +00:00
// write a partial block...
curses_chr(drvthis, x, y-pos, map[len-1]);
2001-09-25 05:10:19 +00:00
break;
}
2002-01-09 16:10:53 +00:00
else {
; // write nothing (not even a space)
}
2006-04-11 10:26:00 +00:00
pixels -= p->cellheight;
2000-04-03 22:13:57 +00:00
}
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Draws a horizontal bar to the right.
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
curses_hbar (Driver *drvthis, int x, int y, int len, int promille, int options)
1999-12-09 23:15:14 +00:00
{
2006-04-11 10:26:00 +00:00
PrivateData *p = drvthis->private_data;
int pixels = ((long) 2 * len * p->cellwidth) * promille / 2000;
2002-01-09 16:10:53 +00:00
int pos;
2006-04-11 10:26:00 +00:00
if ((x <= 0) || (y <= 0) || (y > p->height))
return;
2002-01-09 16:10:53 +00:00
2002-02-08 00:15:50 +00:00
/* x and y are the start position of the bar.
* The bar by default grows in the 'right' direction
* (other direction not yet implemented).
* len is the number of characters that the bar is long at 100%
* promille is the number of promilles (0..1000) that the bar should be filled.
*/
2002-01-09 16:10:53 +00:00
2006-04-11 10:26:00 +00:00
for (pos = 0; pos < len; pos++) {
2002-01-09 16:10:53 +00:00
2006-04-11 10:26:00 +00:00
if (x + pos > p->width)
return;
2002-01-09 16:10:53 +00:00
2006-04-11 10:26:00 +00:00
if (pixels >= p->cellwidth * 2/3) {
2002-02-08 00:15:50 +00:00
/* write a "full" block to the screen... */
curses_chr(drvthis, x+pos, y, '=');
2002-01-09 16:10:53 +00:00
}
2006-04-11 10:26:00 +00:00
else if (pixels > p->cellwidth * 1/3) {
2002-02-08 00:15:50 +00:00
/* write a partial block... */
curses_chr(drvthis, x+pos, y, '-');
2002-01-09 16:10:53 +00:00
break;
}
else {
; // write nothing (not even a space)
}
2006-04-11 10:26:00 +00:00
pixels -= p->cellwidth;
2000-04-03 22:13:57 +00:00
}
1999-12-09 23:15:14 +00:00
}
/////////////////////////////////////////////////////////////////
// Sets character 0 to an icon...
//
2002-05-23 18:03:36 +00:00
MODULE_EXPORT int
curses_icon (Driver *drvthis, int x, int y, int icon)
1999-12-09 23:15:14 +00:00
{
2006-04-11 10:26:00 +00:00
PrivateData *p = drvthis->private_data;
char ch = '?';
2002-02-08 00:15:50 +00:00
switch (icon) {
2006-04-11 10:26:00 +00:00
case ICON_BLOCK_FILLED:
ch = (p->useACS) ? ACS_BLOCK : '#';
break;
case ICON_HEART_OPEN:
ch = '-';
break;
case ICON_HEART_FILLED:
ch = '+';
break;
case ICON_ARROW_UP:
ch = (p->useACS) ? ACS_UARROW : '^';
break;
case ICON_ARROW_DOWN:
ch = (p->useACS) ? ACS_DARROW : 'v';
break;
case ICON_ARROW_LEFT:
ch = (p->useACS) ? ACS_LARROW : '<';
break;
case ICON_ARROW_RIGHT:
ch = (p->useACS) ? ACS_RARROW : '>';
break;
case ICON_ELLIPSIS:
ch = '~';
break;
default:
return -1; /* Let the core do it */
}
curses_chr(drvthis, x, y, ch);
2002-05-23 18:03:36 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}
//////////////////////////////////////////////////////////////////
// Flushes all output to the lcd...
//
2001-12-30 00:15:25 +00:00
MODULE_EXPORT void
curses_flush (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2006-04-11 10:26:00 +00:00
PrivateData *p = drvthis->private_data;
int c;
2006-04-08 14:49:37 +00:00
if ((c = getch()) != ERR)
2006-04-11 07:17:27 +00:00
if (c == 0x0C) { /* ^L restores screen */
curses_restore_screen(drvthis);
2006-04-08 14:49:37 +00:00
ungetch(c);
}
curses_wborder(drvthis);
2006-04-11 10:26:00 +00:00
wrefresh(p->win);
1999-12-09 23:15:14 +00:00
}
2001-12-30 00:15:25 +00:00
MODULE_EXPORT const char *
curses_get_key (Driver *drvthis)
1999-12-09 23:15:14 +00:00
{
2006-04-11 10:26:00 +00:00
//PrivateData *p = drvthis->private_data;
2002-02-08 00:15:50 +00:00
static char ret_val[2] = {0,0};
2006-04-08 14:49:37 +00:00
int key = getch();
1999-12-09 23:15:14 +00:00
2006-04-08 14:49:37 +00:00
switch (key) {
2006-04-11 10:26:00 +00:00
case ERR:
return NULL;
case 0x0C:
/* internal: ^L restores screen */
curses_restore_screen(drvthis);
return NULL;
break;
case KEY_LEFT:
2002-05-26 19:21:23 +00:00
return "Left";
case KEY_UP:
2002-05-26 19:21:23 +00:00
return "Up";
case KEY_DOWN:
2002-05-26 19:21:23 +00:00
return "Down";
case KEY_RIGHT:
2002-05-26 19:21:23 +00:00
return "Right";
2002-02-08 00:15:50 +00:00
case KEY_ENTER:
case 0x0D:
2006-04-11 10:26:00 +00:00
return "Enter";
2002-02-08 00:15:50 +00:00
case 0x1B:
return "Escape";
default:
2006-04-08 14:49:37 +00:00
report(RPT_INFO, "%s: Unknown key 0x%02X", drvthis->name, key);
ret_val[0] = (char) key & 0xFF;
return (ret_val[0] != '\0') ? ret_val : NULL;
break;
}
1999-12-09 23:15:14 +00:00
}
void
curses_restore_screen (Driver *drvthis)
2006-04-11 07:17:27 +00:00
{
2006-04-11 10:26:00 +00:00
PrivateData *p = drvthis->private_data;
erase();
refresh();
#ifdef CURSES_HAS_REDRAWWIN
2006-04-11 10:26:00 +00:00
redrawwin(p->win);
#endif
2006-04-11 10:26:00 +00:00
wrefresh(p->win);
}
2006-04-11 10:26:00 +00:00