Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Console Application Tab Completion

Tags:

.net

console

Any ideas on how to implement tab completion for a .NET (C#) Console Application? And I mean within an application that is run and then loops for user input (like if you run ftp.exe without any arguments), like this:

        string line = string.Empty;
        while (line != "exit")
        {
            //do something here
            Console.ReadLine();
        }

I know I probably couldn't actually use readline, but I would like to be able to do tab completion at that same point where you retrieve input from the user.

like image 341
Adam Haile Avatar asked Sep 05 '08 17:09

Adam Haile


2 Answers

Do a Console.ReadKey().

If you get a Tab, look at what you have in the command buffer, and loop through your available commands. If someCommand.Name.BeginsWith(currentinput), you have a winner, and you can write to screen a list of possible commands.

If there is only one(TM) you can substitute it with what the user had typed :)

like image 133
Lars Mæhlum Avatar answered Sep 29 '22 20:09

Lars Mæhlum


I created a small lib to add this functionality to an app i made:

https://github.com/fjunqueira/hinter

It might not suit your needs, but you can feel free to edit it.

like image 20
Fábio Junqueira Avatar answered Sep 29 '22 21:09

Fábio Junqueira