Skip to content

Conversation

@R44VC0RP
Copy link
Contributor

Summary

  • Fixed a bug where escape sequences like \x03 were passed as literal strings instead of being converted to actual bytes
  • Added parseEscapeSequences() function to convert escape sequences before writing to PTY

Problem

The pty_write tool documentation promises support for escape sequences:

Common escape sequences:
- Ctrl+C (interrupt): "\x03"
- Ctrl+D (EOF): "\x04"
- Arrow keys: "\x1b[A", etc.

However, when calling pty_write with data="\x03", the tool would write the literal 4-character string \x03 instead of the single byte 0x03 (Ctrl+C). This meant you couldn't actually interrupt processes or send control characters.

Solution

Added a parseEscapeSequences() function that converts:

  • \xNN → hex byte (e.g., \x03 → Ctrl+C)
  • \uNNNN → unicode character
  • \n, \r, \t → respective control characters
  • \\ → literal backslash

Testing

Tested by spawning a ping localhost process and sending \x03 - the process now correctly receives the interrupt signal.

The pty_write tool was receiving escape sequences like \x03 as literal
strings instead of converting them to actual bytes. This meant sending
Ctrl+C (\x03) would write the 4 characters '\x03' instead of the
interrupt signal byte.

Added parseEscapeSequences() function that converts:
- \xNN to hex bytes (e.g., \x03 → Ctrl+C)
- \uNNNN to unicode characters
- \n, \r, \t to their respective control characters
- \\\\ to literal backslash

This fixes the documented behavior in write.txt which promises escape
sequence support.
@shekohex shekohex merged commit c54b390 into shekohex:main Dec 30, 2025
@shekohex
Copy link
Owner

Thank you, merged and released. Please update to v0.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants