如何在 Ruby 中使用 (n)curses?
我想创建一个进度条来指示 Ruby 中的批处理作业的状态。
我读过一些 教程 / 使用 (n)curses 的库,其中没有一个对于解释如何在终端中创建“动画”进度条或在Ruby
中使用curses特别有帮助。
我已经知道使用单独的线程来监视给定作业的进度,我只是不确定如何继续绘制进度条。
更新
ProgressBar 类非常简单,完美解决了我的问题。
I'd like to create a progress bar to indicate the status of an a batch job in Ruby
.
I've read some tutorials / libraries on using (n)curses, none of which were particularly helpful in explaining how to create an "animated" progress bar in the terminal or using curses with Ruby
.
I'm already aware of using a separate thread to monitor the progress of a given job, I'm just not sure how to proceed with drawing a progress bar.
Update
ProgressBar class was incredibly straight-forward, perfectly solved my problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 Windows 上,curses 可以开箱即用,而 ncurses 则不然,对于进度条,curses 应该足够了。 因此,使用curses 而不是ncurses。
此外,curses 和 ncurses 都是 C 库的薄包装器 - 这意味着您实际上并不需要特定于 Ruby 的教程。
但是,在 PickAxe 站点上,您可以下载本书的所有代码示例。 文件“ex1423.rb”包含一个 Curses 演示,可以玩 Pong - 这应该为您提供足够的材料来帮助您前进。
On windows, curses works out of the box, ncurses doesn't, and for a progress bar curses should be sufficient. So, use curses instead of ncurses.
Also, both curses and ncurses are wafer-thin wrappers around the c library - that means you don't really need Ruby-specific tutorials.
However, on the site for the PickAxe you can download all the code examples for the book. The file "ex1423.rb" contains a curses demo which plays Pong - that should give you plenty of material to get you going.
我个人认为在这种情况下诅咒是多余的。 虽然curses 库很好(我自己也经常使用它),但每当我12 个月不再需要它时,它就是一个需要重新学习的PITA,这一定是糟糕的界面设计的标志。
如果由于某种原因你无法继续使用 Joey 建议的进度条库,请自行推出并在相当免费的许可证,立即获得荣誉:)
Personally I think curses is overkill in this case. While the curses lib is nice (and I frequently use it myself) it's a PITA to relearn every time I haven't needed it for 12 months which has to be the sign of a bad interface design.
If for some reason you can't get on with the progress bar lib Joey suggested roll your own and release it under a pretty free licence for instant kudos :)
您也许可以从 Ruby/ProgressBar 库 获得一些实现思路,它生成文本进度条。 几个月前我偶然发现了它,但还没有使用它。
You might be able to get some implementation ideas from the Ruby/ProgressBar library, which generates text progress bars. I stumbled across it a couple of months back but haven't made any use of it.
回答很晚,对自我推销感到抱歉,但我创建了 库 来在终端中显示进度。
Very late answer and sorry for self promotion, but I created library to show progress in terminal.