[Lazarus] Displaying text with colour and insertion point
Mark Morgan Lloyd
markMLl.lazarus at telemetry.co.uk
Wed May 16 15:13:32 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
> 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
> 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
> The pos highlighter has always been there.
> What do you mean more fluid? ...
I don't think any sort of pre-existing custom highlighter will work. The
requirement here is that anything- completely context-free- that the
user enters is red, anything that the host supplies (over telnet, serial
line etc.) is black. Either of those can be complete garbage, but should
still show up in the correct colour (and should stay correct,
irrespective of scrolling etc.).
> (btw: SynEdit is not part of the LCL.
> And in is MPL/GPL at your choice, as that is what the original SynEdit is)
OK, but in effect it comes as standard which makes it attractive.
> 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...
In practice (in this particular project) I'm stuffing characters
directly into the items/lines property (of whichever output component
I'm using). In other words I'm not using any of the component's own
keyboard handling, the reason is that there are several stages of
translation in between the user pressing a key and it being printed.
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
More information about the Lazarus