[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
/*
|
2012-06-13 17:47:00 +02:00
|
|
|
* c_input.c - gb.ncurses opaque input routines
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-06-13 17:47:00 +02:00
|
|
|
#define __C_INPUT_C
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <linux/kd.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <ncurses.h>
|
|
|
|
|
|
|
|
#include "gambas.h"
|
|
|
|
#include "gb_common.h"
|
|
|
|
|
|
|
|
#include "main.h"
|
2012-06-13 17:47:00 +02:00
|
|
|
#include "c_input.h"
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
#include "c_window.h"
|
|
|
|
|
|
|
|
#define E_UNSUPP "Unsupported value"
|
|
|
|
#define E_NO_NODELAY "Could not initialise NoDelay mode"
|
|
|
|
|
2012-06-13 17:47:00 +02:00
|
|
|
/* True input mode is inherited from terminal, we need a surely invalid
|
|
|
|
* value to be reset upon initialisation */
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
static int _input = -1;
|
|
|
|
#define IN_NODELAY (_input == INPUT_NODELAY)
|
2012-06-13 17:47:00 +02:00
|
|
|
static char _watch_fd = -1;
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Input initialisation
|
|
|
|
*/
|
|
|
|
int INPUT_init()
|
|
|
|
{
|
|
|
|
INPUT_mode(INPUT_CBREAK);
|
2012-06-13 17:47:00 +02:00
|
|
|
INPUT_watch(0);
|
|
|
|
NODELAY_repeater_delay(1);
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Input cleanup
|
|
|
|
*/
|
|
|
|
void INPUT_exit()
|
|
|
|
{
|
|
|
|
/* If we are still in NoDelay mode, exit it */
|
|
|
|
if (IN_NODELAY) {
|
|
|
|
INPUT_mode(INPUT_CBREAK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-13 17:47:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
#define MY_DEBUG() fprintf(stderr, "in %s\n", __func__)
|
|
|
|
|
|
|
|
|
|
|
|
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
/**
|
2012-06-13 17:47:00 +02:00
|
|
|
* Begin watching the given fd (for read)
|
|
|
|
* @fd: fd to watch. -1 means to stop watching at all.
|
|
|
|
* This automatically stops watching the previously watched fd, if any
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
*/
|
2012-06-13 17:47:00 +02:00
|
|
|
static int INPUT_watch(int fd)
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
{
|
2012-06-13 17:47:00 +02:00
|
|
|
MY_DEBUG();
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
|
2012-06-13 17:47:00 +02:00
|
|
|
if (fd == _watch_fd)
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
return 0;
|
2012-06-13 17:47:00 +02:00
|
|
|
|
|
|
|
if (_watch_fd != -1)
|
|
|
|
GB.Watch(_watch_fd, GB_WATCH_NONE, NULL, 0);
|
|
|
|
if (fd == -1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
GB.Watch(fd, GB_WATCH_READ, INPUT_callback, 0);
|
|
|
|
_watch_fd = fd;
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to be called by Gambas when data arrives
|
2012-06-13 17:47:00 +02:00
|
|
|
* Params currently not used
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
*/
|
|
|
|
static void INPUT_callback(int fd, int flag, intptr_t arg)
|
|
|
|
{
|
2012-06-13 17:47:00 +02:00
|
|
|
MY_DEBUG();
|
|
|
|
|
|
|
|
/* if (IN_NODELAY)
|
|
|
|
NODELAY_change_pressed(NODELAY_get(-1));
|
|
|
|
else
|
|
|
|
*/ WINDOW_raise_read(NULL);
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-13 17:47:00 +02:00
|
|
|
* Return or set the current input mode
|
|
|
|
* @mode: one of INPUT_* enums
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
*/
|
2012-06-13 17:47:00 +02:00
|
|
|
int INPUT_mode(int mode)
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
{
|
2012-06-13 17:47:00 +02:00
|
|
|
if (mode == INPUT_RETURN)
|
|
|
|
return _input;
|
|
|
|
|
|
|
|
if (mode == _input)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (IN_NODELAY)
|
|
|
|
NODELAY_exit();
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case INPUT_COOKED:
|
|
|
|
nocbreak();
|
|
|
|
break;
|
|
|
|
case INPUT_CBREAK:
|
|
|
|
cbreak();
|
|
|
|
break;
|
|
|
|
case INPUT_RAW:
|
|
|
|
raw();
|
|
|
|
break;
|
|
|
|
case INPUT_NODELAY:
|
|
|
|
if (NODELAY_init() == -1) {
|
|
|
|
GB.Error(E_NO_NODELAY);
|
|
|
|
/* We return 0 to not override the previous
|
|
|
|
* error message with the one emitted by the
|
|
|
|
* caller if we return error */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GB.Error(E_UNSUPP);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
_input = mode;
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-13 17:47:00 +02:00
|
|
|
* Drain the input queue
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
*/
|
2012-06-13 17:47:00 +02:00
|
|
|
void INPUT_drain()
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
{
|
2012-06-13 17:47:00 +02:00
|
|
|
if (IN_NODELAY)
|
|
|
|
NODELAY_drain();
|
|
|
|
else
|
|
|
|
flushinp();
|
|
|
|
}
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
|
2012-06-13 17:47:00 +02:00
|
|
|
/**
|
|
|
|
* Retrieve input from ncurses
|
|
|
|
*/
|
|
|
|
static int INPUT_get_ncurses(int timeout)
|
|
|
|
{
|
|
|
|
int ret;
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
|
2012-06-13 17:47:00 +02:00
|
|
|
if (timeout >= 0)
|
|
|
|
timeout(timeout);
|
|
|
|
ret = getch();
|
|
|
|
if (ret == ERR) {
|
|
|
|
/* Had a timeout, the manual doesn't define any errors to
|
|
|
|
happen for wgetch() besides NULL pointer arguments. The
|
|
|
|
only source of ERR is timeout expired. */
|
|
|
|
if (timeout >= 0)
|
|
|
|
ret = 0;
|
|
|
|
}
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
|
2012-06-13 17:47:00 +02:00
|
|
|
if (timeout >= 0)
|
|
|
|
timeout(-1);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a keypress within the given timeout
|
|
|
|
* @timeout: number of milliseconds to wait. If no key is pressed during it,
|
|
|
|
* 0 will be returned.
|
|
|
|
*/
|
|
|
|
int INPUT_get(int timeout)
|
|
|
|
{
|
|
|
|
if (IN_NODELAY)
|
|
|
|
return NODELAY_get(timeout);
|
|
|
|
else
|
|
|
|
return INPUT_get_ncurses(timeout);
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
}
|
|
|
|
|
2012-06-13 17:47:00 +02:00
|
|
|
BEGIN_PROPERTY(Input_IsConsole)
|
|
|
|
|
|
|
|
int fd = NODELAY_consolefd();
|
|
|
|
|
|
|
|
if (fd == -1) {
|
|
|
|
GB.ReturnBoolean(FALSE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
GB.ReturnBoolean(TRUE);
|
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(Input_RepeatDelay)
|
|
|
|
|
|
|
|
if (READ_PROPERTY) {
|
|
|
|
GB.ReturnInteger(NODELAY_repeater_delay(REPEATER_RETURN));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (NODELAY_repeater_delay(VPROP(GB_INTEGER)) == -1) {
|
|
|
|
GB.Error("Invalid value");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
GB_DESC CInputDesc[] = {
|
|
|
|
GB_DECLARE("Input", 0),
|
|
|
|
GB_NOT_CREATABLE(),
|
|
|
|
|
|
|
|
GB_CONSTANT("NoTimeout", "i", TIMEOUT_NOTIMEOUT),
|
|
|
|
|
|
|
|
GB_CONSTANT("Cooked", "i", INPUT_COOKED),
|
|
|
|
GB_CONSTANT("CBreak", "i", INPUT_CBREAK),
|
|
|
|
GB_CONSTANT("Raw", "i", INPUT_RAW),
|
|
|
|
GB_CONSTANT("NoDelay", "i", INPUT_NODELAY),
|
|
|
|
|
|
|
|
GB_STATIC_PROPERTY_READ("IsConsole", "b", Input_IsConsole),
|
|
|
|
GB_STATIC_PROPERTY("RepeatDelay", "i", Input_RepeatDelay),
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NODELAY routines
|
|
|
|
*/
|
|
|
|
static struct {
|
|
|
|
struct {
|
|
|
|
struct termios term;
|
|
|
|
int kbmode;
|
|
|
|
void (*error_hook)();
|
|
|
|
} old;
|
|
|
|
int fd;
|
|
|
|
unsigned short pressed;
|
|
|
|
unsigned int delay;
|
|
|
|
GB_TIMER *timer;
|
|
|
|
} no_delay;
|
|
|
|
static char _exiting_nodelay = 0;
|
|
|
|
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
/**
|
|
|
|
* Init NoDelay mode
|
|
|
|
* We save old settings and prepare the TTY driver and Gambas
|
2012-06-13 17:47:00 +02:00
|
|
|
* Precisely:
|
|
|
|
* - (TTY driver:)
|
|
|
|
* - Save all related values
|
|
|
|
* - Set terminal to (ncurses) raw()-like input mode as base for NoDelay
|
|
|
|
* - Set keyboard to K_MEDIUMRAW mode to see key make and break codes
|
|
|
|
* - (Gambas:)
|
|
|
|
* - Install specific error hook
|
|
|
|
* - Reset repeater timer
|
|
|
|
* - Begin watching console fd
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
*/
|
2012-06-13 17:47:00 +02:00
|
|
|
static int NODELAY_init()
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
{
|
2012-06-13 17:47:00 +02:00
|
|
|
int fd = NODELAY_consolefd();
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
struct termios term;
|
|
|
|
|
|
|
|
if (fd == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* TODO: implement switching between vts, need available signals to
|
|
|
|
* be sent */
|
|
|
|
|
|
|
|
tcgetattr(fd, &no_delay.old.term);
|
|
|
|
ioctl(fd, KDGKBMODE, &no_delay.old.kbmode);
|
|
|
|
|
|
|
|
memcpy(&term, &no_delay.old.term, sizeof(term));
|
|
|
|
term.c_lflag &= ~(ICANON | ECHO | ISIG);
|
|
|
|
term.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);
|
|
|
|
/* Have no timeout per default */
|
|
|
|
term.c_cc[VMIN] = 0;
|
2012-06-13 17:47:00 +02:00
|
|
|
term.c_cc[VTIME] = TIMEOUT_NOTIMEOUT;
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
tcsetattr(fd, TCSAFLUSH, &term);
|
|
|
|
no_delay.old.error_hook = GB.Hook(GB_HOOK_ERROR,
|
2012-06-13 17:47:00 +02:00
|
|
|
NODELAY_error_hook);
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
no_delay.fd = fd;
|
|
|
|
|
|
|
|
no_delay.timer = NULL;
|
|
|
|
|
|
|
|
ioctl(no_delay.fd, KDSKBMODE, K_MEDIUMRAW);
|
|
|
|
|
2012-06-13 17:47:00 +02:00
|
|
|
INPUT_watch(fd);
|
|
|
|
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleanup NoDelay mode
|
2012-06-13 17:47:00 +02:00
|
|
|
* Restore old settings, see NODELAY_init() for details
|
|
|
|
* This function gets called by our error hook and the error hook is removed
|
|
|
|
* here. When removing a hook, it gets automatically called: Hence
|
|
|
|
* @_exiting_nodelay
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
*/
|
2012-06-13 17:47:00 +02:00
|
|
|
static int NODELAY_exit()
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
{
|
|
|
|
if (_exiting_nodelay)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
_exiting_nodelay = 1;
|
2012-06-13 17:47:00 +02:00
|
|
|
|
|
|
|
INPUT_watch(0);
|
|
|
|
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
ioctl(no_delay.fd, KDSKBMODE, no_delay.old.kbmode);
|
2012-06-13 17:47:00 +02:00
|
|
|
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
if (no_delay.timer)
|
|
|
|
GB.Unref((void **) &no_delay.timer);
|
2012-06-13 17:47:00 +02:00
|
|
|
|
|
|
|
GB.Hook(GB_HOOK_ERROR, no_delay.old.error_hook);
|
|
|
|
tcsetattr(no_delay.fd, TCSANOW, &no_delay.old.term);
|
|
|
|
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
close(no_delay.fd);
|
2012-06-13 17:47:00 +02:00
|
|
|
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
_exiting_nodelay = 0;
|
2012-06-13 17:47:00 +02:00
|
|
|
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The NoDelay mode error hook
|
2012-06-13 17:47:00 +02:00
|
|
|
* This calls the former error hook, saved by NODELAY_init() to not
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
* disturb any piece code
|
|
|
|
*/
|
2012-06-13 17:47:00 +02:00
|
|
|
static void NODELAY_error_hook()
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
{
|
|
|
|
if (_exiting_nodelay)
|
|
|
|
return;
|
2012-06-13 17:47:00 +02:00
|
|
|
NODELAY_exit();
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
no_delay.old.error_hook();
|
|
|
|
}
|
|
|
|
|
2012-06-13 17:47:00 +02:00
|
|
|
/**
|
|
|
|
* Return if the given fd can be used with console_ioctls
|
|
|
|
* @fd: file descriptor to test
|
|
|
|
* The idea was derived from "kbd" package, getfd.c, is_a_console()
|
|
|
|
*/
|
|
|
|
static inline char NODELAY_is_cons(int fd)
|
|
|
|
{
|
|
|
|
char type;
|
|
|
|
|
|
|
|
if (fd != -1 && isatty(fd) && ioctl(fd, KDGKBTYPE, &type) != -1
|
|
|
|
&& (type == KB_101 || type == KB_84))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an fd that can be used with console_ioctls or -1 if none
|
|
|
|
* available
|
|
|
|
*/
|
|
|
|
static int NODELAY_consolefd()
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
if (NODELAY_is_cons(0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fd = open("/dev/tty", O_RDWR);
|
|
|
|
if (fd == -1)
|
|
|
|
return -1;
|
|
|
|
if (NODELAY_is_cons(fd))
|
|
|
|
return fd;
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drain NoDelay input queue
|
|
|
|
*/
|
|
|
|
static inline void NODELAY_drain()
|
|
|
|
{
|
|
|
|
tcflush(no_delay.fd, TCIFLUSH);
|
|
|
|
}
|
|
|
|
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
/**
|
|
|
|
* Return or set the repeater delay
|
|
|
|
* @val: value to set the delay to. This value must be at least 1 or an
|
|
|
|
* error is returned. If it is REPEATER_RETURN, the current value is
|
|
|
|
* returned to the caller.
|
|
|
|
* Note that this setting affects the repeater function itself, that gets
|
|
|
|
* called in this interval to generate events and the INPUT_get_nodelay()
|
|
|
|
* function which will wait to return the amount of milliseconds if it is to
|
|
|
|
* return the pressed key.
|
|
|
|
*/
|
2012-06-13 17:47:00 +02:00
|
|
|
static int NODELAY_repeater_delay(int val)
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
{
|
|
|
|
if (val == REPEATER_RETURN)
|
|
|
|
return no_delay.delay;
|
|
|
|
if (val < 1)
|
|
|
|
return -1;
|
|
|
|
no_delay.delay = (unsigned int) val;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-13 17:47:00 +02:00
|
|
|
* Post callback to insert new read event during next event loop.
|
|
|
|
* This is important because the NODELAY_repeater() gets called by the
|
|
|
|
* timer. If we raise an event from there, the event handler may destroy the
|
|
|
|
* timer we are currently in by issuing a NODELAY_change_pressed(). This has
|
|
|
|
* consequently be done outside the timer tick.
|
|
|
|
* @arg: unused
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
*/
|
2012-06-13 17:47:00 +02:00
|
|
|
static void NODELAY_post_read(intptr_t arg)
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
{
|
|
|
|
WINDOW_raise_read(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-13 17:47:00 +02:00
|
|
|
* NoDelay mode event repeater. This function is the timer callback
|
|
|
|
* Used to insert Window_Read events if there is a key pressed
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
*/
|
2012-06-13 17:47:00 +02:00
|
|
|
static int NODELAY_repeater()
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
{
|
2012-06-13 17:47:00 +02:00
|
|
|
MY_DEBUG();
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
|
|
|
|
|
2012-06-13 17:47:00 +02:00
|
|
|
if (!no_delay.pressed)
|
|
|
|
return TRUE;
|
|
|
|
GB.Post(NODELAY_post_read, 0);
|
|
|
|
return FALSE;
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-06-13 17:47:00 +02:00
|
|
|
* Return codes from NODELAY_trans_keycode()
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
TRANS_NEED_MORE = -1,
|
|
|
|
TRANS_KEY_MIN
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* States of the modifier keys that we recognise
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
MOD_NONE = 0,
|
|
|
|
MOD_SHIFT = 1,
|
|
|
|
MOD_CTRL = 2,
|
|
|
|
MOD_ALT = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
#define IS_BREAK(k) ((k) & 0x80)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Translate a keycode (or a sequence) to an ncurses compatible int
|
|
|
|
* @kc: keycode to translate
|
|
|
|
* This function returns one of the above codes. TRANS_NEED_MORE means that
|
|
|
|
* the given @kc is considered part of a multi-keycode sequence (or is a
|
|
|
|
* Shift, Control, Alt), so we need more keys which are (in first case
|
|
|
|
* likely) available without waiting from the tty driver then; in the latter
|
|
|
|
* case (modifier keys), it does not count as a keypress anyway.
|
|
|
|
* Note that after a usual tty key sequence is assembled it is passed to the
|
|
|
|
* driver to try to get an escape sequence for it. If there is no escape
|
|
|
|
* seqeuence for that key, we can simply return the plain value. Otherwise
|
|
|
|
* we exploit ncurses key_defined() routine to translate the sequence to an
|
|
|
|
* int for us. This gives an int like ncurses getch() would do.
|
|
|
|
*/
|
2012-06-13 17:47:00 +02:00
|
|
|
static int NODELAY_trans_keycode(unsigned char kc)
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
{
|
|
|
|
/* Pause/Break has the largest scancode: e1 1d 45 e1 9d c5 */
|
|
|
|
static unsigned char codes[8];
|
|
|
|
static int num = 0;
|
|
|
|
static int modifiers = MOD_NONE;
|
|
|
|
|
|
|
|
struct kbentry kbe;
|
|
|
|
struct kbsentry kbs;
|
|
|
|
register int mod;
|
|
|
|
|
2012-06-13 17:47:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
MY_DEBUG();
|
|
|
|
|
|
|
|
|
|
|
|
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
#define KEYCODE_LCTRL 0x1d
|
|
|
|
#define KEYCODE_RCTRL 0x61
|
|
|
|
#define KEYCODE_ALT 0x38
|
|
|
|
#define KEYCODE_LSHIFT 0x2a
|
|
|
|
#define KEYCODE_RSHIFT 0x36
|
|
|
|
/* Modifiers */
|
|
|
|
switch (kc) {
|
|
|
|
case KEYCODE_LCTRL:
|
|
|
|
case KEYCODE_RCTRL:
|
|
|
|
mod = MOD_CTRL;
|
|
|
|
goto apply_mod;
|
|
|
|
case KEYCODE_ALT:
|
|
|
|
mod = MOD_ALT;
|
|
|
|
goto apply_mod;
|
|
|
|
case KEYCODE_LSHIFT:
|
|
|
|
case KEYCODE_RSHIFT:
|
|
|
|
mod = MOD_SHIFT;
|
|
|
|
goto apply_mod;
|
|
|
|
default:
|
|
|
|
goto account_key;
|
|
|
|
}
|
|
|
|
apply_mod:
|
|
|
|
if (IS_BREAK(kc))
|
|
|
|
modifiers &= ~mod;
|
|
|
|
else
|
|
|
|
modifiers |= mod;
|
|
|
|
return TRANS_NEED_MORE;
|
|
|
|
|
|
|
|
account_key:
|
|
|
|
codes[num++] = kc;
|
|
|
|
/* Break key, sends make and break code together */
|
|
|
|
if (codes[0] == '\xe1') {
|
|
|
|
if (num == 6)
|
|
|
|
return KEY_BREAK;
|
|
|
|
else
|
|
|
|
return TRANS_NEED_MORE;
|
|
|
|
}
|
|
|
|
/* Keys with two keycodes, no matter, those correspond to
|
2012-06-13 17:47:00 +02:00
|
|
|
* single-keycode keys, we can safely use @kc != 0xe0 */
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
if (codes[0] == '\xe0' && num != 2)
|
|
|
|
return TRANS_NEED_MORE;
|
|
|
|
|
|
|
|
/* TODO: what to do with ctrl- ? */
|
|
|
|
|
|
|
|
/* Set table and get action code */
|
|
|
|
if (modifiers & MOD_ALT) {
|
|
|
|
if (modifiers & MOD_SHIFT)
|
|
|
|
kbe.kb_table = K_ALTSHIFTTAB;
|
|
|
|
else
|
|
|
|
kbe.kb_table = K_ALTTAB;
|
|
|
|
} else if (modifiers & MOD_SHIFT) {
|
|
|
|
kbe.kb_table = K_SHIFTTAB;
|
|
|
|
} else {
|
|
|
|
kbe.kb_table = K_NORMTAB;
|
|
|
|
}
|
|
|
|
kbe.kb_index = kc & 0x7f;
|
|
|
|
kbe.kb_value = 0;
|
|
|
|
ioctl(no_delay.fd, KDGKBENT, &kbe);
|
|
|
|
/* Has an escape sequence? */
|
2012-06-13 17:47:00 +02:00
|
|
|
kbs.kb_func = (unsigned char) kbe.kb_value;
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
ioctl(no_delay.fd, KDGKBSENT, &kbs);
|
2012-06-13 17:47:00 +02:00
|
|
|
if (kbs.kb_string[0])
|
|
|
|
return key_defined((char *) kbs.kb_string);
|
|
|
|
else
|
|
|
|
return (int) ((unsigned char) kbe.kb_value);
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the currently pressed key
|
|
|
|
* @key: current key. 0 means that no key is pressed
|
2012-06-13 17:47:00 +02:00
|
|
|
* This installs the repeater
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
*/
|
2012-06-13 17:47:00 +02:00
|
|
|
static void NODELAY_change_pressed(int key)
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
{
|
2012-06-13 17:47:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
MY_DEBUG();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* if (key == no_delay.pressed)
|
|
|
|
return;
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
if (key == 0) {
|
|
|
|
GB.Unref((void **) no_delay.timer);
|
|
|
|
} else {
|
|
|
|
no_delay.timer = GB.Every(no_delay.delay,
|
2012-06-13 17:47:00 +02:00
|
|
|
(GB_TIMER_CALLBACK) NODELAY_repeater, 0);
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
}
|
2012-06-13 17:47:00 +02:00
|
|
|
*/ no_delay.pressed = key;
|
|
|
|
//NODELAY_repeater();
|
|
|
|
WINDOW_raise_read(NULL);
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve input in NoDelay mode, using console_ioctl(4).
|
|
|
|
* If there is a key pressed and no input available on the input queue,
|
|
|
|
* the pressed key is returned.
|
|
|
|
* @timeout: timeout in milliseconds. If that timeout expires, we return 0.
|
|
|
|
* Note that @timeout can only be in the scope of deciseconds and is
|
|
|
|
* silently cut down to those.
|
|
|
|
* The Repeater Delay applies to this function, too, in that we only return
|
|
|
|
* a pressed key when we waited for that delay.
|
|
|
|
* Note carefully, that there is an emergency exit: pressing ESC thrice
|
|
|
|
* during one second will immediately abort NoDelay mode and enter CBreak.
|
|
|
|
*/
|
2012-06-13 17:47:00 +02:00
|
|
|
static int NODELAY_get(int timeout)
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
{
|
|
|
|
static char esc = 0;
|
|
|
|
struct termios old, new;
|
|
|
|
unsigned char b;
|
|
|
|
static time_t stamp;
|
|
|
|
int ret, res, num;
|
|
|
|
int key; /* This will already be ncurses compatible */
|
|
|
|
struct timeval tv1, tv2;
|
|
|
|
|
2012-06-13 17:47:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MY_DEBUG();
|
|
|
|
|
|
|
|
|
|
|
|
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
if (timeout > -1) {
|
|
|
|
gettimeofday(&tv1, NULL);
|
|
|
|
tcgetattr(no_delay.fd, &old);
|
|
|
|
memcpy(&new, &old, sizeof(new));
|
|
|
|
}
|
|
|
|
|
|
|
|
recalc_timeout:
|
|
|
|
#define USEC2MSEC(us) (us / 1000)
|
|
|
|
#define MSEC2USEC(ms) (ms * 1000)
|
|
|
|
#define MSEC2DSEC(ms) (ms / 100)
|
|
|
|
#define DSEC2MSEC(ds) (ds * 100)
|
|
|
|
#define SEC2MSEC(s) (s * 1000)
|
|
|
|
#define MSEC2SEC(ms) (ms / 1000)
|
|
|
|
|
|
|
|
if (timeout > -1) {
|
|
|
|
gettimeofday(&tv2, NULL);
|
|
|
|
timeout -= USEC2MSEC(tv2.tv_usec - tv1.tv_usec);
|
|
|
|
timeout -= SEC2MSEC(tv2.tv_sec - tv1.tv_sec);
|
|
|
|
if (timeout < 0) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set timeout */
|
|
|
|
ioctl(no_delay.fd, TIOCINQ, &num);
|
|
|
|
/* We don't need to set any timeout if there are bytes available */
|
|
|
|
if (!num && timeout > -1) {
|
|
|
|
new.c_cc[VTIME] = MSEC2DSEC(timeout);
|
|
|
|
tcsetattr(no_delay.fd, TCSANOW, &new);
|
|
|
|
gettimeofday(&tv1, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Begin reading */
|
|
|
|
if (no_delay.pressed && !num) {
|
|
|
|
usleep(MSEC2USEC(no_delay.delay));
|
|
|
|
ret = no_delay.pressed;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
/* Try to stick to the user-supplied timeout */
|
|
|
|
ioctl(no_delay.fd, TIOCINQ, &num);
|
|
|
|
if ((res = read(no_delay.fd, &b, 1)) == -1 && errno == EINTR) {
|
|
|
|
goto recalc_timeout;
|
|
|
|
} else if (res == 0) { /* Timeout expired */
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
} else { /* Got a key */
|
|
|
|
/* Emergency exit from NoDelay mode */
|
|
|
|
#define KEYCODE_ESC 0x01
|
|
|
|
if (b == KEYCODE_ESC) {
|
|
|
|
if (time(NULL) - stamp > 0)
|
|
|
|
esc = 0;
|
|
|
|
if (++esc == 3) {
|
2012-06-13 17:47:00 +02:00
|
|
|
NODELAY_exit();
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
INPUT_mode(INPUT_CBREAK);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
stamp = time(NULL);
|
|
|
|
}
|
|
|
|
/* We use ncurses keys for operations on our no_delay data */
|
2012-06-13 17:47:00 +02:00
|
|
|
if ((key = NODELAY_trans_keycode(b)) == TRANS_NEED_MORE)
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
goto recalc_timeout;
|
|
|
|
/* Ignore break codes, except when it is the currently
|
|
|
|
pressed key */
|
|
|
|
if (IS_BREAK(b)) {
|
|
|
|
if (no_delay.pressed == key)
|
2012-06-13 17:47:00 +02:00
|
|
|
// NODELAY_change_pressed(0);
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
/* Key release isn't visible to the gambas programmer
|
|
|
|
* and thus not really an event to gb.ncurses. If
|
|
|
|
* time is left, we try again reading another key */
|
|
|
|
goto recalc_timeout;
|
|
|
|
} else {
|
2012-06-13 17:47:00 +02:00
|
|
|
// NODELAY_change_pressed(key);
|
[GB.NCURSES]
* NEW: Move .Buffered and .Refresh() from Window to Screen class as Screen
reflects better that these routines affect the entire screen
* NEW: Window has a Caption property to display a caption within the border
frame; only visible when the Window has a border
* NEW: Add NoDelay input mode to Screen class (for use with caution and a
true tty). This mode lets the programmer artifically set the keyboard
repeat delay for the program (beware: still broken)
* NEW: Add IsConsole property to check if one can enter NoDelay mode
* NEW: Add Repeater property to Screen to specify keyboard repeat
delay. This specifies the minimum interval of sucessively risen Read
events and Window.Read() calls
* NEW: Rename Window.WaitKey() to .Read()
* NEW: Rename Window.Bottom() to .Lower() and .Top() to .Raise()
* NEW: Add very-visible mode for cursor, according to ncurses doc
* NEW: Window class has a new optional parameter to specify the parent
Screen, if none given, the currently active Screen is used.
* NEW: Window class does not get a default event name anymore. If the Read
event is risen and the active Window cannot raise events, the parent
Screen raises it (beware: still broken)
* NEW: Window.Border is an integer, new constants .None, .ASCII, .ACS to
choose the border look
* NEW: Cursor resides on the new location after Window.Print() now
* OPT: Remove redundant wrapping code in Print function because ncurses
waddch() does this by itself
* OPT: Stream inheritance entirely useless due to future ReadLine()
function, hence it was removed
* OPT: Remove NCurses class, it contained only component-global routines
that were moved to main module
* BUG: Turning off attributes with the Normal attribute now works
* BUG: Changes on color attributes (also on color pairs) are immediately
visible now
* BUG: Fix string argument handling in Window.Ask(), .Insert(), .Print() and
.PrintCenter()
* BUG: Newline to Window.Print() really works now and gives the desired
effect of not returning to x=0 on the next line (like ncurses does)
git-svn-id: svn://localhost/gambas/trunk@4778 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-25 23:09:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = key;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (timeout > -1)
|
|
|
|
tcsetattr(no_delay.fd, TCSANOW, &old);
|
|
|
|
return ret;
|
|
|
|
}
|