Implement rudimentary version of module termios
#1879
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
termios
— a module for low-level terminal I/O system control. It doesn't do much beside defining a bunch of system-specific constants and a few direct POSIX calls.[1][2] The API is old, so old actually that I think it may be obsolete/unused. Anyone needing to set the baud rate to 300 bytes/second? 6 bits per character? On macOS, for instance, some mandatory but kind of obsolete POSIX flags are defined in the header files, but the syscalls don't support them (or not anymore). However, there are a few things that are still quite useful nowadays and perhaps impossible to perform in any other way in a portable fashion. The two common I have encountered:The implementation of
termios
in this PR is quite rudimentary, meant primarily to be enough to support moduletty
from StdLib (and some other 3rd party ones). The constants defined here are the subset whattermios
from CPython defines. See also #1308The Constants
I tried to be thorough but did not try to be complete. The constants defined are the ones in use from other modules (that I have noticed), but once a constant or flag was used, I tried to define the remaining ones from the same group, just for completeness (with the exception of the
TIOC*
codes). This PR comes from my stash some 4 years ago, before we hadgenerate_os_codes.py
, so all constants are hand-crafted, not generated. To generate them would be messy anyway, because of a lack of clear naming. Perhaps in the future theTIOC*
codes can be generated.The Functions
This is a mock implementation of
termios
; it doesn't actually do any syscalls. Instead it emulates the minimal functionality needed bytty
by using .NET/IronPython internals, and only forstdin
. Now that we have genuine file descriptors implemented, this mock code can be replaced by actual syscalls. This will have to be through P/Invoke, as Mono.Unix does not support the termios API (I saw it marked as TODO in Mono). The calls are simple, but the data structure marshalled not so.