- Subject: Re: [jed-users] Return not static string from C + 256+ colors terminal
- From: "John E. Davis" <jed@xxxxxxxxxxx>
- Date: Tue, 6 Sep 2022 13:53:28 -0400
Nicholas Christopoulos <nereus@xxxxxxxxxxx> wrote:
> Two questions
>
> 1. This is the code in C that used inside my patched version of Jed.
> I didn't find in documentation how to return a string (except if it is
> static string). So, I tried this solution that should work in theory
> (and in assembly based on regular languages).
>
> It is worked and seems correct, but there are no manual nor I found
> something similar in JED's code.
>
> I would like a confirmation that it is a correct solution.
>
> ```C
> void cbm_popup_files_sl() {
> char retf[PATH_MAX];
> ...
> // push copy of the string in
> // interpreters stack.
> // this is the returned string
> SLang_push_string(retf);
>}
That is ok, but...
> /* setup S-Lang interface */
> static SLang_Intrin_Fun_Type CBRIEF_Intrinsics [] = {
> ...
> MAKE_INTRINSIC("popup_files", cbm_popup_files_sl, STRING_TYPE, 0),
Here you are saying that cbm_popup_files_sl returns a char*, but it returns
void. So you need to use:
MAKE_INTRINSIC("popup_files", cbm_popup_files_sl, VOID_TYPE, 0),
Note the distinction: The interpreter function "popup_files" returns a
string, but the C function cbm_popup_files_sl does not.
MAKE_INTRINSIC describes the C function.
> 2. My second question, it is mostly a request.
> It is easy to support the 256+ colors in linux / X11 terminals, but
> inside from JED you cannot. Colors always ends-up to
> tt_set_color(obj, fg, bg) where FG and BG are strings of the names of 16
> VGA colors; anything else does not recognized. The set_color_esc() its
> not documented and I don't know how to use it.
If you have a 24bit color terminal, then you can use such colors in
jed provided that you are on a 64 bit system and that jed is linked to
slang 2.3.3. You may also need to set the COLORTERM environment
variable to "truecolor" if you have an older terminfo database that
does not support the RGB capability. Then to set a 24bit color, use
the #RRGGBB hex form, e.g., #B4FFB4.
See <https://www.jedsoft.org/most/> for screen shots of such truecolor
support.
Note also that jed supports italics on terminals that support it, e.g.,
set_color ("comment", "black;italics", "lightgray");
Similarly,
set_color ("keyword", "red;underline", "default");
will underline keywords. These are features of the slang library that
were added in version 2.3.0.
Hopefully this was useful.
Thanks,
--John
> FYI:
>
> If the terminfo reports 256 colors, then you can use 256 or more colors.
> If the COLORTERM environment variable is set, then you can use 24bit
> colors. Check both is safer.
>
> ```
>> tput colors
> 256
> ```
>
> There are at least three ways to use more colors in linux/X11 terminals
>
> a) standard CSI
>
> \e[38;2;r;g;bm Foreground RGB color
> \e[48;2;r;g;bm Background RGB color
>
> man -s 4 console_codes
>
> ```
> Commands 38 and 48 require further arguments:
>
> ;5;x 256 color: values 0..15 are IBGR (black, red, green, ...
> white), 16..231 a 6x6x6 color cube, 232..255 a grayscale ramp
>
> ;2;r;g;b 24-bit color, r/g/b components are in the range 0..255
> ```
>
> This method is used often.
>
> b) OSC
>
> man -s 4 console_codes
>
> ```
> ESC ] 4 ; num; txt ST Set ANSI color num to txt.
> ESC ] 10 ; txt ST Set dynamic text color to txt.
> ```
> The 'ST' (string termination) symbolizes the \033\\ or \007
> In both cases the txt is a RGB number. It is not well documented.
>
> examples:
> /bin/echo -e "\033]4;7;rgb:ff/00/00\007 \033[37mHello - function 4"
> /bin/echo -e "\033]10;rgb:ff/ff/00\033\\ Hello - function 10"
>
> c) OSC second method
>
> man -s 4 console_codes
>
> ```
> ESC ] OSC (Should be: Operating system command) ESC ] P
> nrrggbb: set palette, with parameter given in 7 hexadecimal digits
> after the final P :-(. Here n is the color (0–15), and rrggbb indicates
> the red/green/blue values (0–255). ESC ] R: reset palette
> ```
>
> ...
>
> A script for testing (CSI method):
>
> ```print_console_colors.sh:
> #!/bin/sh
> awk 'BEGIN{\
> s="/\\/\\/\\/\\/\\"; s=s s s s s s s s;\
> for (colnum = 0; colnum<77; colnum++) {\
> r = 255-(colnum*255/76);\
> g = (colnum*510/76);\
> b = (colnum*255/76);\
> if (g>255) g = 510-g;\
> printf "\033[48;2;%d;%d;%dm", r,g,b;\
> printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b;\
> printf "%s\033[0m", substr(s,colnum+1,1);\
> }\
> printf "\n";\
>}'
> ```
>
> Best regards
>
> --
> Nicholas Christopoulos <mailto:nereus@xxxxxxxxxxx>
> Personal Pages: <https://nicholas-christopoulos.dev>
> Github repositories: <https://github.com/nereusx>
> _______________________________________________
> For list information, visit <http://jedsoft.org/jed/mailinglists.html>.
>
_______________________________________________
For list information, visit <http://jedsoft.org/jed/mailinglists.html>.
[2022 date index]
[2022 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]