Skip to content

Commit 101f9bc

Browse files
committed
Add documentation for tty_escape
1 parent 4879590 commit 101f9bc

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ The table below shows which release corresponds to each branch, and what date th
108108
[2405]: https://github.com/Gallopsled/pwntools/pull/2405
109109
[2427]: https://github.com/Gallopsled/pwntools/pull/2405
110110
[2382]: https://github.com/Gallopsled/pwntools/pull/2382
111+
[2435]: https://github.com/Gallopsled/pwntools/pull/2435
111112

112113
## 4.13.0 (`beta`)
113114

pwnlib/util/fiddling.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,24 @@ def js_unescape(s, **kwargs):
10991099
return b''.join(res)
11001100

11011101
def tty_escape(s, lnext=b'\x16', dangerous=bytes(bytearray(range(0x20)))):
1102+
r"""tty_escape(s, lnext=b'\x16', dangerous=bytes(bytearray(range(0x20)))) -> bytes
1103+
1104+
Escape data for terminal output. This is useful when sending data to a
1105+
terminal that may interpret certain bytes as control characters.
1106+
1107+
Check ``stty --all`` for the current settings on your terminal.
1108+
1109+
Arguments:
1110+
s (bytes): The data to escape
1111+
lnext (bytes): The byte to prepend to escape the next character. Defaults to ^V.
1112+
dangerous (bytes): The bytes to escape
1113+
1114+
Returns:
1115+
The escaped data.
1116+
1117+
>>> tty_escape(b'abc\x04d\x18e')
1118+
b'abc\x16\x04d\x16\x18e'
1119+
"""
11021120
s = s.replace(lnext, lnext * 2)
11031121
for b in bytearray(dangerous):
11041122
if b in lnext: continue

0 commit comments

Comments
 (0)