Use FIONREAD to get the number of characters available for reading on stdin
This commit is contained in:
parent
d9003af7a1
commit
63672a28d5
|
@ -1,3 +1,7 @@
|
|||
2020-11-03 Markus Gans <guru.mail@muenster.de>
|
||||
* Use FIONREAD to get the number of characters available
|
||||
for reading on stdin
|
||||
|
||||
2020-11-02 Markus Gans <guru.mail@muenster.de>
|
||||
* Non-blocking reading before timeout after keystroke
|
||||
* Every fourth event processing causes a terminal flush
|
||||
|
|
|
@ -28,9 +28,6 @@ int main (int argc, char* argv[])
|
|||
// Create the application object
|
||||
finalcut::FApplication app{argc, argv};
|
||||
|
||||
// Enable the non-blocking reading mode
|
||||
//app.setNonBlockingRead();
|
||||
|
||||
// Create a simple dialog box
|
||||
finalcut::FMessageBox mbox{&app};
|
||||
mbox.setText("Hello world");
|
||||
|
|
|
@ -21,9 +21,11 @@
|
|||
***********************************************************************/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#if defined(__CYGWIN__)
|
||||
#include <sys/select.h> // need for FD_ZERO, FD_SET, FD_CLR, ...
|
||||
#include <sys/socket.h> // need for FIONREAD
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -466,7 +468,14 @@ FKey FKeyboard::UTF8decode (const char utf8[]) const
|
|||
inline ssize_t FKeyboard::readKey()
|
||||
{
|
||||
setNonBlockingInput();
|
||||
const ssize_t bytes = read(FTermios::getStdIn(), &read_character, 1);
|
||||
int len{0};
|
||||
|
||||
if ( ioctl(FTermios::getStdIn(), FIONREAD, &len) >= 0 && len > int(FIFO_BUF_SIZE) )
|
||||
len = int(FIFO_BUF_SIZE);
|
||||
else
|
||||
len = 1;
|
||||
|
||||
const ssize_t bytes = read(FTermios::getStdIn(), &read_character, std::size_t(len));
|
||||
unsetNonBlockingInput();
|
||||
return bytes;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue