I am trying to install ncurses for ruby on windows. I have not installed ncurses before on my machine. I thought that having the "ruby devkit", it had asked for would be enough, but now I am being asked to specify options... I don't know which options to pick, or if I need to do/install other things for the gem to get installed:
C:\Ruby193\Devkit>gem install ncurses -- --ruby=C:/Ruby193/bin/ruby --without-make-prog --without-opt-dir
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing ncurses:
ERROR: Failed to build gem native extension.
C:/Ruby193/bin/ruby.exe extconf.rb --ruby=C:/Ruby193/bin/ruby --without-make-prog --without-opt-dir
C:/Ruby193/lib/ruby/1.9.1/shellwords.rb:35:in `shellsplit': undefined method `scan' for false:FalseClass (NoMethodError)
from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:2216:in `<top (required)>'
from C:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from C:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:22:in `<main>'
Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/ncurses-0.9.1 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/ncurses-0.9.1/./gem_make.out
WHAT A PAIN, I just want to get this gem installed so I can run this:
require 'curses'
cols = Curses.stdscr.maxx
msg = "random_string"
str = msg.center(msg.length + cols - msg.length - 5 - 3)
puts "<!-- #{str}-->"
Updated version:
- Get ncurses (MinGW Port): http://invisible-island.net/ncurses/
- Put it in C:\ncurses
gem install curses --platform=ruby -- --with-ncurses-dir="C:\ncurses"
- Copy the contents of C:\ncurses\bin to somewhere in your path
C:\ncurses can be any directory
I've managed to do it for ruby 2.2, which doesn't come with curses by default, but it took me a while:
- Download PDCurses from SourceForge;
- Unzip it;
- Copy it's contents to a folder where ruby can see it. I'm not sure which one I used, I think I copied it to multiple ones until it worked.
ruby -e 'puts $:'
might help;
- Install curses,
gem instal curses
. If the previous step was wrong, this will fail;
- Done :D
This method didn't work for other gems, like ffi-ncurses.
Tip: most of curses functionality comes from the Window class, which comes with curses by default.
Update: It seems like SourceForge no longer hosts NCurses binaries for Windows. This answer is effectively obsolete now. Sorry! (As of August 2015, the GNU NCurses Page lists a "new" v6.0 release, which is newer than the 0.9.1 version in my answer.)
I finally got this to work (years after I needed it ...) without Cygwin, PDCurses, or manually building the NCurses source. The instructions are available on my blog. For reference:
- Download the latest NCurses binaries (0.9.1) from SourceForge.
- Unzip the files somewhere on your machine.
- Find out where Ruby searches for libraries by running
ruby -e 'puts $:'
- Copy and paste ncurses.so and lib\ncurses.rb from the NCurses directory into the directory you picked. Place them both in the root directory.
- Run your NCurses-enabled app.
It works. Without PDCurses!
I've successfully downloaded ncurses 0.9.1 binaries from sourceforge, so the library is still available.
I then tried with both native Ruby and IronRuby 1.1.3
placing the two files (ncurses.so ncurses.rb) in
C:\Ruby\Ruby193\lib\ruby\1.9.1
gives an error with native Ruby
The specified module could not be found. - C:/Ruby/Ruby193/lib/ruby/1.9.1/ncurses.so (LoadError)
Placing them here (for IronRuby)
C:\Program Files (x86)\IronRuby 1.1\Lib\ruby\1.9.1
gives
The module was expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018)
When gem installed needs for curses lib; so at first you need to install NCurses
with your msys2
https://sourceforge.net/p/mingw-w64/wiki2/NCurses/
Download NCurses (v5.9 at the time of writing): http://ftp.gnu.org/pub/gnu/ncurses/
in the source directory
Then untar and in the MSYS shell:
./configure --host=x86_64-w64-mingw32 --enable-term-driver --enable-sp-funcs --prefix=/some/prefix
make
make check
make install
then as mentioned in the link :
https://github.com/ruby/curses/issues/13
use --platform=ruby ,--with-curses-include ,--with-curses-lib flags with gem install
The ruby ncurses gem requires that ncurses in installed on the machine. As far as I know ncurses has not been ported to windows. So I don't think you are going to get this to work.
There may be other ways to find out how wide the screen is on windows but I can't help you with that.