[GB.NCURSES]
* NEW: Added Key static class containing key constants * NEW: Buffered property in Window class to allow buffered output * NEW: Refresh method in Window class to produce output if Buffered property was set * NEW: Flush method in Window class to clear the input queue * NEW: Ask method in Window class to prompt the user for specific keys * NEW: PrintCenter method in Window class to print text in the centre of the screen * NEW: Window array accessors now used to change character attributes * OPT: Standard input is watched only once * BUG: Inserted missing return statement when reading Window.Border git-svn-id: svn://localhost/gambas/trunk@4627 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
1464b07a0c
commit
e770acc969
@ -1,6 +1,5 @@
|
||||
SUBDIRS = \
|
||||
main \
|
||||
@ncurses_dir@ \
|
||||
@bzlib2_dir@ \
|
||||
@zlib_dir@ \
|
||||
@mysql_dir@ \
|
||||
@ -27,6 +26,7 @@ SUBDIRS = \
|
||||
@imageimlib_dir@ \
|
||||
@dbus_dir@ \
|
||||
@gsl_dir@ \
|
||||
@ncurses_dir@ \
|
||||
comp \
|
||||
app \
|
||||
examples \
|
||||
|
@ -9,7 +9,6 @@ AC_INIT(configure.ac)
|
||||
|
||||
AC_CONFIG_SUBDIRS(main)
|
||||
|
||||
GB_CONFIG_SUBDIRS(ncurses, gb.ncurses)
|
||||
GB_CONFIG_SUBDIRS(bzlib2, gb.compress.bzlib2)
|
||||
GB_CONFIG_SUBDIRS(zlib, gb.compress.zlib)
|
||||
GB_CONFIG_SUBDIRS(mysql, gb.db.mysql)
|
||||
@ -36,6 +35,7 @@ GB_CONFIG_SUBDIRS(imageio, gb.image.io)
|
||||
GB_CONFIG_SUBDIRS(imageimlib, gb.image.imlib)
|
||||
GB_CONFIG_SUBDIRS(dbus, gb.dbus)
|
||||
GB_CONFIG_SUBDIRS(gsl, gb.gsl)
|
||||
GB_CONFIG_SUBDIRS(ncurses, gb.ncurses)
|
||||
|
||||
AC_CONFIG_SUBDIRS(comp)
|
||||
AC_CONFIG_SUBDIRS(app)
|
||||
|
@ -11,5 +11,6 @@ gb_ncurses_la_LDFLAGS = -module @LD_FLAGS@ @NCURSES_LDFLAGS@
|
||||
gb_ncurses_la_SOURCES = \
|
||||
main.h main.c \
|
||||
c_ncurses.h c_ncurses.c \
|
||||
c_window.h c_window.c
|
||||
c_window.h c_window.c \
|
||||
c_key.h c_key.c
|
||||
|
||||
|
65
gb.ncurses/src/c_key.c
Normal file
65
gb.ncurses/src/c_key.c
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* c_key.c - gb.ncurses Key static class
|
||||
*
|
||||
* Copyright (C) 2012 Tobias Boege <tobias@gambas-buch.de>
|
||||
*
|
||||
* 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, or (at your option)
|
||||
* 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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#define __C_KEY_C
|
||||
|
||||
#include "../gambas.h"
|
||||
|
||||
#include <ncurses.h>
|
||||
|
||||
#include "c_key.h"
|
||||
|
||||
GB_DESC CKeyDesc[] =
|
||||
{
|
||||
GB_DECLARE("Key", 0),
|
||||
GB_NOT_CREATABLE(),
|
||||
|
||||
GB_CONSTANT("Return", "i", (int) '\n'),
|
||||
|
||||
GB_CONSTANT("Break", "i", KEY_BREAK),
|
||||
GB_CONSTANT("Home", "i", KEY_HOME),
|
||||
GB_CONSTANT("Backspace", "i", KEY_BACKSPACE),
|
||||
GB_CONSTANT("PageUp", "i", KEY_PPAGE),
|
||||
GB_CONSTANT("PageDown", "i", KEY_NPAGE),
|
||||
GB_CONSTANT("Enter", "i", KEY_ENTER),
|
||||
|
||||
/* Arrow Keys */
|
||||
GB_CONSTANT("Left", "i", KEY_LEFT),
|
||||
GB_CONSTANT("Right", "i", KEY_RIGHT),
|
||||
GB_CONSTANT("Up", "i", KEY_UP),
|
||||
GB_CONSTANT("Down", "i", KEY_DOWN),
|
||||
|
||||
/* F keys */
|
||||
GB_CONSTANT("F1", "i", KEY_F(0)),
|
||||
GB_CONSTANT("F2", "i", KEY_F(1)),
|
||||
GB_CONSTANT("F3", "i", KEY_F(2)),
|
||||
GB_CONSTANT("F4", "i", KEY_F(3)),
|
||||
GB_CONSTANT("F5", "i", KEY_F(4)),
|
||||
GB_CONSTANT("F6", "i", KEY_F(5)),
|
||||
GB_CONSTANT("F7", "i", KEY_F(6)),
|
||||
GB_CONSTANT("F8", "i", KEY_F(7)),
|
||||
GB_CONSTANT("F9", "i", KEY_F(8)),
|
||||
GB_CONSTANT("F10", "i", KEY_F(9)),
|
||||
GB_CONSTANT("F11", "i", KEY_F(10)),
|
||||
GB_CONSTANT("F12", "i", KEY_F(11)),
|
||||
|
||||
GB_END_DECLARE
|
||||
};
|
29
gb.ncurses/src/c_key.h
Normal file
29
gb.ncurses/src/c_key.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* c_key.h - gb.ncurses Key static class
|
||||
*
|
||||
* Copyright (C) 2012 Tobias Boege <tobias@gambas-buch.de>
|
||||
*
|
||||
* 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, or (at your option)
|
||||
* 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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __C_KEY_H
|
||||
#define __C_KEY_H
|
||||
|
||||
#ifndef __C_KEY_C
|
||||
extern GB_DESC CKeyDesc[];
|
||||
#endif
|
||||
|
||||
#endif /* __C_KEY_H */
|
@ -45,6 +45,7 @@ static int nc_echo;
|
||||
|
||||
DECLARE_EVENT(EVENT_Resize);
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* Signal handler for the SIGWINCH signal.
|
||||
* @signum: signal number given
|
||||
@ -53,12 +54,13 @@ DECLARE_EVENT(EVENT_Resize);
|
||||
void nc_sigwinch_handler(int signum)
|
||||
{
|
||||
/* TODO: I wonder if this works... */
|
||||
|
||||
|
||||
/* BM: Of course not! :-) You can't raise an event from a signal handler
|
||||
* and moreover you have no sender! */
|
||||
|
||||
|
||||
if (signum == SIGWINCH) GB.Raise(NULL, EVENT_Resize, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool _init = FALSE;
|
||||
|
||||
@ -69,12 +71,11 @@ bool NCURSES_running()
|
||||
|
||||
void NCURSES_init(void)
|
||||
{
|
||||
struct sigaction sa;
|
||||
|
||||
if (_init)
|
||||
return;
|
||||
|
||||
|
||||
initscr();
|
||||
keypad(stdscr, TRUE);
|
||||
|
||||
/* global variable default setup */
|
||||
nc_cursor = CURSOR_VISIBLE;
|
||||
@ -85,6 +86,9 @@ void NCURSES_init(void)
|
||||
cbreak();
|
||||
noecho();
|
||||
|
||||
#if 0
|
||||
struct sigaction sa;
|
||||
|
||||
sa.sa_handler = nc_sigwinch_handler;
|
||||
sigemptyset(&(sa.sa_mask));
|
||||
sa.sa_flags = 0;
|
||||
@ -92,9 +96,10 @@ void NCURSES_init(void)
|
||||
{
|
||||
fprintf(stderr, "gb.ncurses: Could not install SIGWINCH signal handler");
|
||||
}
|
||||
#endif
|
||||
|
||||
refresh();
|
||||
|
||||
|
||||
_init = TRUE;
|
||||
}
|
||||
|
||||
@ -108,7 +113,7 @@ void NCURSES_exit()
|
||||
}
|
||||
|
||||
|
||||
BEGIN_PROPERTY(CNCurses_cursor)
|
||||
BEGIN_PROPERTY(NCurses_Cursor)
|
||||
|
||||
if (READ_PROPERTY)
|
||||
{
|
||||
@ -116,7 +121,6 @@ BEGIN_PROPERTY(CNCurses_cursor)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Hide if setting cursor is not supported */
|
||||
switch (VPROP(GB_INTEGER))
|
||||
{
|
||||
case CURSOR_HIDDEN:
|
||||
@ -133,7 +137,7 @@ BEGIN_PROPERTY(CNCurses_cursor)
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
BEGIN_PROPERTY(CNCurses_input)
|
||||
BEGIN_PROPERTY(NCurses_Input)
|
||||
|
||||
if (READ_PROPERTY)
|
||||
{
|
||||
@ -161,7 +165,7 @@ BEGIN_PROPERTY(CNCurses_input)
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
BEGIN_PROPERTY(CNCurses_echo)
|
||||
BEGIN_PROPERTY(NCurses_Echo)
|
||||
|
||||
if (READ_PROPERTY)
|
||||
{
|
||||
@ -175,38 +179,19 @@ BEGIN_PROPERTY(CNCurses_echo)
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
BEGIN_PROPERTY(CNCurses_lines)
|
||||
BEGIN_PROPERTY(NCurses_Lines)
|
||||
|
||||
GB.ReturnInteger(LINES);
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
BEGIN_PROPERTY(CNCurses_cols)
|
||||
BEGIN_PROPERTY(NCurses_Cols)
|
||||
|
||||
GB.ReturnInteger(COLS);
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
BEGIN_METHOD_VOID(CNCurses_init)
|
||||
|
||||
NCURSES_init();
|
||||
|
||||
END_METHOD
|
||||
|
||||
BEGIN_METHOD_VOID(CNCurses_exit)
|
||||
|
||||
NCURSES_exit();
|
||||
|
||||
END_METHOD
|
||||
|
||||
BEGIN_METHOD_VOID(CNCurses_on)
|
||||
|
||||
if (NCURSES_RUNNING) return;
|
||||
refresh();
|
||||
|
||||
END_METHOD
|
||||
|
||||
BEGIN_METHOD_VOID(CNCurses_off)
|
||||
BEGIN_METHOD_VOID(NCurses_exit)
|
||||
|
||||
NCURSES_exit();
|
||||
|
||||
@ -224,17 +209,14 @@ GB_DESC CNCursesDesc[] =
|
||||
GB_CONSTANT("CBreak", "i", INPUT_CBREAK),
|
||||
GB_CONSTANT("Raw", "i", INPUT_RAW),
|
||||
|
||||
GB_STATIC_PROPERTY("Cursor", "i", CNCurses_cursor),
|
||||
GB_STATIC_PROPERTY("Input", "i", CNCurses_input),
|
||||
GB_STATIC_PROPERTY("Echo", "b", CNCurses_echo),
|
||||
GB_STATIC_PROPERTY("Cursor", "i", NCurses_Cursor),
|
||||
GB_STATIC_PROPERTY("Input", "i", NCurses_Input),
|
||||
GB_STATIC_PROPERTY("Echo", "b", NCurses_Echo),
|
||||
|
||||
GB_STATIC_PROPERTY_READ("Lines", "i", CNCurses_lines),
|
||||
GB_STATIC_PROPERTY_READ("Cols", "i", CNCurses_cols),
|
||||
GB_STATIC_PROPERTY_READ("Lines", "i", NCurses_Lines),
|
||||
GB_STATIC_PROPERTY_READ("Cols", "i", NCurses_Cols),
|
||||
|
||||
GB_STATIC_METHOD("_init", NULL, CNCurses_init, NULL),
|
||||
GB_STATIC_METHOD("_exit", NULL, CNCurses_exit, NULL),
|
||||
GB_STATIC_METHOD("On", NULL, CNCurses_on, NULL),
|
||||
GB_STATIC_METHOD("Off", NULL, CNCurses_off, NULL),
|
||||
GB_STATIC_METHOD("_exit", NULL, NCurses_exit, NULL),
|
||||
|
||||
GB_END_DECLARE
|
||||
};
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -33,9 +33,13 @@
|
||||
#define THIS ((struct nc_window *) _object)
|
||||
#define HAS_BORDER (THIS->border)
|
||||
#define IS_WRAPPED (THIS->wrap)
|
||||
/* This will produce final output on terminal screen, shall be called only by Gambas functions
|
||||
as they assemble all changes for a single functionality and may then output once. */
|
||||
#define REFRESH() WINDOW_refresh()
|
||||
#define IS_BUFFERED (THIS->buffered)
|
||||
/* This will produce final output on terminal screen */
|
||||
#define REAL_REFRESH() WINDOW_real_refresh()
|
||||
/* This macro is mostly called by Gambas implementation functions to request output on screen
|
||||
(read: to check if the output is buffered and if not produce output by means of
|
||||
REAL_REFRESH(). To check buffering, this need to get an object parameter.) */
|
||||
#define REFRESH() WINDOW_refresh(THIS)
|
||||
|
||||
/* Translate linear (absolute) memory addresses and x,y coordinates into each other
|
||||
most useful when wrapping is needed. */
|
||||
@ -48,8 +52,10 @@
|
||||
}
|
||||
/* Interpret the -1 values in coordinates as to insert the current cursor position */
|
||||
#define MAKE_COORDS(win, x, y) { \
|
||||
if ((x) == -1) x = getcurx(win); \
|
||||
if ((y) == -1) y = getcury(win); \
|
||||
if ((x) == -1) \
|
||||
x = getcurx(win); \
|
||||
if ((y) == -1) \
|
||||
y = getcury(win); \
|
||||
}
|
||||
/* Check for out-of-range coordinates */
|
||||
#define BAD_COORDS(win, x, y) ((x) < 0 || (x) >= getmaxx(win) || \
|
||||
@ -70,11 +76,12 @@ enum
|
||||
|
||||
#define WIN_ATTR_METHOD(b, a) { \
|
||||
if (READ_PROPERTY) \
|
||||
GB.ReturnBoolean(nc_window_attrs_driver( \
|
||||
GB.ReturnBoolean(WINDOW_attrs_driver( \
|
||||
THIS, (a), ATTR_DRV_RET) \
|
||||
& (a)); \
|
||||
else nc_window_attrs_driver( \
|
||||
THIS, (a), (b) ? ATTR_DRV_ON : ATTR_DRV_OFF); \
|
||||
else \
|
||||
WINDOW_attrs_driver(THIS, (a), \
|
||||
(b) ? ATTR_DRV_ON : ATTR_DRV_OFF); \
|
||||
}
|
||||
#define WIN_ATTR_METHOD_BOOL(a) WIN_ATTR_METHOD(VPROP(GB_BOOLEAN), a);
|
||||
#define WIN_ATTR_METHOD_INT(a) WIN_ATTR_METHOD(1, a);
|
||||
@ -84,12 +91,12 @@ enum
|
||||
line manually. A higher-callstack function may call REFRESH() to get output. */
|
||||
#define CHAR_ATTR_METHOD(b, a) { \
|
||||
if (READ_PROPERTY) \
|
||||
GB.ReturnBoolean(nc_window_char_attrs_driver( \
|
||||
GB.ReturnBoolean(WINDOW_char_attrs_driver( \
|
||||
THIS, (a), THIS->pos.col, THIS->pos.line, \
|
||||
ATTR_DRV_RET) & (a)); \
|
||||
else nc_window_char_attrs_driver( \
|
||||
THIS, (a), THIS->pos.col, THIS->pos.line, \
|
||||
(b) ? ATTR_DRV_ON : ATTR_DRV_OFF); \
|
||||
else \
|
||||
WINDOW_char_attrs_driver(THIS, (a), THIS->pos.col, \
|
||||
THIS->pos.line, (b) ? ATTR_DRV_ON : ATTR_DRV_OFF); \
|
||||
wtouchln(THIS->main, THIS->pos.line + (HAS_BORDER ? 1 : 0), 1, 1); \
|
||||
}
|
||||
#define CHAR_ATTR_METHOD_BOOL(a) CHAR_ATTR_METHOD(VPROP(GB_BOOLEAN), a);
|
||||
@ -113,6 +120,8 @@ struct nc_window
|
||||
PANEL *pan; /* Panel of the main window to provide overlapping windows */
|
||||
bool border; /* Whether there is a border */
|
||||
bool wrap; /* Whether text shall be truncated or wrapped on line ends */
|
||||
bool buffered; /* Whether the output via REFRESH() macro shall be buffered (only a call to
|
||||
Window.Refresh() will then produce any output) */
|
||||
struct /* This structure is used to pass a line and a column number to virtual objects */
|
||||
{
|
||||
int line;
|
||||
@ -126,13 +135,13 @@ extern GB_DESC CWindowAttrsDesc[];
|
||||
extern GB_DESC CCharAttrsDesc[];
|
||||
#endif
|
||||
|
||||
#define nc_window_main_to_content() (nc_window_copy_window(THIS->main, THIS->content, 0, 0, \
|
||||
#define WINDOW_main_to_content() WINDOW_copy_window(THIS->main, THIS->content, 0, 0, \
|
||||
getmaxx(THIS->content), \
|
||||
getmaxy(THIS->content), 0, 0))
|
||||
#define nc_window_content_to_main() (nc_window_copy_window(THIS->content, THIS->main, 0, 0, \
|
||||
getmaxy(THIS->content), 0, 0)
|
||||
#define WINDOW_content_to_main() WINDOW_copy_window(THIS->content, THIS->main, 0, 0, \
|
||||
getmaxx(THIS->content), \
|
||||
getmaxy(THIS->content), 0, 0))
|
||||
getmaxy(THIS->content), 0, 0)
|
||||
|
||||
void WINDOW_refresh(void);
|
||||
void WINDOW_real_refresh();
|
||||
|
||||
#endif /* __C_WINDOW_C */
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include "c_ncurses.h"
|
||||
#include "c_window.h"
|
||||
#include "c_key.h"
|
||||
#include "main.h"
|
||||
|
||||
GB_INTERFACE GB EXPORT;
|
||||
@ -32,7 +33,8 @@ GB_DESC *GB_CLASSES[] EXPORT =
|
||||
CNCursesDesc,
|
||||
CWindowDesc,
|
||||
CWindowAttrsDesc,
|
||||
// CCharAttrsDesc,
|
||||
CCharAttrsDesc,
|
||||
CKeyDesc,
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -41,11 +43,15 @@ static void hook_error(int code, char *error, char *where)
|
||||
NCURSES_exit();
|
||||
}
|
||||
|
||||
static void hook_init()
|
||||
{
|
||||
NCURSES_init();
|
||||
}
|
||||
|
||||
int EXPORT GB_INIT()
|
||||
{
|
||||
GB.Hook(GB_HOOK_ERROR, (void *)hook_error);
|
||||
|
||||
GB.Hook(GB_HOOK_ERROR, (void *) hook_error);
|
||||
GB.Hook(GB_HOOK_MAIN, (void *) hook_init);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user