English 中文(简体)
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.

最佳回答

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.

问题回答

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.

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.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签