get_kbrd() patch

2009-06-03
2013-06-03
  • Fernando Silveira

    As I could not find a mailing list, forum or any information about how to properly submit patches, here follows one to fix the get_kbrd() function behaviour.

    This patch will make it read only one character when called, just as IDL does. For that all I did is set stdin to non-echo and non-canonical mode. I still don't know how to do that (if possible) using just 'readline' APIs.

    get_kbrd() still needs to handle scalar variables properly, I think.

    Please apply it if possible.

    PS: The coding style used in this patch might be different than the used in the whole GDL project. I also could not find any document or reference to it.

    diff --git a/gdl/src/basic_fun.cpp b/gdl/src/basic_fun.cpp
    index aae8c72..c7dfc51 100644
    --- a/gdl/src/basic_fun.cpp
    +++ b/gdl/src/basic_fun.cpp
    @@ -21,6 +21,9 @@

    #include "includefirst.hpp"

    +#include <termios.h>
    +#include <unistd.h>
    +
    #include <string>
    #include <fstream>
    //#include <memory>
    @@ -4457,19 +4460,24 @@ namespace lib {
              }
           }

    -    if( doWait)
    -      {
    -
    -       char c = cin.get();
    -       DStringGDL* res = new DStringGDL( DString( i2s( c)));
    -       return res;
    -      }
    -    else
    -      {
    -       char c = cin.get();
    -       DStringGDL* res = new DStringGDL( DString( i2s( c)));
    -       return res;
    -      }
    +    // TODO Implement proper SCALAR parameter handling (doWait variable?).
    +
    +    struct termios orig, get;
    +    (void)tcgetattr(fileno(stdin), &orig);
    +    get = orig;
    +
    +    // Disable terminal echoing and set it to non-canonical mode.
    +    get.c_lflag &= ~(ECHO|ICANON);
    +
    +    (void)tcsetattr(fileno(stdin), TCSANOW, &get);
    +
    +    char c = cin.get();
    +
    +    // Restore original terminal settings.
    +    (void)tcsetattr(fileno(stdin), TCSANOW, &orig);
    +
    +    DStringGDL* res = new DStringGDL( DString( i2s( c)));
    +    return res;
       }

       BaseGDL* temporary( EnvT* e)

     
    • Marc Schellens

      Marc Schellens - 2009-08-23

      I appied your patch.
      It is in the CVS.
      Thanks,
      Marc

       

Log in to post a comment.