如何使用 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"
显示:
你好!
^[[0m^[[30;47m你好!^[[0m
最终,我需要颜色:
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