开发者

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.


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.


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.


If I'm understanding correctly, you want to mimic the programmable command line completion in zsh (Z shell).

Unfortunately, this functionality is built in to the shell, although it is also programmable; the completion that happens there is actually happening before the program has been started up.

If you were running zsh on Windows, which should be possible with Cygwin, you could program it to assist with commandline completion.

Otherwise I think that your only option is to start a sort of interactive session once the program has been started up; for example, print all options when the program is started, and wait for the user to enter one of the parameters, then show all following possible parameter combinations.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜