Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Console.ReadLine() to return at Tab #800

Closed
Tracked by #64487
iSazonov opened this issue Mar 20, 2019 · 12 comments
Closed
Tracked by #64487

Enhance Console.ReadLine() to return at Tab #800

iSazonov opened this issue Mar 20, 2019 · 12 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Console Team:Libraries
Milestone

Comments

@iSazonov
Copy link
Contributor

iSazonov commented Mar 20, 2019

AB#1115512
On Windows PowerShell implements tab completions in command line (without PSReadline).
https://github.com/PowerShell/PowerShell/blob/0f7efddd22a4a44f61a2f22de86f5d6b6aa47564/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs#L753

On Unix PowerShell can not do this because Console API doesn't support read line complete when the Tab button is pressed.
https://github.com/dotnet/corefx/blob/a10890f4ffe0fadf090c922578ba0e606ebdd16c/src/System.Console/src/System/IO/StdInReader.cs#L149

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.
  • accepts InitialChars such as Windows ReadConsole.

Additional

Bash benefits from Readline library https://en.wikipedia.org/wiki/GNU_Readline

@stephentoub
Copy link
Member

Enhance Console API so that Console.ReadKey() can returns when the Tab (others?) button is pressed.

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:

using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Ready...");
        while (true)
        {
            ConsoleKeyInfo k = Console.ReadKey(intercept: true);
            Console.WriteLine(k.Key + ": " + (int)k.KeyChar);
        }
    }
}

and then type a bunch of tabs, I see:

stoub@stoubdesktop:~/tmpapp$ dotnet run -c Release
Ready...
Tab: 9
Tab: 9
Tab: 9
Tab: 9
Tab: 9
Tab: 9
Tab: 9

@iSazonov
Copy link
Contributor Author

@stephentoub
Copy link
Member

Is it wrong?

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
Copy link
Contributor Author

@stephentoub Thanks for clarify! I really confused ReadKey and Readline methods in CoreFX repo.

@iSazonov
Copy link
Contributor Author

I corrected my request.

@iSazonov iSazonov reopened this Mar 29, 2019
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Console untriaged New issue has not been triaged by the area owner labels Dec 12, 2019
@preethikurup preethikurup transferred this issue from dotnet/corefx Dec 12, 2019
@stephentoub stephentoub changed the title Enhance Console.ReadKey() to return at Tab Enhance Console.ReadLine() to return at Tab Dec 12, 2019
@stephentoub stephentoub added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Dec 12, 2019
@wfurt
Copy link
Member

wfurt commented 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
Copy link
Contributor Author

@wfurt It seems you say about implementing a power line editor class which allows customizations and hooks/handlers. Looks good to me.

@eiriktsarpalis
Copy link
Member

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?

@iSazonov
Copy link
Contributor Author

I'm curious what shape you were thinking this might have?

Ideally extensible line editor.

@Akarinnnnn
Copy link

Yes. #35063 meant this. The "TAB" in C++ STL is called "delim" so I used that name.

radical pushed a commit to radical/runtime that referenced this issue Jul 7, 2022
…230.1 (dotnet#800)

[main] Update dependencies from dotnet/arcade
@jeffhandley
Copy link
Member

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.

@jeffhandley jeffhandley closed this as not planned Won't fix, can't repro, duplicate, stale Sep 12, 2022
@iSazonov
Copy link
Contributor Author

/cc @SteveL-MSFT @daxian-dbw for information. It seems we could to unify PowerShell ReadLine method.

@ghost ghost locked as resolved and limited conversation to collaborators Oct 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Console Team:Libraries
Projects
None yet
Development

No branches or pull requests

8 participants