Shop OBEX P1 Docs P2 Docs Learn Events
FlexProp Clear Screen "C" — Parallax Forums

FlexProp Clear Screen "C"

ShawnaShawna Posts: 508
edited 2020-11-11 22:54 in Propeller 1
I have been playing around with FlexProp the last couple of days and I am getting stuck on a stupid problem. I want to be able to clear the terminal screen.

In SimpleIDE I would use.
term_cmd(CLS);

I have tried the following with no luck.
clrscr();
system("clear");
printf("%c",16);
printf("\x10");
printf("%c", CLS);
print("%c", CLS);

How does one clear the terminal screen with the print() function or the printf() function?

This is a stupid problem I am having, but a problem none the less.

Thanks
Shawn A.

Comments

  • The terminal is ANSI based so the following should work.

    puts("\x1b[0;0H"); // move cursor
    puts("\x1b[2J"); // clear to end of display

    ESC [ 0;0H
    ESC [ 2J

    Mike
  • RaymanRayman Posts: 14,640
    Yes, @ersmith told me this recently:

    The terminal is just the standard Windows terminal. This uses standard ANSI escape codes (https://en.wikipedia.org/wiki/ANSI_escape_code). For example, home is ESC-[-H, clear from current cursor position to end of screen is ESC-[-J.
  • ShawnaShawna Posts: 508
    edited 2020-11-12 18:20
    Thanks for the help guys but I can't seem to get it to work. Attached is the sample code and a screen shot of the terminal. I am using the FlexProp Gui and the default terminal that comes with it. The problem might be the terminal emulator. I am playing around with PuTTy right now to see if it is a terminal issue.


    What code do you guys use to clear the terminal?


    #include <simpletools.h>
    //#include <stdio.h>
    
    int main(){
        
        while(1){        
        	puts("\x1b[0;0H"); // move cursor
            puts("\x1b[2J");   // clear to end of display
        	print("Hello\n");
        	print("Shawn\n");
        	pause(5000);
        	}
        }
    
    

    41da0ffefe78dfff28380312bb52ad.png
    1111 x 647 - 20K
  • RaymanRayman Posts: 14,640
    I'm doing it like this:
    //Terminal escape sequenses
    #define ESC "\x1b"
    #define CSI "\x1b["
    
                    printf(CSI "2J"); // Clear screen
                    printf(CSI "1;1H"); // Home
    
  • Rayman, what terminal window do you use? Do you use the FlexPropGui?
  • RaymanRayman Posts: 14,640
    edited 2020-11-12 20:33
    I'm running flexspin from the command line (Well, actually using Visual Studio, but same result).
    But, assuming you're in Windows, it should be the same terminal.

  • RaymanRayman Posts: 14,640
    I just remembered that there are two different terminal options...
    One is the regular ANSI one, which I think is the default. This is the one I'm using.
    The other is a PST compatible terminal. This one probably has different codes to control the screen.
    You might want to check the FlexProp GUI settings to make sure...
  • I read the Visual Studio guide you have on your website for FlexProp. I'm not ready to pull the trigger on that yet but it looks interesting. This clear screen hiccup is a small hurdle that I can't seem to get over. Which is dumb, my goal is to see if I can figure out how to create libraries in C using the FlexProp compiler, I like the idea of being able to blend C, Spin and PASM code together. Whether I am successful or not it will be a good learning experience.
  • RaymanRayman Posts: 14,640
    edited 2020-11-12 21:09
    I've modified this time example with the above.
    This works for me on P2 with FlexProp GUI. Imagine will work on P1 too.

    Oh, wait, this is a P2 specific example...
    c
    c
  • RaymanRayman Posts: 14,640
    I just tried it on a P1 and see your issue... Doesn't work for me either...

    Seems the loader is different... P1 uses proploader...
  • Does Windows' command prompt support ANSI escape sequences/control codes by default? Showing that left arrow in place of the terminal actually interpreting the ESCape suggests it doesn't. I find some conflicting information that suggests it might not be supported, at least by default. I also see mention of it being enabled by default on more recent builds.
  • RaymanRayman Posts: 14,640
    I can't find any way to clear the P1 terminal window either...

    I think I'd report this to @ersmith
  • RaymanRayman Posts: 14,640
    Seems that some of the ASCII commands work...

    If everything is on one line, you can send a bunch of backspace characters to clear the current line...
            for (int i=0;i<50;i++)
            {
            	putchar(8);
            }
    
  • Does the Windows version of FlexProp just run cmd.exe along with the compile and run commands? (Commands > Configure commands)
    If that's the case, I think it'd be the same when invoked outside of flexprop (i.e., if you were to run it manually on the command line). I think the capabilities of the built-in terminal functionality of the loader depend on the capabilities of whatever terminal emulator it's being run in (so, if cmd.exe is the terminal, and it doesn't interpret ANSI control codes, it won't work). I could be wrong, though - definitely no Windows buff...
  • Yeah, I'm not sure what to say. I did get it to work in PuTTy.

    I tried the following code in SimpleIDE and had the same result as in FlexPropGui. I suppose that's because they both use Proploader for the P1?
    #include <simpletools.h>
    //#include <stdio.h>
    
    int main(){
        
        while(1){        
        	puts("\x1b[0;0H"); // move cursor
            puts("\x1b[2J");   // clear to end of display
        	print("Hello\n");
        	print("Shawn\n");
        	pause(5000);
        	}
        
    

  • avsa242 wrote: »
    Does the Windows version of FlexProp just run cmd.exe along with the compile and run commands? (Commands > Configure commands)
    Yes that's correct.

    avsa242 wrote: »
    If that's the case, I think it'd be the same when invoked outside of flexprop (i.e., if you were to run it manually on the command line).
    This does seem to be the case.


    I ended up creating a custom PuTTy session and creating a shortcut on my desktop for it. I also removed the -t from the configuration Run Command in FlexProp. Its seems by removing the -t the default terminal will not open when the Compile And Run button is pressed.
    cmd.exe /c start "Propeller Output %p" "%D/bin/proploader" -Dbaudrate=%r %P "%B" -r  -t -k
    


    I played around with the run commands to try and get it to launch my PuTTy session automatically but failed. I think I was close, either way I learned a little bit more about the command line options.

    Thanks for all the input guys.

    Shawn A.
  • RaymanRayman Posts: 14,640
    In that case, you could use the Parallax Serial Terminal.
    It has pretty clear cut screen controls (click on the "Prefs..." Button to see).

    It has an automatic disable function when you go to another window, so can get into it fast.
  • @Rayman, I just fired up the Parallax Serial Terminal. I forgot about the automatic disable feature, its pretty slick. This configuration will do while I experiment with the FlexPropGui.


    Thanks Again

    Shawn A.
  • I think eric mentioned that there is some setting he does to force the windows cmd window into ansi mode .

    Mike
  • msrobots wrote: »
    I think eric mentioned that there is some setting he does to force the windows cmd window into ansi mode .

    @msrobots I investigated this via the google and found a workaround. In the Registry Editor under HKEY_CURRENT_USER\Console I added a DWORD named "VirtualTerminalLevel" and gave it a value of 0x1.

    The following code will clear the display, but instead of placing the cursor at line 0 column 0, it places it at line 1 column 0. I'm not sure why but I can live with it.
    puts("\x1b[2J");          // clear to end of display.  ANSI Based
    puts("\x1b[0;0H");      // move cursor.  ANSI Based
    

    Thanks
    Shawn A.
  • puts() automatically moves the cursor to the next line, so this explains why the cursor is going to line 1 column 0.
  • proploader (the P1 loader) doesn't explicitly enable ANSI mode in the Windows console. it relies on the default setting. In Windows 10 there's a control panel setting to make ANSI the default for any cmd.exe, but I don't remember it off-hand.

    I'll try to dig through the P1 loader code and see if I can figure out how to make ANSI the default, as it is in the P2 loader.
Sign In or Register to comment.