Working with Line Colors

Overview of SPFLite color support


SPFLite provides primary commands and keyboard primitive functions to support what are called Virtual Highlighting Pens.


A highlighting pen can color a portion of text in one of four colors: Red, Blue, Green and Yellow, aside from the "standard" text color.


The available keyboard primitive functions are:


       (PenRed)

       (PenBlue)

       (PenGreen)

       (PenYellow)

       (PenStd)


You can specify a color on FIND and CHANGE commands.  You can also use LOCATE to find lines having a particular color, and can use RESET to clear the color from all lines.


See the main SPFLite Help documentation for more details on these commands and primitive functions.



Macro functions for color support


The color interface for macros provides a means to query the current color state of a line, and a way to alter that state.


What could you do with this capability?  You may want to use it to analyze a block of text, and add or remove highlighting colors based on some particular condition or data value you are interested in.  You could look or, or change, the text coloring in ways that are beyond the ability of native SPFLite FIND and CHANGE commands.

Recall that text highlighting pens come in four colors: Red, Blue, Green and Yellow, and a standard color with no highlighting.  The current color of a character position in a given line is represented by the letters R, B, G and Y.  Character positions having the standard text color are presented by a blank.

There is also the "text selection" (from mouse or shift-arrow selection) which is active only during a select operation, and which goes away once you press Enter.  This type of selection is not considered here, nor is the underlining that is done for the (Swap) keyboard primitive function.  You cannot query or change such video attributes using macros.  (However, the location of a text selection area can be queried.)

Suppose you have a line of data colored like this.  (The colors are shown using one possible color palette selection.  You can use the Screen tab of the Global Options dialog to choose any desired text foreground and background for each of the four possible colors.)

   000001 LINE ONE OF COLOR-HIGHLIGHTED DATA

To "get" the color of this line, you ask for a string that represents the color of each column of data on that line.  Assume that currLptr is the line pointer to that line, and Clr_Line is a string variable:

       Clr_Line = Get_Clr_Line$ (currLptr)

This would produce an "array" of color codes, one character for each character in the line of data, as a string value.  Here's what the function would return:

data line  = "LINE ONE OF COLOR-HIGHLIGHTED DATA"

color line = "     RRR                      BBBB"

Because the data line has a length of 34, the string returned in the color-line variable is also of length 34.


Now, suppose you wanted to set the text value "HIGHLIGHTED" to Yellow, and make the word "ONE" the standard color.   You would pass a "new" color array to the function Set_Clr_Line.  This function completely replaces all existing colors for that line.  So, the typical way you would do this is:



Assume that you have the line of data shown above, and the variable currLptr contains a Line Pointer value to that line.  To remove the red color from the word "ONE", and make "HIGHLIGHTED" display as Yellow, you'd write statements like the following:

DIM Clr_Line AS STRING

Clr_Line = Get_Clr_Line$ (currLptr)

MID$(Clr_Line, 6, 3) = "   "                     ' remove color from ONE

MID$(Clr_Line, 19, 11) = "YYYYYYYYYYY"    ' make HIGHLIGHTED display as Yellow

Set_Clr_Line (currLptr, Clr_Line)

where

data line  = "LINE ONE OF COLOR HIGHLIGHTED DATA"

color line = "                  YYYYYYYYYYY BBBB"

Note that "DATA" was Blue before, and we are setting to Blue "again".  That's OK.  We also changed "ONE" from Red to "standard" by making its color-code positions blank, and we changed the word "HIGHLIGHTED" from standard to Yellow.  Observe that each time you call Set_Clr_Line, you are performing a complete replacement of the colors of every character on the data line.

Rules:




You should normally complete any macro modifications to the data line before proceeding with changes to the associated color line.  This will ensure the line length problem will not occur.








Created with the Personal Edition of HelpNDoc: Produce online help for Qt applications