Recent

Author Topic: [Solved] Changing text of a line in console output  (Read 485 times)

nikel

  • Full Member
  • ***
  • Posts: 121
[Solved] Changing text of a line in console output
« on: September 23, 2020, 06:50:15 am »
Hello, how can I change text for my console application? I want to write to the same line.
« Last Edit: September 29, 2020, 02:49:42 pm by nikel »

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1001
  • Former Delphi 1-7, 10.2 User
Re: Changing text of a line in console output
« Reply #1 on: September 23, 2020, 07:56:04 am »
Use write instead of writeLn ?
o Lazarus v2.1.0 r63871, FPC v3.3.1 r46876, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware Fusion VM)
o FPC 3.0.4, FreeBSD 12.2-STABLE r365646 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 20.04 (Parallels VM)

PascalDragon

  • Hero Member
  • *****
  • Posts: 2257
  • Compiler Developer
Re: Changing text of a line in console output
« Reply #2 on: September 23, 2020, 09:16:26 am »
Use write instead of writeLn ?

That won't help if nikel wants to overwrite the printed text. In that case the Crt unit or something equivalent should be used.

mika

  • New member
  • *
  • Posts: 6
Re: Changing text of a line in console output
« Reply #3 on: September 23, 2020, 09:59:35 am »
example how to change content of current line in console application
Code: Pascal  [Select][+][-]
  1. program write_same_line;
  2.  
  3. var k : longint;
  4.  
  5. begin
  6.      writeln ('first line');
  7.      for k:=0 to 10 do
  8.      begin
  9.           write('second line ',k,'   ',#13);
  10.      end;
  11.      writeln;
  12.      writeln('third line');
  13. end.
  14.  

dogriz

  • Full Member
  • ***
  • Posts: 117
    • Tech blog - Delphi, Lazarus, Firebird, Windows, Linux, Android...
Re: Changing text of a line in console output
« Reply #4 on: September 23, 2020, 10:38:27 am »
crt unit gives you some functionality like:

  ClrScr;
  Write('Line one');
  GotoXY(0,6);
  TextColor(10);
  Write('ABC');
...
FPC 3.0.4
Lazarus 2.0.6
Debian x86_64, arm

nikel

  • Full Member
  • ***
  • Posts: 121
Re: Changing text of a line in console output
« Reply #5 on: September 29, 2020, 01:24:59 am »
Hello, thanks for the replies. I couldn' make it work, your code writes text to different lines on my Linux terminal.

How do they design a gui for programs such as Volkov Commander, Moc player and Cmus?
« Last Edit: September 29, 2020, 01:45:50 am by nikel »

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1001
  • Former Delphi 1-7, 10.2 User
Re: Changing text of a line in console output
« Reply #6 on: September 29, 2020, 04:03:29 am »
Hello, thanks for the replies. I couldn' make it work, your code writes text to different lines on my Linux terminal.

Whose code?

mika's code works for me.
o Lazarus v2.1.0 r63871, FPC v3.3.1 r46876, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware Fusion VM)
o FPC 3.0.4, FreeBSD 12.2-STABLE r365646 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 20.04 (Parallels VM)

nikel

  • Full Member
  • ***
  • Posts: 121
Re: Changing text of a line in console output
« Reply #7 on: September 29, 2020, 09:00:27 am »
Mika's code write to three lines.

Quote
can@host:~/Desktop$ ./test
first line
second line 10   
third line
can@host:~/Desktop$

I want it to overwrite the first line.
« Last Edit: September 29, 2020, 09:10:17 am by nikel »

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1001
  • Former Delphi 1-7, 10.2 User
Re: Changing text of a line in console output
« Reply #8 on: September 29, 2020, 10:09:28 am »
Mika's code shows you how to overwrite line two 10 times on the same line. Simply modify the code for line one.
o Lazarus v2.1.0 r63871, FPC v3.3.1 r46876, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware Fusion VM)
o FPC 3.0.4, FreeBSD 12.2-STABLE r365646 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 20.04 (Parallels VM)

nikel

  • Full Member
  • ***
  • Posts: 121
Re: Changing text of a line in console output
« Reply #9 on: September 29, 2020, 11:06:30 am »
How stupid of me! That was what I need. I searched for "pascal text based user interface" found interesting resources.

Code: Pascal  [Select][+][-]
  1. //image image.png
  2. (*
  3. Ein Hello World mit Free-Vision.
  4. Der Text wird in einer Message-Box ausgegeben.
  5. *)
  6. //lineal
  7. //code+
  8. program Project1;
  9.  
  10. uses
  11.   App, MsgBox;
  12. var
  13.   MyApp: TApplication;
  14.  
  15. begin
  16.   MyApp.Init;
  17.   MessageBox('Hello World !', nil, mfOKButton);
  18.   // MyApp.Run;   // Wen es weiter gehen soll.
  19.   MyApp.Done;
  20. end.
  21. //code-
« Last Edit: September 29, 2020, 02:49:23 pm by nikel »

 

TinyPortal © 2005-2018