The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

XAS::Lib::Curses::Win32 - A mixin for handling PDCurses issues on Win32

DESCRIPTION

Who in there right minds would want to run Curses on Windows? I guess I did. To start with you need to download and install PDCurses. You can get that here:

  http://sourceforge.net/projects/pdcurses/files/pdcurses/3.4/

You want the pdc34dllw.zip file. This is compatible with current release of Curses.pm. The package from the GnuWin32 site is not. To install, do the following:

 1) Unpack the zip archive.

 2) Copy the .h files to \strawberry\c\include

 3) Copy the .lib file to \strawberry\c\lib

 4) copy the .dll file to \strawberry\c\bin

That's it, PDCurses is now installed. Now for the fun part. Actually making it work correctly with Curses.pm. Start by downloading it from CPAN. Do not do a default install.

Curses.pm is designed to be used with Ncurses. Which is a standard install on most Linuxes and some Unixes. PDCurses is "compatible" with Ncurses, with the exception of the mouse handling functions.

PDCurses supports the Ncurses mouse handling and an older set of SYSV mouse handling routines. The problem lies with the getmouse() call. This is a name clash with the Ncurses routine of the same name. PDCurses solves this by providing a nc_getmouse() call. Curses.pm doesn't check for this function, only getmouse() which exists, but has a different call interface. So the mouse doesn't work.

To fix this problem you need to edit some files. Start with list.syms and add the following line around the getmouse(0) line.

"E nc_getmouse(0)"

Next change some code in CursesFun.c. Replace the original code for the XS_Curses_getmouse with this:

 XS(XS_Curses_getmouse)
 {
     dXSARGS;
 #ifdef C_GETMOUSE
     c_exactargs("getmouse", items, 1);
     {
     MEVENT *event   = (MEVENT *)sv_grow(ST(0), 2 * sizeof(MEVENT));
     int ret = getmouse(event);
     c_setmevent(ST(0));
     ST(0) = sv_newmortal();
     sv_setiv(ST(0), (IV)ret);
     }
     XSRETURN(1);
 #elif defined C_NC_GETMOUSE
     c_exactargs("getmouse", items, 1);
     {
     MEVENT *event   = (MEVENT *)sv_grow(ST(0), 2 * sizeof(MEVENT));
     int ret = nc_getmouse(event);
     c_setmevent(ST(0));
     ST(0) = sv_newmortal();
     sv_setiv(ST(0), (IV)ret);
     }
     XSRETURN(1);
 #else
     c_fun_not_there("getmouse");
     XSRETURN(0);
 #endif
 }

This will allow Curses.pm to access the correct getmouse() function call. Now you need to build Curses.pm. You do this in the usually fashion.

 > perl Makefile.PL PANELS
 > dmake
 > dmake test
 > dmake install

 Note: You need the "PANELS" qualifier. Curses.pm will build without it, but it
 will automatically find the panel routines in PDCurses. Doing so, without the
 qualifier, will cause Perl to crash.

At this point, you have a fully functional curses on Windows.

METHODS

In the following methods: $kernel, $session, $heap are standard variables from POE.

startup($kernel, $session, $heap)

This will initialize the screen, keyboard and turn on mouse handling. It will also start the polling task for getch().

keyin($kernel)

Read the keyboard with getch() and reschedule the poll.

get_mouse_event

The will parse the mouse event and return the following variables.

$id

This is the id of the event, this is always 0.

$x

The position of the mouse on the X plain of the screen.

$y

The position of the mouse on the Y plain of the screen.

$z

Not, sure, but it is always 0.

$bstate

The state of the mouse.

handle_mounse_event($id, $x, $y, $z, $bstate, $heap)

This will take $id, $x, $y, $z, $bstate and $heap variable and create the appropriate event to dispatch within Curses::Toolkit.

SEE ALSO

XAS
Curses::Toolkit

AUTHOR

Kevin L. Esteb, <kevin@kesteb.us>

COPYRIGHT AND LICENSE

Copyright (C) 2014 Kevin L. Esteb

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

See http://dev.perl.org/licenses/ for more information.