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.
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 :)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With