Search code examples
terminalpascalmacos-sierra

Pascal - Clearing terminal


Getting started with Pascal here. I wanted to write a simple program that first clears the terminal window and then reads user input. The first result of searching for clearing the screen showed the ClrScr procedure. Using it gets the job done but ClrScr needs Crt which results in a new problem. Terminating the program using Ctrl + C does not work. Searching online again, I found that Crt takes over I/O. I have been looking for alternative to ClrScr but haven't really found anything so far.

So how can I clear terminal while still being able to terminate the program using Ctrl + C. Also how can I terminate the program in the current case using Crt?

Current Code:

    program Test;
    uses Crt;
    var     
            x : integer;
    begin
            read(x);
    end.

Solution

  • So far the solutions I have seen online and the ones suggested in the comments for keeping CRT just make it troublesome and unnecessary makes the program complex. So for now I have decided just to discard it totally.

    The workaround I have found now is to use unix.fpsystem with the clear command which gets the job done just fine.