在Windows上安装Ruby的ncurses

5

我正在尝试在Windows上为Ruby安装ncurses。 我之前没有在我的电脑上安装过ncurses。 我认为安装"ruby devkit"就足够了,但现在我被要求指定选项......我不知道该选择哪些选项,或者是否需要进行/安装其他操作才能安装gem:

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

真是太麻烦了,我只想安装这个宝石,这样我就可以运行这个程序:

require 'curses'
cols = Curses.stdscr.maxx
msg = "random_string"
str = msg.center(msg.length + cols - msg.length - 5 - 3)
puts "<!-- #{str}-->"
7个回答

3

更新版本:

  1. 获取ncurses(MinGW版本):http://invisible-island.net/ncurses/
  2. 将它放在C:\ncurses中
  3. gem install curses --platform=ruby -- --with-ncurses-dir="C:\ncurses"
  4. 将C:\ncurses\bin的内容复制到你的路径中的某个位置

C:\ncurses可以是任何目录


0

更新:看起来SourceForge不再为Windows托管NCurses二进制文件。这个答案已经过时了。很抱歉!(截至2015年8月,GNU NCurses Page列出了一个“新”的v6.0版本,比我答案中的0.9.1版本要新。)

我终于在不使用Cygwin、PDCurses或手动构建NCurses源代码的情况下使其正常工作(几年之后...)。有关说明可在我的博客上找到。供参考:

  • SourceForge下载最新的NCurses二进制文件(0.9.1)。
  • 在您的计算机上某个地方解压缩文件。
  • 运行ruby -e 'puts $:'查找Ruby搜索库的位置。
  • 从NCurses目录中复制并粘贴ncurses.so和lib\ncurses.rb到您选择的目录中。将它们都放在根目录中。
  • 运行启用了NCurses的应用程序。

它可以工作。没有PDCurses!


链接失效:您的博客链接已失效。 - Nisanio
@Nisanio 这个回答中应该有足够的信息。我的博客确实已经荒废了很久。 - ashes999
源Forge的链接已经失效。答案已无法找到。 - SlySherZ
@SlySherZ 我相信你可以通过谷歌搜索找到 NCurses 0.9.1 的二进制文件。顺便提一下,GNU 已经发布了 NCurses 6.0 版本。请参考此链接 - ashes999
@ashes999 谢谢!我已经找到了,但是花费的时间比我想象中要长 :D - SlySherZ
没有ncurses 0.9.1(也没有pdcurses)。 - Thomas Dickey

0

我已经成功地在 Ruby 2.2 上实现了它,但是默认情况下它不带 curses,这花费了我一些时间:

  • SourceForge 下载 PDCurses
  • 解压它;
  • 将其内容复制到 Ruby 可以看到的文件夹中。我不确定我使用了哪一个,我认为我将其复制到多个文件夹中,直到它起作用。 ruby -e 'puts $:' 可能会有所帮助;
  • 安装 curses,gem instal curses。如果前面的步骤出错了,这一步将失败;
  • 完成 :D

这种方法对于其他 gem(如 ffi-ncurses)并不适用。 提示:大多数 curses 功能来自 Window 类,该类默认带有 curses。


请修正此答案中的拼写错误。 - anon

0

当您安装gem时需要curses库,因此首先需要在msys2上安装NCurses

https://sourceforge.net/p/mingw-w64/wiki2/NCurses/

下载NCurses(目前版本为v5.9):http://ftp.gnu.org/pub/gnu/ncurses/,并将其放置在源代码目录中。

然后在MSYS shell中解压缩:

./configure --host=x86_64-w64-mingw32 --enable-term-driver --enable-sp-funcs --prefix=/some/prefix

make

make check

make install

接下来按照链接中提到的方法进行操作: https://github.com/ruby/curses/issues/13

使用gem install命令时,加上--platform=ruby、--with-curses-include和--with-curses-lib标志。


0

截至2020年2月(可能更早),您可以使用以下命令安装ncurses库:

gem install curses

它在Ruby 2.6.5上运行没有任何问题。


-1

我已经成功从sourceforge下载了ncurses 0.9.1 binaries,因此该库仍然可用。

然后我尝试使用本机Ruby和IronRuby 1.1.3

  1. 将两个文件(ncurses.so ncurses.rb)放在

    C:\ Ruby \ Ruby193 \ lib \ ruby \ 1.9.1

    会导致本机Ruby出错

    指定的模块无法找到-C:/ Ruby / Ruby193 / lib / ruby / 1.9.1 / ncurses.so(LoadError)

  2. 将它们放在这里(适用于IronRuby) C:\Program Files(x86)\ IronRuby 1.1\Lib\ruby\1.9.1

    会报告

    模块应包含程序集清单。(来自HRESULT的异常:0x80131018)


压缩文件中的库不是ncurses,而是pdcurses,有人将其重命名以简化工作。自2011年以来,已经有一个针对mingw的ncurses端口,但Ruby的打包者尚未意识到这一点。 - Thomas Dickey
这不是一个答案。 - Redoman

-1

Ruby ncurses gem需要在计算机上安装ncurses。据我所知,ncurses尚未移植到Windows。因此,我认为您无法使其正常工作。

可能有其他方法可以找出Windows屏幕的宽度,但我无法帮助您解决这个问题。


require "io/console"; rows, cols = STDIN.winsize - steenslag

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接