ruby / curses

Ruby binding for curses, ncurses, and PDCurses. Formerly part of the ruby standard library.
Other
296 stars 34 forks source link

Use NUM2CHTYPE()/CHTYPE2NUM() in window_attron/attroff/attrset/color_pair? #76

Open bashirley opened 2 years ago

bashirley commented 2 years ago

Hi, on mingw Ruby26-x64, on Windows 7, using curses-1.4.4 and the statically-linked default PDCurses, attron(color_pair(n)) doesn't have any effect, and I only get the default gray-on-black, from this example:

require 'curses'
include Curses
init_screen
start_color
init_pair(6, COLOR_BLUE, COLOR_RED)
attron(color_pair(6)) do
  setpos(5,5)
  addstr('this should be in blue on red')
end
getch
close_screen

It looks like PDCurses is compiled in 64-bit chtype mode by default, and the color bits are shifting off the end of a regular 32-bit long and getting truncated in window_attron(), window_attroff(), window_attrset(), and curses_color_pair() by the INT2FIX()/NUM2INT() macros.

Replacing these macros with NUM2CHTYPE() and CHTYPE2NUM() in the color/attr functions seems to resolve the problem and the example above works as expected.