Skip to content

Make ConsoleHost honor NoEcho on Unix platforms - #3801

Merged
Dongbo Wang (daxian-dbw) merged 1 commit into
PowerShell:masterfrom
JamesWTruher:jameswtruher/ReadKeyNoEcho
Jun 9, 2017
Merged

Make ConsoleHost honor NoEcho on Unix platforms#3801
Dongbo Wang (daxian-dbw) merged 1 commit into
PowerShell:masterfrom
JamesWTruher:jameswtruher/ReadKeyNoEcho

Conversation

@JamesWTruher

@JamesWTruher James Truher (JamesWTruher) commented May 17, 2017

Copy link
Copy Markdown
Collaborator

Fix #3183
this also affects Linux as well.

This does not provide support for IncludeKeyDown or IncludeKeyUp, but does not
echo the character when provided. In order to support IncludeKeyDown and IncludeKeyUp a
more substantial rewrite will be needed as Console.ReadKey doesn't support this behavior.

@JamesWTruher

Copy link
Copy Markdown
Collaborator Author

I should add that I haven't been able to figure out a way to actually test this other than manually. I investigated how the corefx guys test Console.ReadKey, and they do it manually. That is, their automation calls a test which then requires that a user type keys which are then validated by the user.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key = Console.ReadKey(options.HasFlag(NoEcho))?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we should avoid HasFlag, because it's much, much more expensive than a simple bitwise test. HasFlag calls into a native implementation -- see the implementation here: https://github.com/dotnet/coreclr/blob/e67851210d1c03d730a3bc97a87e8a6713bbf772/src/vm/reflectioninvocation.cpp#L3699

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please remove the extra empty line?

@daxian-dbw Dongbo Wang (daxian-dbw) changed the title fix for issue #3183, honor NoEcho on OSX Make ConsoleHost honor NoEcho on Unix platforms May 24, 2017
@daxian-dbw

Copy link
Copy Markdown
Member

Title updated -- it's recommended to briefly describe what is fixed in the PR title, and put "Fix #" in the PR's body. See the contribution.md at https://github.com/PowerShell/PowerShell/blob/master/.github/CONTRIBUTING.md#pull-request-submission

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid the use of the HasFlag api - it is much, much slower than the simple bit test - see the implementation here. The expensive part is mostly boxing, but you can see it does other work before the simple bitwise test.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be better to get uniform input - one person's opinion vs another. My original code was requested to change to this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't see that feedback, so I can't comment on that.

It's not an opinion that the api is significantly slower, e.g. see here - that's the second hit for me on this search

My preference is to avoid the api completely because:

  1. We do have places where the api would make PowerShell measurably slower
  2. People working in our code base should be comfortable reading and writing code that is equivalent to this api
  3. People tend to copy the style, so avoiding the api helps avoid usage creeping into places that matter.

Again, this is just feedback - I'm not blocking the PR.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree completely, there's even an open issue in corefx (https://github.com/dotnet/corefx/issues/15453). My original code did not use hasflag, which I will put back.

This does not provide support for IncludeKeyDown or IncludeKeyUp, but does not
echo the character when provided. In order to support IncludeKeyDown and IncludeKeyUp a
more substantial rewrite will be needed as Console.ReadKey doesn't support this behavior.
This applies to both OSX and Linux.
@JamesWTruher

Copy link
Copy Markdown
Collaborator Author

I think all the feedback has been addressed Dongbo Wang (@daxian-dbw) ?

@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 759aff1 into PowerShell:master Jun 9, 2017
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj/PowerShell that referenced this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants