Skip to content

Commit e1e4aa3

Browse files
fix: Add comments about ICANON and IEXTEN
1 parent 537392c commit e1e4aa3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Lib/getpass.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,14 @@ def unix_getpass(prompt='Password: ', stream=None, *, echo_char=None):
111111
# Extract control characters before changing terminal mode
112112
term_ctrl_chars = None
113113
if echo_char:
114-
# Disable canonical mode so we can read char by char
114+
# ICANON enables canonical (line-buffered) mode where
115+
# the terminal handles line editing. Disable it so we
116+
# can read input char by char and handle editing ourselves.
115117
new[3] &= ~termios.ICANON
116-
# Disable IEXTEN so Ctrl+V (LNEXT) is not intercepted
117-
# by the terminal driver and can be handled by our code
118+
# IEXTEN enables implementation-defined input processing
119+
# such as LNEXT (Ctrl+V). Disable it so the terminal
120+
# driver doesn't intercept these characters before our
121+
# code can handle them.
118122
new[3] &= ~termios.IEXTEN
119123
term_ctrl_chars = _get_terminal_ctrl_chars(fd)
120124
tcsetattr_flags = termios.TCSAFLUSH

0 commit comments

Comments
 (0)