Euphoria Ticket #779: colors_to_attr does not work correctly on OSX

From the manual
function definition: colors_to_attr

include std/console.e 
namespace console 
public function colors_to_attr(object fgbg, integer bg = 0) 

Converts a foreground and background color set to its attribute code format.

Parameters:

  1. fgbg : Either a sequence of {fgcolor, bgcolor} or just an integer fgcolor.
  2. bg : An integer bgcolor. Only used when fgbg is an integer.

Returns:
An integer attribute code.

When I do

include std/console.e 
include std/graphcst.e 
include std/graphics.e 
 
 
? WHITE --> 7 
? RED    --> 4 
? BLUE   --> 1 
? colors_to_attr(WHITE, RED)  --> 71 WHITE characters on RED background 
? colors_to_attr(WHITE, BLUE) --> 23 WHITE characters on BLUE background 
 
display_text_image({1,1}, {{82,23,68,71,82,23,68,71,82,23},{82,23,68,71,68,71,68,71,82,23},{82,23,68,71,68,71,68,71,68,71}}) 
-- WHITE 'R's on BLUE background and WHITE 'D's on RED background 
/* 

The only problem is that for OSX the values of RED and BLUE are switched and so my colors end up switched.  
If I use text_color() and bk_color() then the colors are correct. 
*/ 
text_color(WHITE) 
bk_color(RED) 
printf(1, "This is a test. Should be WHITE on RED\n") 
bk_color(BLUE) 
printf(1, "This is a test. Should be WHITE on BLUE\n") 
bk_color(BLACK) 
printf(1, "Back to white on black\n") 

Due to a hard drive crash I lost my edit access to the repository but the fix is very simple. In file console.e

-- In function colors_to_attr 
-- replace the line 
		return fgbg[1] + fgbg[2] * 16 
--with 
		return true_fgcolor[fgbg[1]+1] + true_bgcolor[fgbg[2]+1] * 16 
-- and the line 
		return fgbg + bg * 16 
--with 
		return true_fgcolor[fgbg+1] + true_bgcolor[bg+1] * 16 

I'm sure that this affects Linux also since the colors are rearranged there as well.

Details

Type: Bug Report Severity: Minor Category: Library Routine
Assigned To: jimcbrown Status: Fixed Reported Release: 4.0.4
Fixed in SVN #: View VCS: none Milestone: 4.0.5

1. Comment by jimcbrown Sep 29, 2012

This is confirmed as affecting Linux/GNU on 4.0 and default.

I suspect attr_to_colors() may also be affected.

2. Comment by jimcbrown Sep 29, 2012

See: hg:euphoria/rev/e5e687455294

changeset: 5700:e5e687455294 tag: tip parent: 5698:3dbca84a0458 user: Jim C. Brown date: Sat Sep 29 08:56:04 2012 -0400 files: include/std/console.e description:

  • Fixes ticket:779 using the fix suggested in that ticket

3. Comment by jimcbrown Sep 29, 2012

See: hg:euphoria/rev/cf8159d91842

changeset: 5701:cf8159d91842 branch: 4.0 tag: tip parent: 5695:d69594cbac16 user: Jim C. Brown date: Sat Sep 29 08:56:43 2012 -0400 files: include/std/console.e description:

  • Fixes ticket:779 using the fix suggested in that ticket

4. Comment by jimcbrown Sep 29, 2012

See: hg:euphoria/rev/f269927c332b

changeset: 5702:f269927c332b tag: tip parent: 5700:e5e687455294 user: Jim C. Brown date: Sat Sep 29 11:16:12 2012 -0400 files: include/std/console.e description:

5. Comment by jimcbrown Sep 29, 2012

See: hg:euphoria/rev/c660a2f85a1f

changeset: 5703:c660a2f85a1f branch: 4.0 tag: tip parent: 5701:cf8159d91842 user: Jim C. Brown date: Sat Sep 29 11:16:44 2012 -0400 files: include/std/console.e description:

6. Comment by Lnettnay Sep 29, 2012

Thank you Jim. I will see about getting Mercurial set up tomorrow so I can do this kind of thing myself.

Search



Quick Links

User menu

Not signed in.

Misc Menu