pyte icon indicating copy to clipboard operation
pyte copied to clipboard

Can't get contain '\r' input from Screen.buffer

Open 18853477039 opened this issue 4 years ago • 2 comments

this is my debug code

` buf = os.read(self.input.fileno(), 4096)

LOG.info(repr(buf)) `

when I send whoami by xshell's command bar the buf's log is [process_stdin():76] [PID:33553 TID:140554967484224] 'whoami\r'

Screen.buffer's log is '[root@fortress-test-169fb0752 ~]#' .

If I just use the shell, input whoami the buf's log is [process_stdin():76] [PID:66022 TID:139634374461248] 'w' [process_stdin():76] [PID:66022 TID:139634374461248] 'h' [process_stdin():76] [PID:66022 TID:139634374461248] 'o' [process_stdin():76] [PID:66022 TID:139634374461248] 'a' [process_stdin():76] [PID:66022 TID:139634374461248] 'm' [process_stdin():76] [PID:66022 TID:139634374461248] 'i' [process_stdin():76] [PID:66022 TID:139634374461248] '\r'

Screen.buffer's log is '[root@fortress-test-169fb0752 ~]# whoami'

So, how can I get the input contains '\r'?

18853477039 avatar Feb 20 '21 05:02 18853477039

I fix it by reading data from stdin, but it's a bad way because the logic is too bad. Is there a good way?

18853477039 avatar Mar 02 '21 07:03 18853477039

\r instructs the terminal to do a carriage return. The only way to get it printed in the input is to escape the \ before printing it. I.e. before feeding data to the stream you could do data.replace("\r", "\\r").

superbobry avatar Mar 03 '21 19:03 superbobry