You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once feature request is implemented, in PowerShell repo we can use the same code on all systems, enhance supported features on Unix and remove explicit P/Invokes.
Feature request
Enhance Console API so that Console.ReadLine() works like Windows ReadConsole:
can returns when the Tab (others?) button is pressed.
This seems like weird request as TAB does not constitute end of line e.g. if the function returns it would give less than line.
It seems like if handling of special keys is needed best approach would be reading keys into buffer and adding handlers for TAB or any other special keys (like '?').
So it would seem like implementing a modified variant of StreamReader.ReadLine() on top of either System.Console.ReadKey() or System.Console.In might be an acceptable workaround for your use case?
Assuming you would like to see this functionality added to System.Console, I'm curious what shape you were thinking this might have? Clearly we cannot make a breaking change to Console.ReadLine(), so I suppose it would have to be a new method?
We have discussed this potential feature again and concluded that we are going to close the request. Features related to tab/word completion and/or other key handling behaviors are commonly needed in shells, and that is the layer where we think the feature is best implemented. With the Unix Console.ReadKey rewrite (#72193) complete in .NET 7.0, we expect that key-level functionality should now be much more reliable to implement upstack as well. Upstack implementations would be wrappers around Console.ReadKey() loops that allow special-case handling of specific keys.
Activity
stephentoub commentedon Mar 20, 2019
I don't understand the request. Console.ReadKey() does return a ConsoleKeyInfo for Tab when Tab is pressed. You can see it's explicitly handled here:
https://github.com/dotnet/corefx/blob/b58eb14dd8694d5142d63fde7b89e9f6a9bf32b1/src/System.Console/src/System/IO/StdInReader.cs#L232-L233
The code you linked to is the implementation of Console.ReadLine, not ReadKey.
When I run this:
and then type a bunch of tabs, I see:
iSazonov commentedon Mar 20, 2019
Using search I got into the file https://github.com/dotnet/corefx/blob/c7a4807728206d959e1878242c0bd6d35948fc2d/src/System.Console/src/System/ConsolePal.Unix.cs#L91
Is it wrong?
stephentoub commentedon Mar 20, 2019
I'm not sure what you're asking. That ReadKey method you linked to in that file calls StdinReader.ReadKey:
https://github.com/dotnet/corefx/blob/c7a4807728206d959e1878242c0bd6d35948fc2d/src/System.Console/src/System/IO/StdInReader.cs#L351
which contains the Tab handling.
iSazonov commentedon Mar 20, 2019
@stephentoub Thanks for clarify! I really confused ReadKey and Readline methods in CoreFX repo.
iSazonov commentedon Mar 29, 2019
I corrected my request.
[-]Enhance Console.ReadKey() to return at Tab[/-][+]Enhance Console.ReadLine() to return at Tab[/+]wfurt commentedon Dec 17, 2019
This seems like weird request as TAB does not constitute end of line e.g. if the function returns it would give less than line.
It seems like if handling of special keys is needed best approach would be reading keys into buffer and adding handlers for TAB or any other special keys (like '?').
iSazonov commentedon Dec 17, 2019
@wfurt It seems you say about implementing a power line editor class which allows customizations and hooks/handlers. Looks good to me.
eiriktsarpalis commentedon May 21, 2020
So it would seem like implementing a modified variant of
StreamReader.ReadLine()on top of eitherSystem.Console.ReadKey()orSystem.Console.Inmight be an acceptable workaround for your use case?Assuming you would like to see this functionality added to
System.Console, I'm curious what shape you were thinking this might have? Clearly we cannot make a breaking change toConsole.ReadLine(), so I suppose it would have to be a new method?iSazonov commentedon May 21, 2020
Ideally extensible line editor.
Akarinnnnn commentedon Jun 26, 2020
Yes. #35063 meant this. The "TAB" in C++ STL is called "delim" so I used that name.
Update dependencies from https://github.com/dotnet/arcade build 20211…
jeffhandley commentedon Sep 12, 2022
We have discussed this potential feature again and concluded that we are going to close the request. Features related to tab/word completion and/or other key handling behaviors are commonly needed in shells, and that is the layer where we think the feature is best implemented. With the Unix Console.ReadKey rewrite (#72193) complete in .NET 7.0, we expect that key-level functionality should now be much more reliable to implement upstack as well. Upstack implementations would be wrappers around
Console.ReadKey()loops that allow special-case handling of specific keys.iSazonov commentedon Sep 13, 2022
/cc @SteveL-MSFT @daxian-dbw for information. It seems we could to unify PowerShell ReadLine method.