Set a window's background color in Ruby curses

三世轮回 提交于 2019-12-24 10:48:11

问题


Trying to add a background to a curses window. I have these two properties

I've found these two methods:

bkgd(ch)

and

bkgdset(ch)

However, I can't implement them:

win1.new(10,10,10,10)
win1.box('|','-')
win1.bkg(COLOR_RED) 

This fills win1 with a load of diamonds! Very insteresting effect but not what I wanted. I want a red background.

Colors work perfectly in my terminal.


回答1:


It's been a while, but maybe my examples are still useful:

It is the same "diamonds" for me when using

window.bkgd(COLOR_RED)

This seems to appear, because the bkgd method takes a char and prints it to all free spaces of the window (see old doc).

However, then you can use a color pair with the wanted background color and apply it to all screen positions before writing oher stuff.

Here is how I solved it:

require 'curses'    

init_screen
start_color

init_pair(COLOR_RED, COLOR_WHITE, COLOR_RED)
window = Curses::Window.new(0, 0, 0, 0)

window.attron(color_pair(COLOR_RED)) do
  lines.times do |line|
    window.setpos(line, 0)
    window << ' ' * cols
  end
end


来源:https://stackoverflow.com/questions/19438195/set-a-windows-background-color-in-ruby-curses

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!