[Lazarus] Displaying text with colour and insertion point

Mark Morgan Lloyd markMLl.lazarus at telemetry.co.uk
Wed May 16 17:50:33 CEST 2012


Paul Breneman wrote:
> Mark Morgan Lloyd wrote:
>> Does anybody have any suggestions for a component to display status or 
>> terminal text that will allow limited enhancement (colour, possibly 
>> underline etc.)?
>>
>> Over the last few weeks I've been tinkering with an emulator for an 
>> obsolete mechanical terminal (IBM 2741), including support for the APL 
>> character set. I started off using a listbox for simple output, noting 
>> that this didn't have provision for multiple colours or marking the 
>> insertion point. I moved on to stuffing characters into a memo, this 
>> allowed me to force a current-position marker but still had no colour.
>>
>> Looking at the CmdLine component, it appears OK as a command window 
>> (i.e. accepting keyboard input etc.) but isn't so hot when the 
>> principal requirement is to display text pushed into the underlying 
>> strings storage from elsewhere: in particular, there isn't a way to 
>> force the insertion point marker to the end of what's just been output.
>>
>> I'm sure I'm not the only person who wants to do this sort of thing: 
>> does anybody have any recommendations?
> 
> Mark,
> 
> I don't have any recommendations but I'm following this message thread 
> with much interest.  Last fall I wrote a "serial debug terminal" with 
> Free Pascal and fpGUI and that program has proved to be one of the most 
> useful simple programs I've written in a long time.  I've customized it 
> a few times already for real work projects and I also have some other 
> projects planned.  If you want to see how simple the present code is see 
> the "DbgTerm.pas" program at this page:
>   http://www.turbocontrol.com/easyfpgui.htm

I think that almost everybody who has to deal with non-modem equipment 
or who has demanding modem requirements (e.g. accommodate a mix of 
incoming and outgoing calls and/or obscure protocols) ends up doing the 
same. Something that's particularly badly handled in off-the-shelf 
software is control-line handling (DTR, CD etc.).

> Right now you can't put the cursor in the terminal and send characters 
> by typing them, but rather there are separate SendEdit and SendButton 
> components.  I'd like to implement a more standard "terminal" operation 
> so what you are discussing here applies to that.

In my case, I'm collecting keydown events from whatever the visible 
control is, converting them to an internal code (derived from the 
mechanics of the original 2741 terminal), (local echo done here), 
converting that to characters for the serial interface, and finally 
sending those to a serial line or telnet connection. Received data 
(which might be coded differently from what was transmitted) is 
converted to the internal code, written to the same queue that got the 
local echo, the content of which is finally converted to Unicode using a 
table that mimics an IBM golfball and stuffed into the stringlist that 
underlies the listbox or memo control.

A listbox does not have a caret marking the insertion point. A memo 
does, and I can generally force that to indicate the position the next 
keypress will appear after each character is output. Obviously that can 
be confused by a mouse click, but since I'm not using the control's own 
keyboard handler the next output character will always appear in the 
right place.

I'm sure all this isn't very efficient, but I am, after all, emulating 
the terminal that gave the World 134.5 Baud operation :-)

> I'd like to keep the present DbgTerm as a very simple example of serial 
> communications code but I will consider having a more complex terminal 
> program too.  I've run into many people who need a replacement for 
> HyperTerminal since it has been gone from Vista and later Windows editions.

For Windows I'd point you at Teraterm, of which v1 was Pascal if you 
think you need to tinker. For Linux gtkterm.

-- 
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 mailing list