Permalink
Browse files

Merge pull request #464 from be-red/master

Update for wide-chars. Panel librairy and example added.
  • Loading branch information...
2 parents 5be02bb + 7f09606 commit f1dc5d5570a75acb8ea6ccbfcd46407f2678215b @dockimbel dockimbel committed Apr 9, 2013
@@ -1,46 +1,57 @@
Curses library for Red/System
------------------------
-This is a low level binding for Curses library.
+This is a low level binding for Curses and Panel libraries.
+
+Curses for Red/System now uses wide-characters library (libncursesw.so).
Requirements
------------
* **Linux**
- *libncurses 5.9* : avaliable with your favorite distro.
+ *libncursesw 5.9* : avaliable with your favorite distro.
+
+ *libpanelw 5.9* : avaliable with your favorite distro.
* **Windows**
- *pdcurses.dll* : [Public Domain Curses for windows](http://sourceforge.net/projects/pdcurses/files/), version 3.4 : [pdc34dllw.zip](http://sourceforge.net/projects/pdcurses/files/pdcurses/3.4/pdc34dllw.zip/download)
+ *pdcurses.dll* : [Public Domain Curses for windows](http://sourceforge.net/projects/pdcurses/files/), version 3.4 : [pdc34dllu.zip](http://sourceforge.net/projects/pdcurses/files/pdcurses/3.4/pdc34dllu.zip/download)
+
+ The panel library is include in PDCurses.
* **MacOSX**
Help needed to check the right library name, write `%curses-macosx.reds` (may be identical to `%curses-linux.reds`) and test.
-Running the Red/System curses-example
+Running the Red/System curses examples
------------------------
+1. This binding is provided with two examples for curses and panel libraries.
+
1. From the REBOL console type :
`change-dir %red-system`
`do/args %rsc.r "%library/curses/examples/curses-example.reds"`, the compilation process should finish with a `...output file size` message.
+ `do/args %rsc.r "%library/curses/examples/panel-example.reds"`, the compilation process should finish with a `...output file size` message.
+
1. From command line, use the REBOL compilation script :
`cd red-system/library/builds/curses/examples`
- `rebol -s compile-curses-example.r` Linux
+ `rebol -s compile-examples.r` Linux
or
- `rebol.exe -s compile-curses-example.r` Windows
+ `rebol.exe -s compile-examples.r` Windows
+ This script buid all examples included in this directory.
-1. The resulting binary is in `red-system/builds/`, go try it!
+1. The resulting binaries are in `red-system/builds/`, go try them!
- Linux users run `curses-example` from command line.
+ Linux users run `curses-example` or `panel-example` from command line.
- Windows users need to open a DOS console and run `curses-example.exe` from there.
+ Windows users need to open a DOS console and run `curses-example.exe` or `panel-example.exe` from there.
@@ -1,7 +1,8 @@
Red/System [
- Title: "Linux Curses binding constant"
+ Title: "Linux Red/System Curses binding constant"
Author: "Bruno Anselme"
EMail: "be.red@free.fr"
+ File: %curses-linux.reds
Rights: "Copyright (c) 2013 Bruno Anselme"
License: {
Distributed under the Boost Software License, Version 1.0.
@@ -150,4 +151,14 @@ Red/System [
KEY_EVENT: 019Bh ; We were interrupted by an event
KEY_MAX: 01FFh ; Maximum key value is 019Bh
+
+ ; Not included in Linux curses.h. Added manually with Windows constant names.
+ CTL_UP: 0236h ; ctl-up arrow
+ CTL_DOWN: 020Dh ; ctl-down arrow
+ CTL_LEFT: 0221h ; Control-Left-Arrow
+ CTL_RIGHT: 0230h
+ CTL_PGUP: 022Bh
+ CTL_PGDN: 0226h
+ CTL_HOME: 0217h
+ CTL_END: 0207h
]
@@ -1,7 +1,8 @@
Red/System [
- Title: "Windows Curses binding constant"
+ Title: "Windows Red/System Curses binding constant"
Author: "Bruno Anselme"
EMail: "be.red@free.fr"
+ File: %curses-win32.reds
Rights: "Copyright (c) 2013 Bruno Anselme"
License: {
Distributed under the Boost Software License, Version 1.0.
@@ -302,4 +303,4 @@ Red/System [
KEY_MIN: KEY_BREAK ; Minimum curses key value
KEY_MAX: KEY_SDOWN ; Maximum curses key
- ]
+ ]
@@ -2,6 +2,7 @@ Red/System [
Title: "Red/System curses Binding"
Author: "Bruno Anselme"
EMail: "be.red@free.fr"
+ File: %curses.reds
Rights: "Copyright (c) 2013 Bruno Anselme"
License: {
Distributed under the Boost Software License, Version 1.0.
@@ -21,6 +22,23 @@ Red/System [
curses: context [
+ #define __LC_CTYPE 0
+ #define __LC_ALL 6
+ #import [
+ LIBC-file cdecl [
+ setlocale: "setlocale" [
+ category [integer!]
+ locale [c-string!]
+ return: [c-string!]
+ ]
+ find-str: "strstr" [ ; Return first occurence of target in src or null if not found
+ src [c-string!]
+ target [c-string!]
+ return: [c-string!]
+ ]
+ ]
+ ]
+
#define window! integer!
#define sysfile! integer!
@@ -30,12 +48,12 @@ curses: context [
#define curses-library "pdcurses.dll"
]
MacOSX [
- #include %curses-macosx.reds ; TODO: missing file, to be written with macosx curses.h
- #define curses-library "libncurses.5.dylib" ; TODO: check this
+ #include %curses-macosx.reds ; TODO: missing file, to be written with macosx curses.h
+ #define curses-library "libncursesw.5.dylib" ; TODO: check this
]
#default [
#include %curses-linux.reds
- #define curses-library "libncurses.so.5"
+ #define curses-library "libncursesw.so.5"
]
]
@@ -56,6 +74,10 @@ curses: context [
wid [window!]
return: [integer!]
]
+ wnoutrefresh: "wnoutrefresh" [ ; Mark window to be refreshed
+ wid [window!]
+ return: [integer!]
+ ]
doupdate: "doupdate" [ ; Update terminal.
return: [integer!]
]
@@ -80,15 +102,6 @@ curses: context [
echo-off: "noecho" [ ; Disable terminal echo.
return: [integer!]
]
- echochar: "echochar" [ ; Echo single-byte character and rendition to screen and refresh.
- ch [integer!]
- return: [integer!]
- ]
- wechochar: "wechochar" [ ; Echo single-byte character and rendition to a window and refresh.
- wid [window!]
- ch [integer!]
- return: [integer!]
- ]
; Window management
@@ -261,10 +274,6 @@ curses: context [
col [integer!]
return: [integer!]
]
- ungetch: "ungetch" [ ; Push a character onto the input queue.
- ch [integer!]
- return: [integer!]
- ]
getnstr: "getnstr" [ ; Get almost n bytes from input.
str [c-string!]
n [integer!]
@@ -337,7 +346,16 @@ curses: context [
; Print to screen
- addch: "addch" [ ; Put character from current cursor position inside stdscr.
+ echochar: "echochar" [ ; Echo wide-character and immediately refresh the screen.
+ ch [integer!]
+ return: [integer!]
+ ]
+ wechochar: "wechochar" [ ; Echo wide-character and immediately refresh the window.
+ wid [window!]
+ ch [integer!]
+ return: [integer!]
+ ]
+ addch: "addch" [ ; Put wide-character from current cursor position inside stdscr.
ch [integer!]
return: [integer!]
]
@@ -350,7 +368,7 @@ curses: context [
str [c-string!]
return: [integer!]
]
- waddch: "waddch" [ ; Put character from current cursor position into window.
+ waddch: "waddch" [ ; Put wide-character from current cursor position into window.
wid [window!]
ch [integer!]
return: [integer!]
@@ -545,6 +563,7 @@ curses: context [
return: [integer!]
]
wclrtoeol: "wclrtoeol" [ ; Erase the current line from the cursor to the end of the line inside the specified window
+ wid [window!]
return: [integer!]
]
clrtobot: "clrtobot" [ ; Clear all lines following the cursor.
@@ -911,6 +930,11 @@ curses: context [
isendwin: "isendwin" [ ; Determine whether a screen has been refreshed.
return: [logic!]
]
+ ripoffline: "ripoffline" [ ; Reserves a screen line for use by the application.
+ line [integer!]
+ init [integer!] ; pointer on init: function [ [cdecl] wid [integer!] cols [integer!]
+ return: [integer!]
+ ]
def-prog-mode: "def_prog_mode" [ ; Saves the current terminal modes as the "program" (in Curses) state for use by reset_prog_mode.
return: [integer!]
@@ -927,7 +951,22 @@ curses: context [
baudrate: "baudrate" [ ; Returns the output speed of the terminal in bits per second.
return: [integer!]
]
-
+ #switch OS [
+ Windows [
+ ungetch: "PDC_ungetch" [ ; Push a character onto the input queue.
+ ch [integer!]
+ return: [integer!]
+ ]
+ ]
+ MacOSX [
+ ]
+ #default [
+ ungetch: "ungetch" [ ; Push a character onto the input queue.
+ ch [integer!]
+ return: [integer!]
+ ]
+ ]
+ ] ; #switch OS
] ; cdecl
] ; #import [curses-library
@@ -951,59 +990,96 @@ curses: context [
return stdscr
]
- color-set: function [ ; Set terminal color pair
+ color-set: function [ "Set terminal color pair"
pair [integer!]
][
_color_set pair 0
]
- wcolor-set: function [ ; Set window color pair
+ wcolor-set: function [ "Set window color pair"
wid [window!]
pair [integer!]
][
_wcolor_set wid pair 0
]
- getch: function [ ; Wait for user input. Not avaliable on Windows, so redefined here
- return: [integer!]
+ getch: function [ "Wait for user input. Not avaliable on Windows, so redefined here"
+ return: [integer!]
][
return wgetch stdscr
]
- printw-attr: function [ ; printw surrounded by attribute on/off
+ printw-attr: function [ "printw surrounded by attribute on/off"
attr [integer!]
txt [c-string!]
- return: [integer!]
][
attron attr
printw [ txt ]
attroff attr
]
- wprintw-attr: function [ ; wprintw surrounded by attribute on/off
+ wprintw-attr: function [ "wprintw surrounded by attribute on/off"
wid [window!]
attr [integer!]
txt [c-string!]
- return: [integer!]
][
wattron wid attr
wprintw [ wid txt ]
wattroff wid attr
]
- color-pair: func [
- pair [integer!]
- return: [integer!]
+ mvwprintw-attr: function [ "wprintw surrounded by attribute on/off"
+ wid [window!]
+ row [integer!]
+ col [integer!]
+ attr [integer!]
+ txt [c-string!]
+ ][
+ wmove wid row col
+ wattron wid attr
+ wprintw [ wid txt ]
+ wattroff wid attr
+ ]
+ color-pair: function [
+ pair [integer!]
+ return: [integer!]
][
return (pair << PDC_COLOR_SHIFT) and A_COLOR
]
- pair-number: func [
- pair [integer!]
- return: [integer!]
+ pair-number: function [
+ pair [integer!]
+ return: [integer!]
][
return (pair and A_COLOR) >> PDC_COLOR_SHIFT
]
+ _top_line: 0 ; Pointer to top line window
+ _bottom_line: 0 ; Pointer to bottom line window
+ _top_cols: 0 ; Number of columns in top line window
+ _bottom_cols: 0 ; Number of columns in bottom line window
+
+ init-top-line: function [ "Callback function for ripoffline"
+ [cdecl]
+ wid [window!]
+ cols [integer!]
+; return: [int-ptr!]
+ ][
+ _top_line: wid
+ _top_cols: cols
+; return 0
+ ]
+
+ init-bottom-line: function [ "Callback function for ripoffline"
+ [cdecl]
+ wid [window!]
+ cols [integer!]
+; return: [int-ptr!]
+ ][
+ _bottom_line: wid
+ _bottom_cols: cols
+; return 0
+ ]
+
; Test interface --------------------------------------------------------------------
init-screen: func [
@@ -1030,5 +1106,17 @@ curses: context [
return scr
]
+ locale: ""
+ UTF-8: false
+ #switch OS [
+ Windows [
+ ]
+ #default [
+ locale: setlocale __LC_ALL "" ;@@ check if "utf8" is present in returned string?
+ if null <> find-str locale "UTF-8" [
+ UTF-8: true
+ ]
+ ]
+ ] ; #switch OS
] ; with curses
] ; context curses
Oops, something went wrong.

0 comments on commit f1dc5d5

Please sign in to comment.