Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.3k
gh-85984: New additions and improvements to the tty library.#101832
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
7 commits Select commitHold shift + click to select a range
33f1871
New additions to the tty library. Functions added: cfmakeraw(), and c…
8vasu0bb5baf
📜🤖 Added by blurb_it.
blurb-it[bot]fb5e28c
Merge branch 'main' into tty_new_additions
8vasu286e30c
Add versionadded tags and improve NEWS.
gpsheadc35b85f
Merge branch 'main' into tty_new_additions
gpshead96c03d5
versionadded indentation
gpshead970c419
Merge branch 'tty_new_additions' of https://github.com/8vasu/cpython …
gpsheadFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
NextNext commit
New additions to the tty library. Functions added: cfmakeraw(), and c…
…fmakecbreak(). Thefunctions setcbreak() and setraw() now return original termios to save an extra tcgetattr() call.Signed-off-by: Soumendra Ganguly <soumendraganguly@gmail.com>
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit33f1871b8b8b567f3d2bfb7f216a63491426eade
There are no files selected for viewing
18 changes: 16 additions & 2 deletionsDoc/library/tty.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
70 changes: 54 additions & 16 deletionsLib/tty.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -4,9 +4,9 @@ | ||
from termios import * | ||
__all__ = ["cfmakeraw", "cfmakecbreak", "setraw", "setcbreak"] | ||
#Indices for termios list. | ||
IFLAG = 0 | ||
OFLAG = 1 | ||
CFLAG = 2 | ||
@@ -15,22 +15,60 @@ | ||
OSPEED = 5 | ||
CC = 6 | ||
def cfmakeraw(mode): | ||
gpshead marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
"""Make termios mode raw.""" | ||
# Clear all POSIX.1-2017 input mode flags. | ||
# See chapter 11 "General Terminal Interface" | ||
# of POSIX.1-2017 Base Definitions. | ||
mode[IFLAG] &= ~(IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP | | ||
INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF) | ||
# Do not post-process output. | ||
mode[OFLAG] &= ~OPOST | ||
# Disable parity generation and detection; clear character size mask; | ||
# let character size be 8 bits. | ||
mode[CFLAG] &= ~(PARENB | CSIZE) | ||
mode[CFLAG] |= CS8 | ||
# Clear all POSIX.1-2017 local mode flags. | ||
mode[LFLAG] &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON | | ||
IEXTEN | ISIG | NOFLSH | TOSTOP) | ||
# POSIX.1-2017, 11.1.7 Non-Canonical Mode Input Processing, | ||
# Case B: MIN>0, TIME=0 | ||
# A pending read shall block until MIN (here 1) bytes are received, | ||
# or a signal is received. | ||
mode[CC][VMIN] = 1 | ||
mode[CC][VTIME] = 0 | ||
def cfmakecbreak(mode): | ||
"""Make termios mode cbreak.""" | ||
# Do not map CR to NL on input. | ||
mode[IFLAG] &= ~(ICRNL) | ||
# Do not echo characters; disable canonical input. | ||
mode[LFLAG] &= ~(ECHO | ICANON) | ||
# POSIX.1-2017, 11.1.7 Non-Canonical Mode Input Processing, | ||
# Case B: MIN>0, TIME=0 | ||
# A pending read shall block until MIN (here 1) bytes are received, | ||
# or a signal is received. | ||
mode[CC][VMIN] = 1 | ||
mode[CC][VTIME] = 0 | ||
def setraw(fd, when=TCSAFLUSH): | ||
"""Put terminal into raw mode.""" | ||
mode = tcgetattr(fd) | ||
new = list(mode) | ||
cfmakeraw(new) | ||
tcsetattr(fd, when, new) | ||
return mode | ||
def setcbreak(fd, when=TCSAFLUSH): | ||
"""Put terminal into cbreak mode.""" | ||
mode = tcgetattr(fd) | ||
new = list(mode) | ||
cfmakecbreak(new) | ||
tcsetattr(fd, when, new) | ||
return mode |
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.