OSX 10.5.x + PHP + pecl_ncurses
Geschrieben von Harald Lapp in PHP um 15:32
After several days playing around with newt i am quite disappointed to come to a point where i have to say, that newt has not only a very limited documentation (i think there's only documentation of about 50% of the newt functionality) -- which would not be that of a problem, though. The bigger problem is, that things are very unstable. "Segmentation faults" reproducable on different operating systems and platforms -- not sure though, if the problem is newt or pecl_newt. However: this is definitly not what i want. So, let's move on to something better.
I had a look at the apple's opensource repository the other day and stumbled over a ncurses package. I had problems with the normal gnu ncurses package before, it would not install but hang when building the terminfo database. With the ncurses package i found at apple's opensource repository, i get it to install. Here is the howto:
Note: The first three steps below are for osx 10.5.x. For osx 10.6.6 simply download ncurses 5.7 and build it using ./configure --with-shared.
- Download ncurses from apple's opensource repository. You can find it by clicking on the link of the Mac OSX version you are running, eg. 10.5.8.
- Unpack the package und you get a directory called something like "ncurses-21" or so. Next cd into this direktory and run make and sudo make install. If make complains about a missing directory /tmp/ncurses/Build, just create it mkdir -p /tmp/ncurses/Build and start again.
- Now an intermediate build should have been generated. Next cd /tmp/ncurses/Build, make and sudo make install. Now ncurses should have been successfully installed.
- Ready to install the ncurses php extension by either executing sudo pecl install ncurses or downloading ncurses from pecl.php.net and building manually.
- Don't forget to add ncurses.so to your php.ini
Now everything should be ready to start writing ncurses apps -- however: for me it sill did not work. The simplest ncurses app resultet in the following error message:
Error opening terminal: vt100.
What's going on? dtruss might be your friend to figure this out. Execute the following command, where example.php is your ncurses app you want to run: sudo dtruss php example.php. You should see output like:
[...]
lstat("/Users/harald\0", 0xBFFFE41C, 0xFFFFFFFFBFFFEFC8) = 0 0
lstat("/Users\0", 0xBFFFE2EC, 0xFFFFFFFFBFFFEFC8) = 0 0
ioctl(0x3, 0x4004667A, 0xBFFFF17C) = -1 Err#25
ioctl(0x3, 0x402C7413, 0xBFFFF150) = -1 Err#25
fstat(0x3, 0xBFFFF1B0, 0xBFFFF150) = 0 0
mmap(0x0, 0x226, 0x1, 0x2, 0x3, 0x100000000) = 0x17FA000 0
lseek(0x3, 0x0, 0x1) = 518 0
munmap(0x17FA000, 0x1F3) = 0 0
close_nocancel(0x3) = 0 0
ioctl(0x1, 0x4004667A, 0xBFFFECEC) = 0 0
stat("/Users/harald/.terminfo\0", 0xBFFFEC00, 0xBFFFECEC) = 0 0
access("/Users/harald/.terminfo/73/vt100\0", 0x4, 0xBFFFECEC) = -1 Err#2
stat("/usr/local/share/terminfo\0", 0xBFFFEC00, 0xBFFFECEC) = -1 Err#2
write_nocancel(0x2, "Error opening terminal: vt100.\n\0", 0x24) = 36 0
You can see, that ncurses is looking for a file vt100 in a terminfo directory and fails looking at /usr/local/share/terminfo. I indeed had no directory /usr/local/share/terminfo but a directory /usr/share/terminfo. I was not able to figure out, where i could specify the correct directory configuration for this, so i just created a symlink: sudo ln -snf /usr/share/terminfo /usr/local/share/terminfo. After creating the symlink, i was able to execute my example ncurses application.
OSX 10.5.x + PHP + pecl_newt
Geschrieben von Harald Lapp in PHP um 16:05
I always wanted to provide nice user interfaces for some of my commandline tools written in PHP, but was not able to solve one problem until recently. The big problem when writing user interfaces for commandline utilities written in PHP is: ... what library to use for actually building the user interface?
You could try to write your own library using ANSI escape sequences -- but your user interfaces would either be very limited or it would be a hell of work to write an extensive library providing more than just the basics.
You could try to get the ncurses extension to work -- i failed.
You could try to get the newt extension to work -- i failed ...
... until recently. Every once in a while i tried to dig up more information of how to get newt to work, because this is the library i would prefer over the other solutions. However, it did not compile on my system. Recently i searched again and was able to dig up a patch for newt-0.5.22.11. So, here are the steps to get things work:
Download newt 0.52.11 and extract it.
Download the patch for newt from the page above and apply it as described in the short tutorial provided on that page.
Download slang, which is required by newt. I decided to download the latest snapshot (pre2.2.3-60) and things worked just fine with it. Extract and build it -- i did not use any special flags for this.
Download popt, which is required for newt. I decided to download popt-1.16, which seems to be the latest release and can be found at the bottom of the download page. Extract and build it -- i did not use any special flags for this.
After installing slang and popt and patching newt, you should now be able to build and install newt.
Download pecl_newt, or install it using pecl install .... Don't forget to add newt.so to your php.ini.
pecl_newt provides some examples which should be executed to verify, that installation succeeded.




