Shop OBEX P1 Docs P2 Docs Learn Events
SimpleIDE terminal cursor control — Parallax Forums

SimpleIDE terminal cursor control

RsadeikaRsadeika Posts: 3,837
edited 2013-07-10 10:02 in Propeller 1
I started experimenting with cursor control, and the first problem I am running into is, Back Space backs up two characters instead of one. Am I using the code incorrectly? Also, when I test for a cursor left, nothing occurs, is there something that I am missing?

Ray
CON
  _clkmode   = xtal1 + pll16x                           
  _xinfreq   = 5_000_000

'' This program uses the terminal and some common tools, so
'' to use them, label the objects.                                 
OBJ

  term : "Extended_FDSerial"  '' An enhanced version of FullDuplexSerial (FDS)
''  misc : "tools"             '' My object that contains some common tools.
PUB Start
  '' Setup EFDS for a 115200 BAUD rate.
  ''         Rx,Tx,Mode,BAUD
  term.Start(31,30,0,115200)

  Main

PUB Main | inAbyte

  repeat
    repeat
      inAbyte := term.Rx
      term.Tx(inAbyte)
      if inAbyte == 10  '' Is it a CR
        CRLF
      if inAbyte == 8   '' Is it a Back Space
        term.Tx(8)      '' Moves back two characters
      if inAbyte == 3   '' Is it a cursor left
        term.Tx(3)      '' This does nothing
      
PUB CRLF
  term.Tx(13)  '' CR
  term.Tx(10)  '' LF

Comments

  • jazzedjazzed Posts: 11,803
    edited 2013-07-08 11:00
    Ray, can you try it without an interactive program?

    Code fragment ....
    /* start with a dot */
    putchar('.');
    /* dot shoudn't disappear. */
    while(1) {
      putchar(' ');
      putchar(8);
      waitcnt(CLKFREQ+CNT);
    }
    
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-07-08 11:14
    After I run the code segment, I see '.' then a space, then the flashing cursor. What I would expect is a '.', then a flashing cursor.

    Ray
  • jazzedjazzed Posts: 11,803
    edited 2013-07-08 11:40
    Rsadeika wrote: »
    After I run the code segment, I see '.' then a space, then the flashing cursor. What I would expect is a '.', then a flashing cursor.

    Ray

    Ugh, suffering from buffering again. No idea wtf putchar should be buffered.
    The simpletext library will solve that and many other stdio related print problems.

    Here is a more interesting example.
    /**
     * This is the main Spinner program file.
     */
    #include <stdio.h>
    #include <propeller.h>
    
    
    int main(void)
    {
      waitcnt(CLKFREQ+CNT);
      setvbuf(stdout, 0, _IONBF, 0);
    
    
      /* start with some dots. one gets erased */
      putchar('.');
      putchar('.');
    
    
      /* spinning wheel */
      while(1) {
        putchar('\b');
        putchar('-');
        waitcnt(CLKFREQ/10+CNT);
        putchar('\b');
        putchar('\\');
        waitcnt(CLKFREQ/10+CNT);
        putchar(8);
        putchar('|');
        waitcnt(CLKFREQ/10+CNT);
        putchar(8);
        putchar('/');
        waitcnt(CLKFREQ/10+CNT);
      }
      return 0;
    }
    
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-07-08 11:46
    OK, but what does all this have to do with Spin program in terminal mode?

    Ray
  • jazzedjazzed Posts: 11,803
    edited 2013-07-08 11:51
    Rsadeika wrote: »
    OK, but what does all this have to do with Spin program in terminal mode?

    Ray

    It is an example of backspace operation which is language agnostic.
    You were concerned about backspace operation not working.
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-07-08 12:17
    So, I tried my Spin cursor control program again, and I am still seeing a two position move when I use the Back Space key, not sure what is going on. Well, at least it is removing two characters when it moves to the left, I guess it could be worse. I am not sure about the '<-' key, I do not get anything out of that one.

    Ray
  • jazzedjazzed Posts: 11,803
    edited 2013-07-08 13:49
    Rsadeika wrote: »
    So, I tried my Spin cursor control program again, and I am still seeing a two position move when I use the Back Space key, not sure what is going on. Well, at least it is removing two characters when it moves to the left, I guess it could be worse. I am not sure about the '<-' key, I do not get anything out of that one.

    Ray

    Ray,

    Could your original program get two back-spaces because you enter a backspace and it gets echoed?

    Again, try a simple loop without entering keys ... in spin this time ... and see what happens.

    Arrow keys have different codes than back-space.
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-07-08 14:55
    The nearest that I can tell is when you have the (8)Backspace checked, the terminal screen shows one char being erased, which is what is expected. When I insert the
        if inAbyte == 8   '' Is it a Back Space        
          term.Tx(8)         " Do a backspace
    
    then this shows the double char delete.
    The larger problem is that if I am doing an RxStr how do I capture the Backspace press, and then remove the char from the RxStr input stream? This would be an even larger problem if I use the left cursor or right cursor keys to place the cursor on the char that I want to backspace/delete. I guess this is where I would want the power of C to take care of the issue. I will keep looking at this, but a push in the right direction would be appreciated.

    Ray
  • jazzedjazzed Posts: 11,803
    edited 2013-07-08 16:24
    Rsadeika wrote: »
    The nearest that I can tell is when you have the (8)Backspace checked, the terminal screen shows one char being erased, which is what is expected. When I insert the
        if inAbyte == 8   '' Is it a Back Space        
          term.Tx(8)         " Do a backspace
    
    then this shows the double char delete.

    Yes, that is expected behavior.
    Rsadeika wrote: »
    The larger problem is that if I am doing an RxStr how do I capture the Backspace press, and then remove the char from the RxStr input stream? This would be an even larger problem if I use the left cursor or right cursor keys to place the cursor on the char that I want to backspace/delete. I guess this is where I would want the power of C to take care of the issue. I will keep looking at this, but a push in the right direction would be appreciated.

    Ray I looked at the common serial input objects, and didn't see any input handling like this.

    The simpletext library is designed to handle backspace (and delete, but the terminal only recognizes backspace).

    Arrow keys are not handled. Arrow keys are defined for ANSI/VT100 terminals. ANSI terminal functions are beyond the scope of the Simple Terminal at this time.
  • AribaAriba Posts: 2,690
    edited 2013-07-08 18:33
    Ray

    You send the Backspace character twice, no wonder that it goes two spaces back:
    PUB Main | inAbyte
    
      repeat
        repeat
          inAbyte := term.Rx
          [COLOR="#FF0000"]term.Tx(inAbyte)   'first BackSpc[/COLOR]
          if inAbyte == 10  '' Is it a CR
            CRLF
          if inAbyte == 8   '' Is it a Back Space
            [COLOR="#FF0000"]term.Tx(8)[/COLOR]      '' Moves back two characters  [COLOR="#FF0000"](2nd BackSpc)[/COLOR]
          if inAbyte == 3   '' Is it a cursor left
            term.Tx(3)      '' This does nothing
    

    Andy
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-07-09 01:18
    Thanks Ariba, that is such a rookie mistake, I am embarrassed. I guess I should check for a special key press before I display the key press. Well that solves one problem.

    Ray
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-07-09 05:11
    The code segment below now works correctly when you press the Back Space key. I tried some of the other Simple Terminal Option codes, like (6) Move Cursor Down, that worked. But when I tried the (4)Move Cursor Right, that did not work, so far, the terminal option codes are not looking all that functional/useful in Spin mode. So the other option is to work towards a functioning external terminal program, like Putty, but then you run into problems when you use the Simple Terminal for a test run of the program. Kind of stuck here for the moment, things are not looking very promising.

    Ray
    CON
      _clkmode   = xtal1 + pll16x                           
      _xinfreq   = 5_000_000
    
    '' This program uses the terminal and some common tools, so
    '' to use them, label the objects.                                 
    OBJ
    
      term : "Extended_FDSerial"  '' An enhanced version of FullDuplexSerial (FDS)
      misc : "tools"             '' My object that contains some common tools.
    PUB Start
      '' Setup EFDS for a 115200 BAUD rate.
      ''         Rx,Tx,Mode,BAUD
      term.Start(31,30,0,115200)
    
      Main
    
    PUB Main | inAbyte
    
      repeat
        repeat
          inAbyte := term.Rx  '' Get the char
          if inAbyte == 8   '' Is it a Back Space
            inAbyte := 255   '' inAbyte is a blank space     
            term.Tx(8)      '' Moves back one char
          if inAbyte == 10  '' Is it a CR
            CRLF
          term.Tx(inAbyte)  '' Print the char
    
          
    PUB CRLF
      term.Tx(13)  '' CR
      term.Tx(10)  '' LF
    
  • jazzedjazzed Posts: 11,803
    edited 2013-07-09 05:29
    Interesting. Glad your testing this. I never dreamed that code 4 should add to a line. That's the way PST works though. I'll fix it.

    Postedit: Actually there is code to add to a line, but it doesn't work for some reason.
  • jazzedjazzed Posts: 11,803
    edited 2013-07-09 16:05
    Ray I posted a fix for your move right issue in the usual place (v0-9-35).

    The image also allows doing project-less spin compile if no project is open and no project exists with the same spin name.
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-07-10 02:39
    I started to test some more of the terminal codes, in this case (0), and (16) - Clear Screen. The command works in the start of the program, but it does not work when placed in the test for CR. Not sure what is going. The other thing that I noticed is when I removed 'CRLF', when in interactive mode, the CR still seems to work, so this could be a big problem when coding for an external program like TeraTerm.

    Ray
    CON
      _clkmode   = xtal1 + pll16x                           
      _xinfreq   = 5_000_000
    
    '' This program uses the terminal and some common tools, so
    '' to use them, label the objects.                                 
    OBJ
    
      term : "Extended_FDSerial"  '' An enhanced version of FullDuplexSerial (FDS)
      misc : "tools"             '' My object that contains some common tools.
    PUB Start
      '' Setup EFDS for a 115200 BAUD rate.
      ''         Rx,Tx,Mode,BAUD
      term.Start(31,30,0,115200)
    
      Main
    
    PUB Main | inAbyte
      misc.waitMS(1000)
      term.str(string("This is a test"))
      misc.waitMS(2000)
      repeat
        term.Tx(0)  '' This works, clear screen
        repeat
          inAbyte := term.Rx  '' Get the char
          if inAbyte == 8   '' Is it a Back Space
            inAbyte := 255   '' inAbyte is a blank space     
            term.Tx(8)      '' Moves back one char
          if inAbyte == 10  '' Is it a CR
    ''        CRLF
            term.Tx(0)  '' This does not work, clear screen
          term.Tx(inAbyte)  '' Print the char
    
          
    PUB CRLF
      term.Tx(13)  '' CR
      term.Tx(10)  '' LF
    
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-07-10 05:54
    Now, I am starting to get strange behavior, the program below is doing a clear the screen, and then moving the cursor to the x, and y positions. The problem is that I have not requested a clear the screen, and the second Position Cursor is not working. This looks serious, not sure if Spin is misbehaving or just the SimpleIDE terminal program?

    Ray
    CON
      _clkmode   = xtal1 + pll16x                           
      _xinfreq   = 5_000_000
    
    '' This program uses the terminal and some common tools, so
    '' to use them, label the objects.                                 
    OBJ
    
      term : "Extended_FDSerial"  '' An enhanced version of FullDuplexSerial (FDS)
      misc : "tools"             '' My object that contains some common tools.
    PUB Start
      '' Setup EFDS for a 115200 BAUD rate.
      ''         Rx,Tx,Mode,BAUD
      term.Start(31,30,0,115200)
    
      Main
    
    PUB Main | inAbyte
      misc.waitMS(1000)
      term.str(string("This is a test",13,10))
      misc.waitMS(2000)
      repeat
        term.Tx(15) '' y    this part works
        term.Tx(10)
        term.Tx(14) '' x
        term.Tx(20)
        repeat
          inAbyte := term.Rx  '' Get the char
          if inAbyte == 8   '' Is it a Back Space
            inAbyte := 255   '' inAbyte is a blank space     
            term.Tx(8)      '' Moves back one char
          if inAbyte == 10  '' Is it a CR
            CRLF
            term.Tx(15) '' y  This part does not work
            term.Tx(10)
            term.Tx(14) '' x
            term.Tx(20)
          term.Tx(inAbyte)  '' Print the char
    
          
    PUB CRLF
      term.Tx(13)  '' CR
      term.Tx(10)  '' LF
    
    
  • jazzedjazzed Posts: 11,803
    edited 2013-07-10 07:26
    Sending any value above 127 (255 in this case) starts a unicode sequence. Don't do that.

    Most likely your "broken" code is affected by the interpretation of Enter.
    One fix is to use "if inAbyte == 10 or inAbyte == 13 '' Is it a CR", but that won't be perfect
    The other fix is to use the Terminal options "Enter is NL" check-box.

    There are two interpretations of Enter depending on the operating system being used: 10 and 13.
    In the terminal options, you can choose what enter means.
    By default Enter is NL (10) is checked. If you uncheck "Enter is NL", Enter will be CR (13).
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-07-10 07:49
    The other fix is to use the Terminal options "Enter is NL" check-box.
    This will not work on a Windows PC, you have to have that unchecked in order for the interactive session CR to work properly.

    Is there a switch control, in SimpleIDE, to direct it to an external terminal program. It seems like it may be easier to find an external terminal program that has cursor, and screen control, then to keep getting surprises in the SimpleIDE terminal. It also seems like if you design the program for use with an external terminal program you will have difficulty in running correctly on the SimpleIDE serial program. But then there might be the case where I am the only guy that is doing this, so maybe I should just find another alternative.

    Ray
  • jazzedjazzed Posts: 11,803
    edited 2013-07-10 08:39
    Rsadeika wrote: »
    This will not work on a Windows PC, you have to have that unchecked in order for the interactive session CR to work properly.

    You have it backwards. Are you using Return instead of Enter?
  • jazzedjazzed Posts: 11,803
    edited 2013-07-10 10:02
    I've been thinking about this Enter -vs- Return Key problem. It gets worse across platforms.

    I'm thinking the terminal should just send 10 to the program if it gets either 10 or 13.
Sign In or Register to comment.