How to Get/Read Console palette setting (from C)?

This forum is for general developer support questions.

How to Get/Read Console palette setting (from C)?

Postby marko » Sat Feb 27, 2016 8:36 pm

Hi, I wonder if it's possible (how) to easily detect (in C code), if the palette in Console is set to "System Pens" or ANSI colors?

In other words, I want to Get/Read the Console palette setting, from my C code/program? If it's "System Pens" or "Full ANSI colors" or other...

If it's possible, thanks :)


EDIT:
Subject changed from "If palette in Console is System Pens or ANSI colors?" to "How to Get/Read Console palette setting (from C)?"
Last edited by marko on Mon Feb 29, 2016 3:02 pm, edited 1 time in total.
AmigaOS 4.1 FE on Sam440ep-flex @ 800MHz, 1GB RAM, Radeon 9250
Still waiting (or dreaming) for The Amiga revolution...
m4rko.com/AMIGA
User avatar
marko
 
Posts: 42
Joined: Sun Jun 19, 2011 5:09 am
Location: Gothenburg, Sweden, EU

Re: If palette in Console is System Pens or ANSI colors?

Postby tonyw » Sun Feb 28, 2016 12:34 am

You can set the palette yourself at any time, and you are expected to remember what you set it to. The default setting is System Pens (zero), but that will be over-written by the console prefs setting when the window is opened.

To set the palette, you can use the IO request CD_SETATTRS (see the docs for CD_SETATTRS/CDT_SELECTPALETTE).
You can also use the escape sequence "CSI <n>s", where "<n>" is the number of the palette. See the docs for CMD_WRITE, look for "aSCP". The angle brackets around the "n" are there only to show that it is an argument. Example:

9B 31 73 // set the palette to "1" (ANSI colours)
cheers
tony
User avatar
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 1314
Joined: Wed Mar 09, 2011 2:36 pm
Location: Sydney, Australia

Re: If palette in Console is System Pens or ANSI colors?

Postby marko » Mon Feb 29, 2016 2:50 pm

@tonyw

Okej.. but I'm looking for a way of doing the other way around...

I want to get (from my C code), if a user have set the Console palette to "System Pens" or "Full ANSI colors".

Being able to read/get what kind of palette the user have chosen in the Console, allows my code the behave correctly...

Now my code/program, needs the user to tell my code/program what kind of palette the user is using... so my code/program can behave correctly...
AmigaOS 4.1 FE on Sam440ep-flex @ 800MHz, 1GB RAM, Radeon 9250
Still waiting (or dreaming) for The Amiga revolution...
m4rko.com/AMIGA
User avatar
marko
 
Posts: 42
Joined: Sun Jun 19, 2011 5:09 am
Location: Gothenburg, Sweden, EU

Re: If palette in Console is System Pens or ANSI colors?

Postby marko » Mon Feb 29, 2016 2:50 pm

For example:

I have this program called ShowFiles (sf), I want to output file links in green color to the console, so I use pen 2 to do so if the user uses ANSI colors.
But if the user uses System Pens, it outputs links in white color (instead of green), which is wrong. Instead my code should detect that a non-ANSI palette is being used and output the link in default color (pen 1 (black) in this case).

So now I need the user telling my code/program what kind of palette the person is using, before the program outputs correctly to the Console. Instead I want my code/program being able to get/read what kind of palette the user have chosen in the Console Preferences (so the program doesn't need to bother the user about it).

Is it possible? :)
AmigaOS 4.1 FE on Sam440ep-flex @ 800MHz, 1GB RAM, Radeon 9250
Still waiting (or dreaming) for The Amiga revolution...
m4rko.com/AMIGA
User avatar
marko
 
Posts: 42
Joined: Sun Jun 19, 2011 5:09 am
Location: Gothenburg, Sweden, EU

Re: How to Get/Read Console palette setting (from C)?

Postby tonyw » Tue Mar 01, 2016 12:22 am

As it stands, you can read the Console Prefs settings at any time, it will return the "struct ConsolePrefs", which includes the current palette and colour settings. To do that, you have to:
Code: Select all
#include <prefs/console.h>
struct ConsolePrefs conPrefs;
struct IORequest request;
Tag tagList[4];

// open console device first, to get io_Device and io_Unit. Copy from earlier request if you like.
request.io_Length = sizeof (tagList);
request.io_Command = CD_GETATTRS;
request.io_Data = tagList;

// enter Tags
tagList[0] = CDT_GETPREFS;
tagList[1] = (uint32)&conPrefs;
tagList[2] = TAG_END;

// send the request
error = IExec->DoIO (request);
if ((error != 0) || (request.io_Error != 0))
{
// error handling
}
palette = conPrefs.Palette;
FGColour = conPrefs.FGColor;
BGColour = conPrefs.BGColor;
(etc)



That should get you started. It's just off the top of my head, I haven't checked it.
cheers
tony
User avatar
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 1314
Joined: Wed Mar 09, 2011 2:36 pm
Location: Sydney, Australia

Re: How to Get/Read Console palette setting (from C)?

Postby marko » Wed Mar 02, 2016 1:51 pm

@tonyw

Thank you for the example code Tony, I will give it a go :D
AmigaOS 4.1 FE on Sam440ep-flex @ 800MHz, 1GB RAM, Radeon 9250
Still waiting (or dreaming) for The Amiga revolution...
m4rko.com/AMIGA
User avatar
marko
 
Posts: 42
Joined: Sun Jun 19, 2011 5:09 am
Location: Gothenburg, Sweden, EU


Return to General Developer Support

Who is online

Users browsing this forum: No registered users and 1 guest