Skip to content

System.Console.Read() needlessly changes terminal settings on linux #49129

Description

@webczat

I have noticed that when using Console.Read on linux, the method disables canonical mode (ICANON) flag when reading, may apply to mac too.
Generally while ReadKey reads key by key and to do this it's needed to disable canonical mode and possibly echo when requested, read reads single characters, but actually blocks until newline before starting to return characters, so works similarly to scanf/cin/whatever in other languages.
However, linux itself would handle that just fine in canonical mode, so that the Read call does not have to turn it off. Turning it off makes it impossible to, for example, erase typed characters before pressing return key, or use standard terminal editing features like ctrl+u to erase line.
In canonical mode linux would start returning characters one by one, but only when the user presses enter on a terminal. Pretty sure it's standard unix behavior, and likely same for OSX.
Of course it is also an expected behavior when the program behaves like standard unix tools and just reads from standard input, if user runs it interactively, input is accepted line by line even if the program is not really doing line based input parsing. That way user still has limited edit capability but the program itself still has freedom when it goes to the way it reads input.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions