selectel / pyte

Simple VTXXX-compatible linux terminal emulator
http://pyte.readthedocs.org/
GNU Lesser General Public License v3.0
649 stars 101 forks source link

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

Open 18853477039 opened 3 years ago

18853477039 commented 3 years ago

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' [processstdin():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 commented 3 years ago

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?

superbobry commented 3 years ago

\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").