红宝石诅咒颜色
如何使用 Ruby 的默认 Curses 库获取颜色?
所以类似:
puts "\e[0m\e[30;47mtest\e[0m"
效果很好。在浅灰色背景上呈现漂亮的黑色。但这:
#!/usr/bin/env ruby
require 'curses'
Curses.noecho # do not show typed keys
Curses.init_screen
Curses.stdscr.keypad(true) # enable arrow keys (for pageup/down)
Curses.stdscr.nodelay = 1
Curses.clear
Curses.setpos(0,0)
Curses.addstr "Hello!"
Curses.addstr "\e[0m\e[30;47mHello!\e[0m"
显示:
你好!
^[[0米^[[30;47米你好!^[[0米
最终,我需要为此的颜色:
require 'curses'
Curses.noecho # do not show typed keys
Curses.init_screen
Curses.stdscr.keypad(true) # enable arrow keys (required for pageup/down)
loop do
case Curses.getch
when Curses::Key::PPAGE
Curses.setpos(0,0)
Curses.addstr("Page Up")
when Curses::Key::NPAGE
Curses.setpos(0,0)
Curses.addstr("Page Dn")
end
end
How can I get colors with Ruby's default Curses library?
So something like:
puts "\e[0m\e[30;47mtest\e[0m"
works great. Gives a nice black on light gray background. But this:
#!/usr/bin/env ruby
require 'curses'
Curses.noecho # do not show typed keys
Curses.init_screen
Curses.stdscr.keypad(true) # enable arrow keys (for pageup/down)
Curses.stdscr.nodelay = 1
Curses.clear
Curses.setpos(0,0)
Curses.addstr "Hello!"
Curses.addstr "\e[0m\e[30;47mHello!\e[0m"
Displays:
Hello!
^[[0m^[[30;47mHello!^[[0m
Ultimately, I need colors for this:
How to capture a key press in Ruby?
require 'curses'
Curses.noecho # do not show typed keys
Curses.init_screen
Curses.stdscr.keypad(true) # enable arrow keys (required for pageup/down)
loop do
case Curses.getch
when Curses::Key::PPAGE
Curses.setpos(0,0)
Curses.addstr("Page Up")
when Curses::Key::NPAGE
Curses.setpos(0,0)
Curses.addstr("Page Dn")
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ruby源代码中有curses用法的示例,请参见,例如此处。
你的代码可能是这样的:
There are examples of curses usage in the ruby source code, see, e.g. here.
Your code could be something like: