473,320 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Console autocompletion

Hi,

I want to write a small console application, that is used a bit like
bash or cisco shell, with an autocompletion feature.

Have you ever done that and is it possible ?

I can't find any sample on google...

Can you explain me the basis of that feature ?

Regards

Fred

Aug 16 '06 #1
4 6295

do********@yahoo.fr wrote:
Hi,

I want to write a small console application, that is used a bit like
bash or cisco shell, with an autocompletion feature.

Have you ever done that and is it possible ?

I can't find any sample on google...

Can you explain me the basis of that feature ?

Regards

Fred
If I understand your requirements you want to present the user with a
text entry window and offer simple auto completion?

You could use a rich text box and write some code that gets called when
the KeyPress event is fired. The code would scan back to the start of
a line or a space, extract the start of the word the user has entered,
and then find all words in a list of supported commands that start with
that text.

Let me know if this is the sort of thing you're after. Really though
it should be quite simple, have a play with the KeyPress and KeyDown
(to get a tab press) events.

Nick
http://seecharp.blogspot.com/

Aug 16 '06 #2
Hi,

I don't want to use winforms at all.

The autocomplétion feature must apply to the console output.

let's say you type in the console "show conf".
If the user press a specific key (tab), i want my code to autocomplete
"show conf" by "show config".

Regards

nick_nw a écrit :
If I understand your requirements you want to present the user with a
text entry window and offer simple auto completion?

You could use a rich text box and write some code that gets called when
the KeyPress event is fired. The code would scan back to the start of
a line or a space, extract the start of the word the user has entered,
and then find all words in a list of supported commands that start with
that text.

Let me know if this is the sort of thing you're after. Really though
it should be quite simple, have a play with the KeyPress and KeyDown
(to get a tab press) events.

Nick
http://seecharp.blogspot.com/
Aug 17 '06 #3

dodger_web wrote:
Hi,

I don't want to use winforms at all.

The autocomplétion feature must apply to the console output.

let's say you type in the console "show conf".
If the user press a specific key (tab), i want my code to autocomplete
"show conf" by "show config".

Regards

nick_nw a écrit :
If I understand your requirements you want to present the user with a
text entry window and offer simple auto completion?

You could use a rich text box and write some code that gets called when
the KeyPress event is fired. The code would scan back to the start of
a line or a space, extract the start of the word the user has entered,
and then find all words in a list of supported commands that start with
that text.

Let me know if this is the sort of thing you're after. Really though
it should be quite simple, have a play with the KeyPress and KeyDown
(to get a tab press) events.

Nick
http://seecharp.blogspot.com/
The principles are still the same. This code is the start of a very
simplistic solution to your problem:

string [] words = new string [] { "show conf", "list things", "do" };

StringBuilder sb = new StringBuilder ();
while (true)
{
ConsoleKeyInfo cki = Console.ReadKey (false);

if (cki.Key == ConsoleKey.Tab)
{
// Look up word in the words list amd write remaining text
to console.
}
else
{
// Add the typed in key to the string builder.
sb.Append (cki.KeyChar.ToString ());
}
}

Obviously a lot of scope for improvement, but the gist is there. Let
me know how you get on.

By the way is this a work project/college uni/or just your own
interest?

Best,

Nick
http://seecharp.blogspot.com/

Aug 17 '06 #4
Thanks a lot Nick,

It's exactly what i was looking for.

Maybe there is something best to do with a hash of words to complete to
improve performances, but the basis are there.

This question was for my open source project moreXo
(http://moreXo.sf.net).

Regards

nick_nw a écrit :
dodger_web wrote:
Hi,

I don't want to use winforms at all.

The autocomplétion feature must apply to the console output.

let's say you type in the console "show conf".
If the user press a specific key (tab), i want my code to autocomplete
"show conf" by "show config".

Regards

nick_nw a écrit :
If I understand your requirements you want to present the user with a
text entry window and offer simple auto completion?
>
You could use a rich text box and write some code that gets called when
the KeyPress event is fired. The code would scan back to the start of
a line or a space, extract the start of the word the user has entered,
and then find all words in a list of supported commands that start with
that text.
>
Let me know if this is the sort of thing you're after. Really though
it should be quite simple, have a play with the KeyPress and KeyDown
(to get a tab press) events.
>
Nick
http://seecharp.blogspot.com/

The principles are still the same. This code is the start of a very
simplistic solution to your problem:

string [] words = new string [] { "show conf", "list things", "do" };

StringBuilder sb = new StringBuilder ();
while (true)
{
ConsoleKeyInfo cki = Console.ReadKey (false);

if (cki.Key == ConsoleKey.Tab)
{
// Look up word in the words list amd write remaining text
to console.
}
else
{
// Add the typed in key to the string builder.
sb.Append (cki.KeyChar.ToString ());
}
}

Obviously a lot of scope for improvement, but the gist is there. Let
me know how you get on.

By the way is this a work project/college uni/or just your own
interest?

Best,

Nick
http://seecharp.blogspot.com/
Aug 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Dave | last post by:
Hi, I have done some research, trying to Clear The Screen in java code. The first option was the obv: system.out.print("\n\n\n\n\n\n\n\n\n\n\n\n"); then i heard about this method:...
20
by: Brett Hoerner | last post by:
This is a pretty basic, mostly un-python-related question, although I'm asking because of Python. Is there a different shell I can use (other than cmd.com) to run Python in, where I can...
2
by: MS | last post by:
Hi everyone, I have moved to a new installation of Visual Studio 2003 (using C#), and I no longer have the autocompletion feature inside the command window. I have been all through the options...
1
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
7
by: shawnk | last post by:
Hello Everyone How do you format format numbers right-justified using Console.WriteLine(), i.e I need to line up numbers in vertical columns and the MSDN documentation is pretty poor Here is the...
5
by: Barry Mossman | last post by:
Hi, can I detect whether my class is running within the context of a Console application, vs say a WinForm's application ? also does anyone know whether the compiler or runtime is smart enough...
1
by: John Wright | last post by:
I am running a console application that connects to an Access database (8 million rows) and converts it to a text file and then cleans and compacts the database. When it runs I get the following...
2
by: Papalagi Pakeha | last post by:
Hi all, How can I turn on autocompletion when I push <tabin python 2.5.1 interactive mode? E.g. to give me a list of all methods and attributes of a given object. It works great on my Linux /...
0
by: cie | last post by:
Hi, I'm having problem with data integration in my program, so I want to give restriction that only data from autocompletion (like in System.Windows.TextBox) which is got from another table can be...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.