Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make win C# console application to show posibile command when user hit TAB

I am developing console application in C# with lot of parameters and sometime I as developer can't remember combination of parameters to call application in right way, I can't even and think how users will do it. So I asking You is there and what will be the proper (scholastic) way to make my application act like those UNIX OS. You know what I trying to accomplish is that when user call application and after that when hit a TAB then get list of possible commands, after choice one of command again hit a tab and get referent list of parameters and other commands.

like image 304
adopilot Avatar asked Nov 16 '25 07:11

adopilot


2 Answers

I think the easiest way to do this is to use the Console.ReadKey method. This will allow you to get the tab key as soon as it's pressed by the user. You can then handle that keystroke and if it's a tab, determine the current context and print out the commands as appropriate.

like image 85
JaredPar Avatar answered Nov 18 '25 21:11

JaredPar


Develop your application as a PowerShell CmdLet. Powershell already has tab-completion infrastructure built-in. For example, if you do the following for the dir CmdLet:

dir -Tab

then hitting Tab repeatedly will cycle through the possible options for the dir command:

  • dir -Path
  • dir -LiteralPath
  • dir -Filter
  • dir -Include

Etcetera.

like image 26
Wim Coenen Avatar answered Nov 18 '25 19:11

Wim Coenen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!