fix: parse escape sequences in pty_write input #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
\x03were passed as literal strings instead of being converted to actual bytesparseEscapeSequences()function to convert escape sequences before writing to PTYProblem
The
pty_writetool documentation promises support for escape sequences:However, when calling
pty_writewithdata="\x03", the tool would write the literal 4-character string\x03instead of the single byte0x03(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 backslashTesting
Tested by spawning a
ping localhostprocess and sending\x03- the process now correctly receives the interrupt signal.