[Lazarus] Displaying text with colour and insertion point

Martin lazarus at mfriebe.de
Wed May 16 14:51:18 CEST 2012


On 16/05/2012 13:24, Mark Morgan Lloyd wrote:
> Martin wrote:
>> TSynEdit? TSynPosSyn (position highlighter, see examples)
>
> Do you mean that that can now colour arbitrary sequences of characters 
> (i.e. what you'd expect from a terminal emulator), rather than having 
> to define things in advance? As an example, see 
> http://wotho.ethz.ch/APL-1130/2741_APL_Demo.png where everything the 
> user enters (which starts at the 7th column) is printed in red.

Yes, though it may be a bit tedious to add.

The normal way (see example):
      // Line 0, from start of line to pos 3 (3 chars) highlighted as Attr1
      Highlighter.AddToken(0,3,Attr1);

but this will do a single char
      Highlighter.AddToken(0,3,Attr1);  // Attr1 from col 3
      Highlighter.AddToken(0,4,tkText);  // text from col 4


It may be easier to write a custom highlighter - there is a tutorial
http://wiki.lazarus.freepascal.org/SynEdit_Highlighter#Creating_a_SynEdit_Highlighter

samples are also in the example folder (SVN).

I assume you have a fixed amount of lines and columns? It should be easy 
to have it an array of attributes matching each char in each line.

----
Whatever you do: make sure to switch off the removal of trailing spaces 
(or you can not highlight them...)

There is a property(IIRC Options)

>
> Being able to use a standard component would definitely be an 
> advantage, since particularly for this project I am very keen on a 
> user with limited (or no) Pascal experience simply being able to grab 
> the sources and a copy of Lazarus and compile.
>
> But I must also ask: how long has TSynedit done this? It does appear 
> to be one of the more fluid parts of the LCL and I'm afraid I'm a bit 
> wary...
>

The pos highlighter has always been there.


What do you mean more fluid? ... (btw: SynEdit is not part of the LCL. 
And in is MPL/GPL at your choice, as that is what the original SynEdit is)

SynEdit had a few changes ( 
http://wiki.lazarus.freepascal.org/Lazarus_0.99.0_release_notes#SynEdit )
I tried to get them in before 1.0, hence so many so sudden...
But most of them should not need user changes.

folding highlighters, if you wrote your own, might still be subject to 
change (so I hope it will not be needed, the latest change should do). 
That is because folding still has a lot of changes...
But the basic highlighter should not need to change.

The internal representation of the Textbuffer, and it's Views will 
change. But that should not affect any one...








More information about the Lazarus mailing list