Closed qianyun210603 closed 2 years ago
tests passed
most of this should be solved by #79
Issue to be solve here has been included in a more comprehensive refactoring by Cube707. Close this and any further discussion should be directed to https://github.com/Cube707/python-readchar/pull/5
I'd like to introduce this pull request to make below fix/improve:
Inconsistent return of
readchar
function on windows 10 and linux platformmsvcrt.getch()
.use
setcbreak
instead ofsetraw
on linux platform to avoid unwanted, mysteriously-generated blank characters, then overwrite the result by the desired code of "ENTER", instead of usingsetraw
and bear the blank characters.setraw
tosetcbreak
. And this was released in v3.0.1.readchar
function to\x0a
(Line feed,'\n'
) from\x0d
(Carriage Return,'\r'
). Where the latter is desired by some other lib (likeinquirer
) from @C0D3D3V 's test.\x0a
(Line feed,'\n'
) and\x0d
(Carriage Return,'\r'
). Also on windows since the line break is defined as '\r\n', but on linux it is defined as '\n' only. I think this should be whysetcbreak
returns\x0a
(Line feed,'\n'
) on linux.setcbreak
instead ofsetraw
to avoid the white spaces issue, and then overwrite the the return to the desired "ENTER KEY" code afterwards in the function (as mentioned before, there should be no modern keyboard which have separate key to generate both\x0a
(Line feed,'\n'
) and\x0d
(Carriage Return,'\r'
)).@magmax would you give this some consideration please.