[Lazarus] Displaying text with colour and insertion point
Martin
lazarus at mfriebe.de
Wed May 16 19:13:53 CEST 2012
On 16/05/2012 16:32, Mark Morgan Lloyd wrote:
>
> Since it's emulating a mechanical terminal that printed to roll paper,
> the number of lines is indeterminate and increasing. I suppose that I
> could limit it to (say) 1000, but if other people started using it
> there'd be bound to be somebody complain.
>
I see.
Still possible (at least I think)
Highlighter stores something called a range for each line (line as in
textbuffer lines, so scrolling of display does not matter)
They are automatically adjusted if lines are added/inserted/removed
from/to the textbuffer
So you could write a HL, that stores a list of x-positions for each
line, together with the attributes. (If you edit the line itself, you
need to adjust the list)
The highlighter can then return the text, cut into "tokens" (in your
case each continuous group of chars with the same attributes), and
supply the attributes for each token.
By default the "Range" is not freed, when the line is dropped (e.g. if
it is an enum or set, then just the memory is dropped).
But the highlighter allows to override that code, so it can be added.
Depends how interested you are.
I can assist, and help put together the framework, but you'll have to
implement the rest.
Also to get the memory to be freed (using dynamic array for ranges), it
touches a few internal methods. I do not foresee that they will change,
but ....
--------------
If you look at the 1st example from the tutorial ("SimpleHl").
As I said the ranges move with the lines. And I can make it possible
that you can store a dynamic array (actually pointer to dyn array) as
range, and that it will be freed, if a line is removed.
The array could be something like
TLinePosArray = Array of record
XPos, NumChar: Smallint; // assuming a max line length
Attr: TSynHighlighterAttributes; // could alse be an enum, that you
map later
end;
PLinePosArray = ^TLinePosArray;
The rest should be self-explaining from the tutorial.
More information about the Lazarus
mailing list