[Lazarus] How to clear screen in console app

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] How to clear screen in console app

Bo Berglund
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.
I started with a Console app in Lazarus and just added this piece of
code:
  { add your program here }
  repeat
    ClrScr;  //Needs Crt in uses
    Write('Enter command: ');
    Readln(FCheck);
  until FCheck = 'q';

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.

What am I doing wrong?

--
Bo Berglund
Developer in Sweden


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to clear screen in console app

Bo Berglund
On Sat, 23 Apr 2016 07:32:55 +0200, Bo Berglund
<[hidden email]> 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.

--
Bo Berglund
Developer in Sweden


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to clear screen in console app

Michael Van Canneyt


On Sat, 23 Apr 2016, Bo Berglund wrote:

> On Sat, 23 Apr 2016 07:32:55 +0200, Bo Berglund
> <[hidden email]> 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.

Michael.

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to clear screen in console app

Mark Morgan Lloyd
Michael Van Canneyt wrote:

> On Sat, 23 Apr 2016, Bo Berglund wrote:
>
>> On Sat, 23 Apr 2016 07:32:55 +0200, Bo Berglund
>> <[hidden email]> 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]

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to clear screen in console app

Michael Van Canneyt


On Sat, 23 Apr 2016, Mark Morgan Lloyd wrote:

> Michael Van Canneyt wrote:
>> On Sat, 23 Apr 2016, Bo Berglund wrote:
>>
>>> On Sat, 23 Apr 2016 07:32:55 +0200, Bo Berglund
>>> <[hidden email]> 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,

No. It just uses ansi escape characters.

Michael.

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to clear screen in console app

Bo Berglund
In reply to this post by Mark Morgan Lloyd
On Sat, 23 Apr 2016 08:10:09 +0000, Mark Morgan Lloyd
<[hidden email]> wrote:

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

I am comparing to how it works in Delphi (7)...
When I program a console program in Delphi and run it from within the
IDE it creates the console window and the interactions are shown
there.
All Writeln() output shows up as is and the program stops for input on
ReadLn() commands etc.

When I started my program in Lazarus nothing showed up at all so I had
to google for it and then I was directed towards the menu
"View/Debug Windows/Terminal Output" which displays a window titled
"Console".
This is the window I refer to and it does not behave like the real
terminal...

If OTOH I open a terminal window and navigate to the project dir and
start the executable produced by Lazarus, then it behaves as expected.

I am working to transfer my GUI test program into a terminal program
with no GUI output so it can be started via the console to map my TCP
interactions.
Then I don't have to access any GUI at all to get the port forwarding
to work. The target RPi is located in Texas behind a slow Internet
connection while I am in Sweden close to Stockholm. A long ways away..

I access the site via VPN but bringing up a TightVNC GUI is no fun due
to the latencies caused by the slow Internet speed.
SSH via PuTTY works much better and I plan on using screen to run the
mapper program while I can continue to work in the terminal base.


--
Bo Berglund
Developer in Sweden


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to clear screen in console app

Michael Van Canneyt


On Sat, 23 Apr 2016, Bo Berglund wrote:

> On Sat, 23 Apr 2016 08:10:09 +0000, Mark Morgan Lloyd
> <[hidden email]> wrote:
>
>> 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.
>>
>
> I am comparing to how it works in Delphi (7)...
> When I program a console program in Delphi and run it from within the
> IDE it creates the console window and the interactions are shown
> there.
> All Writeln() output shows up as is and the program stops for input on
> ReadLn() commands etc.
>
> When I started my program in Lazarus nothing showed up at all so I had
> to google for it and then I was directed towards the menu
> "View/Debug Windows/Terminal Output" which displays a window titled
> "Console".
> This is the window I refer to and it does not behave like the real
> terminal...

No, it does not. Because it is not a real terminal and does not obey the
ANSI codes to control the terminal.

Michael.

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to clear screen in console app

Bart
In reply to this post by Bo Berglund
On 4/23/16, Bo Berglund <[hidden email]> wrote:

> When I started my program in Lazarus nothing showed up at all so I had
> to google for it and then I was directed towards the menu
> "View/Debug Windows/Terminal Output" which displays a window titled
> "Console".
> This is the window I refer to and it does not behave like the real
> terminal...

Indeed it is not a terminal.
AFAIK it's a pseudoterminal based upon a TMemo or TSynEdit (too lazy
to look it up).
The code is in $(LazarusDir)/debugger/pseudoterminaldlg.pp

There is a bugreport already about it's behaviour (echoing control
characters) in http://bugs.freepascal.org/view.php?id=22349

Feel free to post enhencements.

Bart

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus