Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't drop Keypresses outside of readchar_linux() #74

Closed
wants to merge 1 commit into from

Conversation

vanschelven
Copy link
Contributor

Calling tty.setraw makes it so that subsequent calls to read() don't read
any of the typed-but-not-read characters. Reading the code, this could be
expected since tty.setraw is called without explicit parameters, and the
default for when
is TCSAFLUSH, which means:

If optional_actions is TCSAFLUSH, the change shall occur after all output
written to fildes is transmitted, and all input so far received but not
read shall be discarded before the change is made.
(emphasis mine)

Indeed, changing the call to be with TCSADRAIN seems to solve the problem of
missing keystrokes.

However, that solves the problem that any keystrokes that occur outside of
readchar are dropped fully, but it does not solve the problem that they will
be echoed. (They will be echoed because they occur at a point in time that
stdin is in "cooked" or "canonical" (non-raw) mode).

See #73

Calling `tty.setraw` makes it so that subsequent calls to `read()` don't read
any of the typed-but-not-read characters. Reading the code, this could be
expected since `tty.setraw` is called without explicit parameters, and the
[default for when](https://github.com/python/cpython/blob/345572a1a026/Lib/tty.py#L18)
is `TCSAFLUSH`, which means:

> If optional_actions is TCSAFLUSH, the change shall occur after all output
> written to fildes is transmitted, **and all input so far received but not
> read shall be discarded before the change is made.** (emphasis mine)

Indeed, changing the call to be with `TCSADRAIN` seems to solve the problem of
missing keystrokes.

However, that solves the problem that any keystrokes that occur outside of
`readchar` are dropped fully, but it does not solve the problem that they will
be echoed. (They will be echoed because they occur at a point in time that
stdin is in "cooked" or "canonical" (non-raw) mode).

See magmax#73
@Cube707
Copy link
Collaborator

Cube707 commented Jul 9, 2022

Hello,

I am working on similar problem over on https://github.com/Cube707/python-readchar/pull/5 and as my experiences with the unix-termianl are limited, your insigt might be helpfull. If you can find the time you may want to take a look.

@Cube707
Copy link
Collaborator

Cube707 commented Jul 29, 2022

this PR is no longer relevant in v4.0.0 but discussion on how to deal with this problem continues in the original issue

@Cube707 Cube707 closed this Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants