Skip to content

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

Closed as not planned
Closed as not planned

Description

@iSazonov

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

Activity

  1. stephentoub commented on Mar 20, 2019

    @stephentoub
    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
    
  2. iSazonov commented on Mar 20, 2019

    @iSazonov
    ContributorAuthor
  3. stephentoub commented on Mar 20, 2019

    @stephentoub
    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.

  4. iSazonov commented on Mar 20, 2019

    @iSazonov
    ContributorAuthor

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

  5. iSazonov commented on Mar 29, 2019

    @iSazonov
    ContributorAuthor

    I corrected my request.

  6. transferred this issue fromdotnet/corefxon Dec 12, 2019
  7. changed the title [-]Enhance Console.ReadKey() to return at Tab[/-] [+]Enhance Console.ReadLine() to return at Tab[/+] on Dec 12, 2019
  8. added
    api-suggestionEarly API idea and discussion, it is NOT ready for implementation
    on Dec 12, 2019
  9. wfurt commented on Dec 17, 2019

    @wfurt
    Member

    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 '?').

  10. iSazonov commented on Dec 17, 2019

    @iSazonov
    ContributorAuthor

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

  11. eiriktsarpalis commented on May 21, 2020

    @eiriktsarpalis
    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?

  12. iSazonov commented on May 21, 2020

    @iSazonov
    ContributorAuthor

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

    Ideally extensible line editor.

  13. added this to the Future milestone on Jun 24, 2020
  14. Akarinnnnn commented on Jun 26, 2020

    @Akarinnnnn

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

  15. removed
    untriagedNew issue has not been triaged by the area owner
    on Jul 6, 2020
  16. added a commit that references this issue on Jul 7, 2022
  17. jeffhandley commented on Sep 12, 2022

    @jeffhandley
    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.

  18. iSazonov commented on Sep 13, 2022

    @iSazonov
    ContributorAuthor

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

  19. ghost locked as resolved and limited conversation to collaborators on Oct 13, 2022
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions