PavelRadzevich / grub4dos-chenall

Automatically exported from code.google.com/p/grub4dos-chenall
0 stars 0 forks source link

Support for getting and restoring 'standard' console color #152

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

I would like to display a warning message in say red and then set the console 
color back to whatever it was before.
The problem is I don't know what the console color was as it can be set by the 
user.

So I need a way of getting and setting/restoring the console color in grub4dos 
0.4.5c.

i.e. 

get current console text color
save it in variable
set color standard=red
echo ERROR xxxxx
restore original console colour

Original issue reported on code.google.com by Steve6375 on 11 Sep 2013 at 8:00

GoogleCodeExporter commented 8 years ago
Sorry,I'm busy lately.

Current you can try this(not in debug off mode)
color | set c=
set c=%c:~15,2%
if "%c:~-1%"=="," set c=%c:~0,-1%
set standard=0x%c%

Original comment by chenall.cn on 13 Oct 2013 at 1:25

GoogleCodeExporter commented 8 years ago
Thanks! I didn't know that color command displayed current standard color!

Original comment by Steve6375 on 13 Oct 2013 at 7:59

GoogleCodeExporter commented 8 years ago
If you just want to change the text colour but not the background color, then 
you have to do something like this. Would be easier if color values where at 
known locations???

!BAT
# USAGE: set emsg=your message  set emsgcol=4  call /PrintMsg.g4b
# Note: debug is turned on

# assumes emsg is the text we want to display at current cursor position - 
background text colour is not altered
if "%emsg%"=="" set emsg=\nWARNING\n\x20    No emsg variable set before calling 
%0     \x20\n
# emsgcol is the TEXT colour 0-F only or rrggbb (must be either 1 hex digit or 
3+hex digits but not 2 hex digits) - e.g. red text = 4 or ff0000
#if "%emsgcol%"=="" set emsgcol=ff4032

if "%emsgcol%"=="" echo -e -n %emsg% && exit

debug on
color | set c= ;; set stdb=%c:~15,1% ;; set stdf=%c:~16,1% ;; if "%stdf%"=="," 
set stdf=%stdb% && set stdb=0
set stdh=%c:~18,10% ;; set stdh=0x%stdh% 
set /A e=0x%emsgcol%+0 > nul  
if %emsgcol%>=0x100 color standard %e% || color standard 0x%stdb%%%emsgcol%
echo -e -n %emsg%
color standard 0x%stdb%%%stdf% ;; color standard %stdh%
set c= ;; set e= ;; set stdh= ;; set stdb= ;; set stdf=

Original comment by Steve6375 on 15 Oct 2013 at 2:07

GoogleCodeExporter commented 8 years ago
There is another way to get current color
//32bit color
#define current_color ((*(int **)0x8304)[42])
//64bit color
#define foreground ((*(int **)0x8304)[43])
//64bit color
#define background ((*(int **)0x8304)[44])

so it's easy to get the color
eg
calc 44<<2 + *0x8304 ;; read %@retval% ;; set color_bg=%@retval%
calc 43<<2 + *0x8304 ;; read %@retval% ;; set color_fg=%@retval%

Original comment by chenall.cn on 15 Oct 2013 at 5:10

GoogleCodeExporter commented 8 years ago
Thats much better and I don't have to turn on debug  :-)
thanks!

Original comment by Steve6375 on 15 Oct 2013 at 6:13

GoogleCodeExporter commented 8 years ago

Original comment by chenall.cn on 16 Oct 2013 at 2:11