read doesn't block on Mac OS X

Dave Brondsema avatarDave Brondsema created an issue

When I call getch() on Mac OS X, the first call is blocking and waits for a keypress. But subsequent calls immediately returns an empty string rather than blocking for a keypress. As best I can tell, the termios.tcsetattr call to restore the old settings (vmin and vtime) does not take affect. Calling tcgetattr shows that vmin & vtime have been restored, but apparently something is causing them not to work. I've tried changing that tcsetattr method to use the TCSANOW or TCSAFLUSH flags, but it doesn't help.

The root problem seems like it might be within OS X or an OS X library, but a workaround in this "pager" library would be extremely helpful.

Comments (2)

  1. Dave Brondsema

    Unfortunately those recipes don't work. They're very old and the carbon imports don't work any more. Carbon was deprecated before OS X.

    I looked at PyObjC and Cocoa/Quartz libraries. They are probably the best way to get keypresses directly from OSX, but are quite complicated and seem to require a lot of setup in your application, including running an event loop. That doesn't seem like a good fit for the 'pager' package.

    In theory OS X terminals are POSIX compatible, it just seems to be buggy here :(

  2. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.