toggle_cbreak
Simple lib to turn cbreak mode on and off
Installation
pip install toggle_cbreak
Quickstart
from toggle_cbreak import cbreak_off, cbreak_on
# by default, our terminal is now in cooked mode
cbreak_on() # turns on cbreak mode
# now, we are in cbreak mode
cbreak_off()
# now, we are in cooked mode again
Some context on terminal modes
Our terminal has 3 modes:
- cooked mode (default)
- raw mode
- cbreak mode
Cooked mode (default)
- data is preprocessed before being given to program
- system intercepts special characters, and gives special behaviour to them
- eg. Backspace, Control-C, etc
- Let's say you type
"ABC<Backspace>D"- in cooked mode, this is processed as
"ABD" - the
<Backspace>in a way, deletes ourC
- in cooked mode, this is processed as
Raw mode
- data is passed as it is to program
- system does not interpret special characters as special characters
- Let's say you type
"ABC<Backspace>D""ABC<Backspace>D"itself is given to our program- no processing done
Cbreak mode
- a mode between cooked mode and raw mode
- only certain characters eg. Control-C will be processed as special characters
Simple example (copy paste this and try it out)
from toggle_cbreak import cbreak_off, cbreak_on
firstname = input("(cooked mode) Enter first name: ")
cbreak_on()
print(
"(cbreak mode) Enter some text. "
"Whatever you type will be repeated multiple times as you type. "
"Hit Control-C to escape this mode."
)
try:
while True:
char = sys.stdin.read(1)
print(char * random.randrange(1, 4), end="", flush=True)
except KeyboardInterrupt:
pass
cbreak_off()
print("\nBack to normal cooked mode.\n")
lastname = input("(cooked mode) Enter last name: ")
print(f"{firstname=} {lastname=}")
Metadata
Release files for toggle-cbreak 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| toggle_cbreak-0.0.3.tar.gz | 2.8 kB | Without provenance | Details for toggle_cbreak-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| toggle_cbreak-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for toggle_cbreak-0.0.3-py3-none-any.whl |
Total release size: 5.5 kB
Release files / toggle_cbreak-0.0.3.tar.gz
| Download URL | toggle_cbreak-0.0.3.tar.gz |
|---|---|
| Size | 2.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fac597781400ffc6ae760dbdfb4e68b1523f7ce6aa065c5089c8341f97b54a35
|
|
BLAKE2b-256 checksum How to use checksums |
7f654a1a90430c45e9d991f7f0a847fc99f0f5c1bed1934f05b7319d7d671150
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|
Release files / toggle_cbreak-0.0.3-py3-none-any.whl
| Download URL | toggle_cbreak-0.0.3-py3-none-any.whl |
|---|---|
| Size | 2.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
71d1c9ab78fc202b5b94551225892268d84886aec1caca6c87d275f6dcf9229d
|
|
BLAKE2b-256 checksum How to use checksums |
00a8385190a0c7c9126e40cfb1961dd2f7991d6c3c7e41b17dba75963d8ee11e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|
Security for toggle-cbreak 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.