Skip to content

Conversation

@JamesWTruher
Copy link
Collaborator

@JamesWTruher JamesWTruher commented May 17, 2017

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
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
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
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
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

@JamesWTruher JamesWTruher force-pushed the jameswtruher/ReadKeyNoEcho branch from 61603c5 to c950d8d Compare May 23, 2017 19:07
@daxian-dbw daxian-dbw removed their assignment May 24, 2017
@mirichmo mirichmo assigned mirichmo and unassigned mirichmo May 24, 2017
Copy link
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 daxian-dbw self-assigned this May 24, 2017
@daxian-dbw 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
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
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
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
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
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 JamesWTruher force-pushed the jameswtruher/ReadKeyNoEcho branch from c950d8d to 10625c3 Compare June 6, 2017 19:25
@JamesWTruher
Copy link
Collaborator Author

I think all the feedback has been addressed @daxian-dbw ?

@daxian-dbw daxian-dbw merged commit 759aff1 into PowerShell:master Jun 9, 2017
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