tab completion with a Unix Shell simulation

Hi everyone,

I am writing a command line program which needs to interface a Unix Shell.

when I type "!command", it will send the command to a bash process and read the output then write it on stdout.

The bash I am running merges stdout and stderr (exec 2>&1).

Everything works great, but now I would like to add the tab-completion functionality.

I would just need to send (tab) to the process so that I can read the output completion, I tried many ways but without success.

Also, I saw we can specify the tag for completion in file ~/.inputrc, but if my tag does not end with \n, I will write it in the buffer and we will be red by bash only after \n is typed.

I hope I made myself clear.

Thanks for your help!

Dimebag

[786 byte] By [dimebaga] at [2007-11-27 6:30:15]
# 1
Tab completion in bash requires a terminal. Search the internet for "java terminal emulator"
jsalonena at 2007-7-12 17:54:41 > top of Java-index,Java Essentials,Java Programming...
# 2
I do have a terminal.This is the result of the command typed in my java program.> !echo $TERMvt100Dimebag
dimebaga at 2007-7-12 17:54:41 > top of Java-index,Java Essentials,Java Programming...
# 3
So I guess you've tried sending a (char)9 (you probably have)? It's the ASCII value for the tab.out.write( (char)9 );Might need to send it twice in some cases, I think.
kevjavaa at 2007-7-12 17:54:41 > top of Java-index,Java Essentials,Java Programming...
# 4

> So I guess you've tried sending a (char)9 (you

> probably have)? It's the ASCII value for the tab.

> > out.write( (char)9 );

>

>

> Might need to send it twice in some cases, I think.

That is the point.

I did try with out.write((char)9) twice followed by flush(), however the data gets stuck in the buffer and will only be received after the next command (finishing with \n).

I would need to use println but this does not work either.

dimebaga at 2007-7-12 17:54:41 > top of Java-index,Java Essentials,Java Programming...
# 5

> That is the point.

> I did try with out.write((char)9) twice followed by

> flush(), however the data gets stuck in the buffer

> and will only be received after the next command

> (finishing with \n).

> I would need to use println but this does not work

> either.

Ahh, I see...

According to this page (http://www.die.net/doc/linux/man/man1/screen.1.html), vt100 allows you to send 'ESC [ Pn I", or {(char)33, (char)91, (char)0, (char)73} as an escape code for the horizontal tab. I don't know if that will work either (never done terminal emulation), but it might be worth a shot.

As an aside, an alias for Bash's tab completion is a Control I, but I don't know what that translates to, if not the weird escape sequence above.

kevjavaa at 2007-7-12 17:54:41 > top of Java-index,Java Essentials,Java Programming...
# 6

Read the PATH variable.

for each path in PATH

add each executable name to a list.

Now you have a list of viable execuables for tab completion, if that is what you meant...

If you are trying to do tab completion for a path...like ~/somefile, you just have to figure out what directory you are in, then you have a list of things that can be completed... default directory coule be the 'java.home' property, as well as ~/. / is the / directory...once you have a place to start you can create a file object and list the contents.

Then you have to listen for the tab key and then use regex against the list of files and/or executables.

robtafta at 2007-7-12 17:54:41 > top of Java-index,Java Essentials,Java Programming...
# 7

Thanks for your help!

kevjava, very good hints but unfortunately it did not work.

robtaft , this is a solution but I would have prefered to use unix completion since I am running bash process.

I may have found a solution using gnu.realine package in java (it can communicate with the bash readline library)

dimebaga at 2007-7-12 17:54:41 > top of Java-index,Java Essentials,Java Programming...