[Lazarus] Example of full screen console program anywhere?
Kostas Michalopoulos
badsectoracula at gmail.com
Sat May 7 03:04:07 CEST 2016
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
On Thu, Apr 28, 2016 at 9:27 PM, Bo Berglund <bo.berglund at gmail.com> wrote:
> On Thu, 28 Apr 2016 15:23:01 +0200, Bo Berglund
> <bo.berglund at gmail.com> 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
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160507/c1b29797/attachment-0002.html>
More information about the Lazarus
mailing list