figuring out current colors

12 views
Skip to first unread message

seasoned_geek

unread,
Aug 31, 2021, 4:56:48 PM8/31/21
to scintilla-interest
All,

Maybe I'm just brain damaged today. What is the way to determine what the current style is?

I have a feeling I'm suffering from "Scintilla Speak" and lack of a thesaurus. My mental experience is trapped in thinking like many other editors, when you have COBOL set, COBOL has its own color scheme that is different from C. So does BASIC, FORTRAN, etc.

I need to determine what the current "ordinary text" foreground and background colors are to create a prompt for user input that will match the current editor. The function calls styleFore() and styleBack() both want an sptr_t style parameter. Thus my confusion and search for determining the currently active style.

There is the function call styleAt( currentPos()) but no way to ensure what style the cursor is currently sitting in.

Is this line from the doc just misleading?

STYLE_DEFAULT

This style defines the attributes that all styles receive when the SCI_STYLECLEARALL message is used.

Does every Lexer style fill in
#define STYLE_DEFAULT 32
#define STYLE_LINENUMBER 33
#define STYLE_BRACELIGHT 34
#define STYLE_BRACEBAD 35
#define STYLE_CONTROLCHAR 36
#define STYLE_INDENTGUIDE 37
#define STYLE_CALLTIP 38
#define STYLE_FOLDDISPLAYTEXT 39

such that STYLE_DEFAULT will return the normal text background and foreground when COBOL is active and it will be the one active in the COBOL editor?

I've not gotten to the example with Lexilla and CopperSpice yet. Still working on Example3 for Scintilla and adding EDT keypad support and prompting. I haven't gotten around to reading the Klingon document.

file:///tmp/Scintilla-var.aq-Tutorial.pdf

Was waiting until I got to the actual color stuff in the next two examples.

Naive enough to believe this tiny little bit would have been straight forward. <Grin>

Thanks in advance,
Roland

Mitchell

unread,
Aug 31, 2021, 5:20:47 PM8/31/21
to scintilla...@googlegroups.com
Hi,

On Tue, 31 Aug 2021 13:56:48 -0700 (PDT)
"'seasoned_geek' via scintilla-interest" <scintilla...@googlegroups.com> wrote:

> All,
>
> Maybe I'm just brain damaged today. What is the way to determine what the
> current style is?
>
> I have a feeling I'm suffering from "Scintilla Speak" and lack of a
> thesaurus. My mental experience is trapped in thinking like many other
> editors, when you have COBOL set, COBOL has its own color scheme that is
> different from C. So does BASIC, FORTRAN, etc.

Scintilla's lexers do not have color schemes. They recognize different token types for styling (keywords, strings, comments, numbers, etc.), but a Scintilla-based editor is responsible for setting up how those tokens should be styled on a per-language basis.

> I need to determine what the current "ordinary text" foreground and
> background colors are to create a prompt for user input that will match the
> current editor. The function calls styleFore() and styleBack() both want an
> sptr_t style parameter. Thus my confusion and search for determining the
> currently active style.

If you want the default text foreground and background color, you would use:

int fore = SCI_STYLEGETFORE(STYLE_DEFAULT);
int back = SCI_STYLEGETBACK(STYLE_DEFAULT);

If you want the foreground and background color of the text at the current position, you would use:

int style = SCI_STYLEAT(SCI_CURRENTPOS);
int fore = SCI_STYLEGETFORE(style);
int back = SCI_SETYLEGETBACK(style);

> There is the function call styleAt( currentPos()) but no way to ensure what
> style the cursor is currently sitting in.

That call does return the style at the current position, which may or may not be the "ordinary" text style.

> Is this line from the doc just misleading?
>
> STYLE_DEFAULT
>
> *This style defines the attributes that all styles receive when the
> SCI_STYLECLEARALL message is used.*

When setting styles, one normally calls SCI_STYLESET*(STYLE_DEFAULT, ...) and then SCI_STYLECLEARALL() in order to apply the STYLE_DEFAULT settings to all styles and cut down on repetition.

> Does every Lexer style fill in
> #define STYLE_DEFAULT 32
> #define STYLE_LINENUMBER 33
> #define STYLE_BRACELIGHT 34
> #define STYLE_BRACEBAD 35
> #define STYLE_CONTROLCHAR 36
> #define STYLE_INDENTGUIDE 37
> #define STYLE_CALLTIP 38
> #define STYLE_FOLDDISPLAYTEXT 39
>
> such that STYLE_DEFAULT will return the normal text background and
> foreground when COBOL is active and it will be the one active in the COBOL
> editor?

When used as I described earlier, STYLE_DEFAULT is the base style all others inherit from. Any further SCI_STYLESET*() calls build on the defaults. Lexers do not specify styles -- the editor is responsible for doing so. When the editor sets up styles for COBOL, STYLE_DEFAULT will have the normal text background and foreground colors. Other text like comments, keywords, strings, etc. will likely have different colors because they have different style numbers that are not STYLE_DEFAULT.

I hope this helps.

Cheers,
Mitchell

seasoned_geek

unread,
Aug 31, 2021, 6:42:20 PM8/31/21
to scintilla-interest
On Tuesday, August 31, 2021 at 4:20:47 PM UTC-5 Mitchell wrote:
When used as I described earlier, STYLE_DEFAULT is the base style all others inherit from. Any further SCI_STYLESET*() calls build on the defaults. Lexers do not specify styles -- the editor is responsible for doing so. When the editor sets up styles for COBOL, STYLE_DEFAULT will have the normal text background and foreground colors. Other text like comments, keywords, strings, etc. will likely have different colors because they have different style numbers that are not STYLE_DEFAULT.

I hope this helps.


That last part is clear as mud, but I'm a couple of days (or more) away from getting to colors, lexers, and styles. The answer I needed for now is STYLE_DEFAULT should get me what I want.

Thanks
Roland
Reply all
Reply to author
Forward
0 new messages