toggles cbreak mode on terminal
Project description
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=}")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
toggle_cbreak-0.0.2.tar.gz
(2.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file toggle_cbreak-0.0.2.tar.gz.
File metadata
- Download URL: toggle_cbreak-0.0.2.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c25c97ce9a8aa6843440f741880a9ea1778a28884c91ee025e0504d27030875
|
|
| MD5 |
f905fbf2bf8dd1949bff639a0a526352
|
|
| BLAKE2b-256 |
80c805d0ccdf4a59c7b3dafd7c5be9482e39d37dfa5e785c2a6e9b89472beee8
|
File details
Details for the file toggle_cbreak-0.0.2-py3-none-any.whl.
File metadata
- Download URL: toggle_cbreak-0.0.2-py3-none-any.whl
- Upload date:
- Size: 2.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bd967018f1d53088e988927b9f07425638885048640db798d4e542be821bdb2
|
|
| MD5 |
fd60da8986bd880218f7675de0e29925
|
|
| BLAKE2b-256 |
c2726bbf425cc9635271d10595dd7ac66ef271f02407f6160bccf233b29a56b8
|