[Lazarus] How to clear screen in console app

Mark Morgan Lloyd markMLl.lazarus at telemetry.co.uk
Sat Apr 23 10:10:09 CEST 2016


Michael Van Canneyt wrote:
> On Sat, 23 Apr 2016, Bo Berglund wrote:
> 
>> On Sat, 23 Apr 2016 07:32:55 +0200, Bo Berglund
>> <bo.berglund at gmail.com> wrote:
>>
>>> I need to make a console app that can run on Linux.
>>> It would be a simple thing I believed, but no...
>>>
>>> I cannot get the ClrScr command working, it just puts strange
>>> characters on the screen instead of clearing it.
>> ...
>>> But the console debug window just shows a bunch of control characters
>>> (square with 001B inside) plus [6n [H [m [H [2JEnter command:
>>> And every command I enter results in a new line being displayed rather
>>> than staying on the same line and erasing the previous output.
>>
>> UPDATE:
>> It seems to be caused by the Lazarus debug console window!
>> If I go to the dir where the program resides in my terminal (both
>> local and via SSH) and execute ~/tmp/project1 then it looks OK.
>>
>> So my question now changes to:
>> Why does the debug window show different output than the actual
>> terminal console?
>>
>> I am using Lazarus 1.6 release and fpc 3.0.0 both built from svn
>> sources on a Raspberry Pi3 with Raspbian Jessie if that matters.
> 
> The console respects the special terminal control characters.
> The debug window does not respect these characters, and just prints them 
> out
> to screen. I am not sure this can be properly handled. Maybe there is an
> option that can be given to xterm to respect the characters.
> 
> If you are debugging using SSH, then you probably need to add the -t 
> option.

The console window in which the shell and app run might have different 
commands, depending on what's actually being used (i.e. xterm, an SSH 
session from a remote system and so on). The console window will have an 
associated $TERM shell description, and strictly speaking the program 
that wants to clear the screen should refer to this possibly using 
curses or libtinto.

I don't know whether the ClrScr procedure refers to libtinfo, or what 
properties libtinfo thinks the debug window has. It could probably be 
argued that the debug window should set TERM to indicate that it doesn't 
obey commands, but I'd suggest that if the program does a ClrScr then 
the programmer wants notification of this and it should probably /not/ 
wipe earlier debug output. After all, the debug window is there for 
debugging, not for normal interaction.

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