Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-04

Example of full screen console program anywhere?

10 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

I need to create a console program, but one that works similar to the nano editor, the gpsd position/satellite view or raspi-config on a Raspberry Pi.
I.e. the program manages the full terminal screen and displays its data in certain areas on screen and reads keystrokes as commands for controlling the program.
I once did such programs on Windows using BASIC, but that was before Windows appeared and I have all but forgotten how it was actually accomplished....
So I am looking for some examples to start off where the cursor for writing is positioned on the screen in order to put output data in certain places and commands can be entered without moving the displayed screen.

Is there such an example for FPC/Lazarus available somewhere? Target is Raspbian on a Raspberry Pi3 and I cannot use any GUI system for this because it must be accessed remotely via SSH (PuTTY) over a slow link that does not work decently with the graphical interface.

Bo Berglund Developer in Sweden

Reply by email

Sven Barth
to Bo Berglund
"Bo Berglund" wrote 19 lines
I need to create a console program, but one that works similar to the nano editor, the gpsd position/satellite view or raspi-config on a Raspberry Pi. I.e. the program manages the full terminal screen and displays its data in certain areas on screen and reads keystrokes as commands for controlling the program. I once did such programs on Windows using BASIC, but that was before Windows appeared and I have all but forgotten how it was actually accomplished.... So I am looking for some examples to start off where the cursor for writing is positioned on the screen in order to put output data in certain places and commands can be entered without moving the displayed screen. Is there such an example for FPC/Lazarus available somewhere? Target is Raspbian on a Raspberry Pi3 and I cannot use any GUI system for this because it must be accessed remotely via SSH (PuTTY) over a slow link that does not work decently with the graphical interface.

One example would be the Free Pascal's text mode IDE that you can find in the compiler's sources in ide/. It uses the Free Vision component system that's an open source clone of Turbo Pascal's Turbo Vision (FV is also part of FPC).

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160425/034439b1/attachment.html>

Reply by email

Paul Breneman
to Sven Barth
Sven Barth wrote 25 lines
Am 25.04.2016 16:59 schrieb "Bo Berglund" : > > I need to create a console program, but one that works similar to the > nano editor, the gpsd position/satellite view or raspi-config on a > Raspberry Pi. > I.e. the program manages the full terminal screen and displays its > data in certain areas on screen and reads keystrokes as commands for > controlling the program. > I once did such programs on Windows using BASIC, but that was before > Windows appeared and I have all but forgotten how it was actually > accomplished.... > So I am looking for some examples to start off where the cursor for > writing is positioned on the screen in order to put output data in > certain places and commands can be entered without moving the > displayed screen. > > Is there such an example for FPC/Lazarus available somewhere? > Target is Raspbian on a Raspberry Pi3 and I cannot use any GUI system > for this because it must be accessed remotely via SSH (PuTTY) over a > slow link that does not work decently with the graphical interface. One example would be the Free Pascal's text mode IDE that you can find in the compiler's sources in ide/. It uses the Free Vision component system that's an open source clone of Turbo Pascal's Turbo Vision (FV is also part of FPC).

About two years ago (on 26 May 2014) I put together a mini FPC distribution that compiled the FP IDE:
http://turbocontrol.com/gnuroot.htm

Reply by email

Bo Berglund
to Bo Berglund: I need to create a console program, but one that works similar to the nano editor, the…
Bo Berglund wrote 19 lines
I need to create a console program, but one that works similar to the nano editor, the gpsd position/satellite view or raspi-config on a Raspberry Pi. I.e. the program manages the full terminal screen and displays its data in certain areas on screen and reads keystrokes as commands for controlling the program. I once did such programs on Windows using BASIC, but that was before Windows appeared and I have all but forgotten how it was actually accomplished.... So I am looking for some examples to start off where the cursor for writing is positioned on the screen in order to put output data in certain places and commands can be entered without moving the displayed screen. Is there such an example for FPC/Lazarus available somewhere? Target is Raspbian on a Raspberry Pi3 and I cannot use any GUI system for this because it must be accessed remotely via SSH (PuTTY) over a slow link that does not work decently with the graphical interface.

Just to clarify:
I want to be able to run an FPC program in the console of an SSH terminal like PuTTY connected to the remote system (a Raspberry Pi3 sitting across the world from me).
This program should have 4-5 commands via key entries where it activates certain combinations of GPIO output pins to control relays, which in turn power on certain devices connected to the RPi controller.

I have a GUI program created with Lazarus 1.6 and FPC 3.0.0 where I have located almost all of the actual processing in separate classes. I *can* run the GUI program on the remote Pi via VPN and then TightVNC but it is a PITB because of the sluggish response due to the slow connection to there from here.

So I want to make a console type program instead which continuously displays the state of the GPIO outputs (like I have GUI shapes which change color) and then reacts to key presses where single letters mean different things causing an action on the outputs.

What I do not want is a program that scrolls up on the screen as keys are entered etc. I want the screen to stay put and only the status fields change when I do the commands.

Your two responses have been a bit over the top of my head in this context.
I should have formulated my request a bit clearer of course. For example comparing to the nano editor was a bit over the top. :(

Bo Berglund Developer in Sweden

Reply by email

Graeme Geldenhuys
to Bo Berglund
Bo Berglund wrote
What I do not want is a program that scrolls up on the screen as keys are entered etc. I want the screen to stay put and only the status fields change when I do the commands.

Free Vision can do just that for you. Obviously you can search the Internet for DOS type menu interfaces [loads of such examples are still around], but that would require low level console codes and interpretation. Free Vision does it already for you - and the end-result should look much prettier. I suggest you grab a copy of a Turbo Pascal manual (they are freely available on the Internet now - Borland released them) or search for some Turbo Vision example programs/code. Or even look at the FPC Text IDE as a working example (but that's a rather complex example to study).

I did a quick search, here is a simple Turbo Vision tutorial. It will apply exactly as is to Free Vision as well.

http://www.baskent.edu.tr/~tkaracay/etudio/ders/prg/pascal/PasHTM3/pas/pasl3007.html

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Paul Breneman
to Bo Berglund: On Mon, 25 Apr 2016 16:59:25 +0200, Bo Berglund Just to clarify: I want to be able to run…
Bo Berglund wrote
So I want to make a console type program instead which continuously displays the state of the GPIO outputs (like I have GUI shapes which change color) and then reacts to key presses where single letters mean different things causing an action on the outputs.

I *want* to do the same thing to remote control a RPi to control power on devices!

I'm thinking of using a FPC Free Vision app, controlled by encrypted UDP packets (completely stealth), with the RPi code eventually written with www.ultibo.org

Reply by email

Bo Berglund
to Bo Berglund: On Mon, 25 Apr 2016 16:59:25 +0200, Bo Berglund Just to clarify: I want to be able to run…

On Thu, 28 Apr 2016 15:23:01 +0200, Bo Berglund
wrote:

I went ahead and created a new Console Application in Lazarus where I use the same object for controlling the GPIO pins as I did in the GUI program.

The Console program just initializes the control object then enters into a repeat loop reading a key from the user and then interpreting the key in a case construct for valid commands.
It exits if the q key is pressed.

When I run this in Lazarus all operates according to plan but as soon as I try to run it outside of the GUI, for example in a terminal in Raspbian or in a PuTTY terminal connected by SSH to the RPi literally nothing works of the stuff that should happen in the repeat loop!

What I get is the greeting message and then when I press the keys that should produce the action nothing at all happens including pressing q, which is the exit code out of the loop and should terminate the program.

For some reason it was possible to close it using Ctrl-C, though.

In Lazarus I use the debug window "Terminal Output" and here everything planned works fine!

What a mystery! This is the first time I have encountered such a difference!

After some further debugging I found that the keypresses are not even handled in the repeat loop. It uses this type of construct:

  //Display main screen
  Writeln('Controls are:');
  Writeln('p = Toggle 12V SS Power ON/OFF');
  Writeln('w = Toggle WiFi Power feed ON/OFF');
  Writeln('l = Toggle Alarm Lamp ON/OFF');
  Writeln('s = Start SS by sending a 1s pulse');
  Writeln('q = Quit the program and reset the control lines');
  Writeln('Press any key!');
  //Check input and act on commands
  repeat
    Read(cKey);
    case cKey of
      'p': //SS Power toggle command
...
  until cKey = 'q';
end;

I added debug printing to the case sections to see what was sent in and the answer was NOTHING!
It seems like Read() does not return anything for a simple key press unlike what happens in the Lazarus debug window. So the program probably just hangs on the Read(cKey) command, but in Lazarus it does not so it is impossible to debug...

Then I tested to use the Enter key and surprise! Now the relays operate...

But this should happen exactly when the key is pressed not when Enter is also pressed later. I use Read() instead of Readln() just in order to get one single key to process...

What could be done to fix this?

-- Bo Berglund Developer in Sweden
Bo Berglund Developer in Sweden

Reply by email

Mr Bee
to Bo Berglund

If the Free Vision code seems a bit complicated and complex to you, you may want to study the classic CRT unit (from the Turbo Pascal era). Basically it "draws" chars to the console screen, using method like ClrScr, GotoXY, WhereX, WhereY, etc. It's also able to read keystrokes, using method like ReadKey, Keypressed, etc. I think it's good enough for console app with simple interactions. However, I'm not sure whether it works with SSH and unicode. ?Mr Bee

Pada Jumat, 29 April 2016 1:28, Bo Berglund menulis:

On Thu, 28 Apr 2016 15:23:01 +0200, Bo Berglund
wrote:

I went ahead and created a new Console Application in Lazarus where I use the same object for controlling the GPIO pins as I did in the GUI program.

The Console program just initializes the control object then enters into a repeat loop reading a key from the user and then interpreting the key in a case construct for valid commands.
It exits if the q key is pressed.

When I run this in Lazarus all operates according to plan but as soon as I try to run it outside of the GUI, for example in a terminal in Raspbian or in a PuTTY terminal connected by SSH to the RPi literally nothing works of the stuff that should happen in the repeat loop!

What I get is the greeting message and then when I press the keys that should produce the action nothing at all happens including pressing q, which is the exit code out of the loop and should terminate the program.

For some reason it was possible to close it using Ctrl-C, though.

In Lazarus I use the debug window "Terminal Output" and here everything planned works fine!

What a mystery! This is the first time I have encountered such a difference!

After some further debugging I found that the keypresses are not even handled in the repeat loop. It uses this type of construct:

? //Display main screen
? Writeln('Controls are:');
? Writeln('p = Toggle 12V SS Power ON/OFF');
? Writeln('w = Toggle WiFi Power feed ON/OFF');
? Writeln('l = Toggle Alarm Lamp ON/OFF');
? Writeln('s = Start SS by sending a 1s pulse');
? Writeln('q = Quit the program and reset the control lines');
? Writeln('Press any key!');
? //Check input and act on commands
? repeat
? ? Read(cKey);
? ? case cKey of
? ? ? 'p': //SS Power toggle command
...
? until cKey = 'q';
end;

I added debug printing to the case sections to see what was sent in and the answer was NOTHING!
It seems like Read() does not return anything for a simple key press unlike what happens in the Lazarus debug window. So the program probably just hangs on the Read(cKey) command, but in Lazarus it does not so it is impossible to debug...

Then I tested to use the Enter key and surprise! Now the relays operate...

But this should happen exactly when the key is pressed not when Enter is also pressed later. I use Read() instead of Readln() just in order to get one single key to process...

What could be done to fix this?

-- Bo Berglund Developer in Sweden
Bo Berglund Developer in Sweden --

Reply by email

Kostas Michalopoulos
to Bo Berglund: On Thu, 28 Apr 2016 15:23:01 +0200, Bo Berglund I went ahead and created a new Console…

How about using the Crt unit? It implements a Turbo Pascal-compatible API under all supported targets and should work fine with terminals.

Example: http://pastebin.com/gzhsrv6x

Bo Berglund wrote 84 lines
On Thu, 28 Apr 2016 15:23:01 +0200, Bo Berglund wrote: I went ahead and created a new Console Application in Lazarus where I use the same object for controlling the GPIO pins as I did in the GUI program. The Console program just initializes the control object then enters into a repeat loop reading a key from the user and then interpreting the key in a case construct for valid commands. It exits if the q key is pressed. When I run this in Lazarus all operates according to plan but as soon as I try to run it outside of the GUI, for example in a terminal in Raspbian or in a PuTTY terminal connected by SSH to the RPi literally nothing works of the stuff that should happen in the repeat loop! What I get is the greeting message and then when I press the keys that should produce the action nothing at all happens including pressing q, which is the exit code out of the loop and should terminate the program. For some reason it was possible to close it using Ctrl-C, though. In Lazarus I use the debug window "Terminal Output" and here everything planned works fine! What a mystery! This is the first time I have encountered such a difference! After some further debugging I found that the keypresses are not even handled in the repeat loop. It uses this type of construct: //Display main screen Writeln('Controls are:'); Writeln('p = Toggle 12V SS Power ON/OFF'); Writeln('w = Toggle WiFi Power feed ON/OFF'); Writeln('l = Toggle Alarm Lamp ON/OFF'); Writeln('s = Start SS by sending a 1s pulse'); Writeln('q = Quit the program and reset the control lines'); Writeln('Press any key!'); //Check input and act on commands repeat Read(cKey); case cKey of 'p': //SS Power toggle command ... until cKey = 'q'; end; I added debug printing to the case sections to see what was sent in and the answer was NOTHING! It seems like Read() does not return anything for a simple key press unlike what happens in the Lazarus debug window. So the program probably just hangs on the Read(cKey) command, but in Lazarus it does not so it is impossible to debug... Then I tested to use the Enter key and surprise! Now the relays operate... But this should happen exactly when the key is pressed not when Enter is also pressed later. I use Read() instead of Readln() just in order to get one single key to process... What could be done to fix this? > >-- >Bo Berglund >Developer in Sweden -- Bo Berglund Developer in Sweden -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160507/c1b29797/attachment.html>

Reply by email