Forum: Ruby-core [ruby-trunk - Bug #8659][Open] Curses::Window#bkgdset does not handle color correctly

Abe2880c92f9009aa7a16fb0a03015de?d=identicon&s=25 inferiorhumanorgans (Alex Zepeda) (Guest)
on 2013-07-20 08:55
(Received via mailing list)
Issue #8659 has been reported by inferiorhumanorgans (Alex Zepeda).

----------------------------------------
Bug #8659: Curses::Window#bkgdset does not handle color correctly
https://bugs.ruby-lang.org/issues/8659

Author: inferiorhumanorgans (Alex Zepeda)
Status: Open
Priority: Normal
Assignee:
Category: ext
Target version:
ruby -v: ruby 1.9.3p385 (2013-02-06 revision 39114)
[x86_64-darwin12.2.1]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


=begin
Colors in curses are handled as high bits on a character.  Logically
ORing a character with a color pair should allow bkgdset to configure a
colored background.  This can be seen in the source for the Python
curses module.  The Python function takes one or two arguments (color +
character).  If there are two arguments they are ORed together and
passed to curses as such.  Back in ruby land, with one argument it
should be possible to specify a background color for the whole screen
thusly:

 # Define a color pair
 Curses.init_pair(1, Curses::COLOR_GREEN, Curses::COLOR_BLUE)
 # Set the screen background to blue
 Curses.bkgdset(' '.ord | Curses.color_pair(1))

The following:

 #!/usr/bin/env ruby

 require 'curses'

 Curses.init_screen
 Curses.start_color

 Curses.init_pair(1, Curses::COLOR_YELLOW, Curses::COLOR_BLUE)
 Curses.bkgdset('='.ord | Curses.color_pair(1))
 Curses.clear
 Curses.refresh

 Curses.addstr('Press_any_key_to_continue')
 Curses.getch

Should fill the screen with equals signs (yellow on blue background),
and prompt the user to press any key to continue.  With Ruby 1.9.3 this
doesn't work.  The curses module assumes curses characters are one byte
(typeof(chtype) == char).  Yet GNU ncurses defines the chtype data type
as an unsigned integer (OSX 10.8) or an unsigned long (FreeBSD 9.1,
RedHat 7.3).  The curses module defines a macro "NUM2CH" to convert from
ruby objects to chtype objects.  At present NUM2CH is defined as
NUM2CHR.  Instead NUM2CH should be defined as NUM2INT to allow for
values > 255 (ex: character + color).

=end
Bb39d9ff4410a47cd75bd71254577427?d=identicon&s=25 ThomasDickey (Thomas dickey) (Guest)
on 2013-07-20 13:42
(Received via mailing list)
Issue #8659 has been updated by ThomasDickey (Thomas dickey).


agree: not just ncurses, but any implementation of SVr4 or X/Open curses
will use >8 bits for chtype.
8-bit values were for BSD-curses, which is rarely used (essentially only
for antique programs).
----------------------------------------
Bug #8659: Curses::Window#bkgdset does not handle color correctly
https://bugs.ruby-lang.org/issues/8659#change-40591

Author: inferiorhumanorgans (Alex Zepeda)
Status: Open
Priority: Normal
Assignee:
Category: ext
Target version:
ruby -v: ruby 1.9.3p385 (2013-02-06 revision 39114)
[x86_64-darwin12.2.1]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


=begin
Colors in curses are handled as high bits on a character.  Logically
ORing a character with a color pair should allow bkgdset to configure a
colored background.  This can be seen in the source for the Python
curses module.  The Python function takes one or two arguments (color +
character).  If there are two arguments they are ORed together and
passed to curses as such.  Back in ruby land, with one argument it
should be possible to specify a background color for the whole screen
thusly:

 # Define a color pair
 Curses.init_pair(1, Curses::COLOR_GREEN, Curses::COLOR_BLUE)
 # Set the screen background to blue
 Curses.bkgdset(' '.ord | Curses.color_pair(1))

The following:

 #!/usr/bin/env ruby

 require 'curses'

 Curses.init_screen
 Curses.start_color

 Curses.init_pair(1, Curses::COLOR_YELLOW, Curses::COLOR_BLUE)
 Curses.bkgdset('='.ord | Curses.color_pair(1))
 Curses.clear
 Curses.refresh

 Curses.addstr('Press_any_key_to_continue')
 Curses.getch

Should fill the screen with equals signs (yellow on blue background),
and prompt the user to press any key to continue.  With Ruby 1.9.3 this
doesn't work.  The curses module assumes curses characters are one byte
(typeof(chtype) == char).  Yet GNU ncurses defines the chtype data type
as an unsigned integer (OSX 10.8) or an unsigned long (FreeBSD 9.1,
RedHat 7.3).  The curses module defines a macro "NUM2CH" to convert from
ruby objects to chtype objects.  At present NUM2CH is defined as
NUM2CHR.  Instead NUM2CH should be defined as NUM2INT to allow for
values > 255 (ex: character + color).

=end
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 drbrain (Eric Hodel) (Guest)
on 2013-07-23 00:56
(Received via mailing list)
Issue #8659 has been updated by drbrain (Eric Hodel).

Status changed from Open to Assigned
Assignee set to shugo (Shugo Maeda)


----------------------------------------
Bug #8659: Curses::Window#bkgdset does not handle color correctly
https://bugs.ruby-lang.org/issues/8659#change-40610

Author: inferiorhumanorgans (Alex Zepeda)
Status: Assigned
Priority: Normal
Assignee: shugo (Shugo Maeda)
Category: ext
Target version:
ruby -v: ruby 1.9.3p385 (2013-02-06 revision 39114)
[x86_64-darwin12.2.1]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


=begin
Colors in curses are handled as high bits on a character.  Logically
ORing a character with a color pair should allow bkgdset to configure a
colored background.  This can be seen in the source for the Python
curses module.  The Python function takes one or two arguments (color +
character).  If there are two arguments they are ORed together and
passed to curses as such.  Back in ruby land, with one argument it
should be possible to specify a background color for the whole screen
thusly:

 # Define a color pair
 Curses.init_pair(1, Curses::COLOR_GREEN, Curses::COLOR_BLUE)
 # Set the screen background to blue
 Curses.bkgdset(' '.ord | Curses.color_pair(1))

The following:

 #!/usr/bin/env ruby

 require 'curses'

 Curses.init_screen
 Curses.start_color

 Curses.init_pair(1, Curses::COLOR_YELLOW, Curses::COLOR_BLUE)
 Curses.bkgdset('='.ord | Curses.color_pair(1))
 Curses.clear
 Curses.refresh

 Curses.addstr('Press_any_key_to_continue')
 Curses.getch

Should fill the screen with equals signs (yellow on blue background),
and prompt the user to press any key to continue.  With Ruby 1.9.3 this
doesn't work.  The curses module assumes curses characters are one byte
(typeof(chtype) == char).  Yet GNU ncurses defines the chtype data type
as an unsigned integer (OSX 10.8) or an unsigned long (FreeBSD 9.1,
RedHat 7.3).  The curses module defines a macro "NUM2CH" to convert from
ruby objects to chtype objects.  At present NUM2CH is defined as
NUM2CHR.  Instead NUM2CH should be defined as NUM2INT to allow for
values > 255 (ex: character + color).

=end
This topic is locked and can not be replied to.