Ruby readline - completion based on already-entered commands

hi,

i'm new to ruby, and having the problem Bill Atkins was having with
the readline library. i searched the archives and found this thread.
unfortunately no great solution. there was the partial solution from
Dave Baldwin that involved changing the word split character. as he
pointed out the real problem is that ruby readline doesn't provide the
whole line buffer so one cannot do context line completion.

i'm wondering on the follow up process. there is a patch to fix this
at:

   http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/54796

it was posted back in nov 2002. but hasn't made it in so far (checked
1.8.3), but has been a problem for 3 or 4 years. was the patch no
good?

thanks for any insight

matt

···

On 11 Aug 2005, at 15:44, Bill Atkins wrote:

How can I use the builtin readline library to complete arguments to
commands? I have basic completion working now, so that

%wmi > st [TAB]

will show valid commands starting with "st" (in this case "start"
and "stop"), but how do I complete arguments specific to that
command?

For instance, if the user has already typed "start Te" and then hits
TAB, it should show completions specific to the start command (in
this case "TestDevice" and "TerminalServer"), but I'm not clear on
how to do this.

--
Bill Atkins

Hi,

$ cat rlcomp.rb
require "readline"

nominee = %w[foo bar baz quit]
Readline.completion_proc =
  lambda { |s| nominee.find_all { |e| e.match(s) } }

begin
  line = Readline.readline("prompt> ")
  puts line
end until line =~ /quit/

$ ruby rlcomp.rb

ba

bar baz

HTH.

···

On 10/28/05, Matt Wilkins <mcw@cs.ubc.ca> wrote:

hi,

i'm new to ruby, and having the problem Bill Atkins was having with
the readline library. i searched the archives and found this thread.
unfortunately no great solution. there was the partial solution from
Dave Baldwin that involved changing the word split character. as he
pointed out the real problem is that ruby readline doesn't provide the
whole line buffer so one cannot do context line completion.

i'm wondering on the follow up process. there is a patch to fix this
at:

   http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/54796

it was posted back in nov 2002. but hasn't made it in so far (checked
1.8.3), but has been a problem for 3 or 4 years. was the patch no
good?

thanks for any insight

matt

On 11 Aug 2005, at 15:44, Bill Atkins wrote:
> How can I use the builtin readline library to complete arguments to
> commands? I have basic completion working now, so that
>
> %wmi > st [TAB]
>
> will show valid commands starting with "st" (in this case "start"
> and "stop"), but how do I complete arguments specific to that
> command?
>
> For instance, if the user has already typed "start Te" and then hits
> TAB, it should show completions specific to the start command (in
> this case "TestDevice" and "TerminalServer"), but I'm not clear on
> how to do this.
>
> --
> Bill Atkins
>
>

--
http://nohmad.sub-port.net

Oops, I misread your question. Sorry for noise.

Do you mean argument-specific completion?
As far as I know, most readline-based programs tend to parse
user input manually. How can it be achived by other language?

···

On 10/28/05, Gyoung-Yoon Noh <nohmad@gmail.com> wrote:

Hi,

$ cat rlcomp.rb
require "readline"

nominee = %w[foo bar baz quit]
Readline.completion_proc =
  lambda { |s| nominee.find_all { |e| e.match(s) } }

begin
  line = Readline.readline("prompt> ")
  puts line
end until line =~ /quit/

$ ruby rlcomp.rb
> ba
bar baz

HTH.

On 10/28/05, Matt Wilkins <mcw@cs.ubc.ca> wrote:
>
> hi,
>
> i'm new to ruby, and having the problem Bill Atkins was having with
> the readline library. i searched the archives and found this thread.
> unfortunately no great solution. there was the partial solution from
> Dave Baldwin that involved changing the word split character. as he
> pointed out the real problem is that ruby readline doesn't provide the
> whole line buffer so one cannot do context line completion.
>
> i'm wondering on the follow up process. there is a patch to fix this
> at:
>
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/54796
>
> it was posted back in nov 2002. but hasn't made it in so far (checked
> 1.8.3), but has been a problem for 3 or 4 years. was the patch no
> good?
>
> thanks for any insight
>
> matt
>
> On 11 Aug 2005, at 15:44, Bill Atkins wrote:
> > How can I use the builtin readline library to complete arguments to
> > commands? I have basic completion working now, so that
> >
> > %wmi > st [TAB]
> >
> > will show valid commands starting with "st" (in this case "start"
> > and "stop"), but how do I complete arguments specific to that
> > command?
> >
> > For instance, if the user has already typed "start Te" and then hits
> > TAB, it should show completions specific to the start command (in
> > this case "TestDevice" and "TerminalServer"), but I'm not clear on
> > how to do this.
> >
> > --
> > Bill Atkins
> >
> >
>
>

--
http://nohmad.sub-port.net

--
http://nohmad.sub-port.net

Do you mean argument-specific completion?

yip

As far as I know, most readline-based programs tend to parse
user input manually.

gnu readline provides a lot things, so throwing that away and using my
own cooked up scheme isn't the way i want to go.

How can it be achived by other language?

well one way is to use gnu readline, so long as whatever binding
hasn't hidden the necessary info (in this case the line buffer). for
instance in the perl binding, the completion function is passed $text,
$line, $start. the patch in my previous posting (not my patch) passes
the current token, and the whole line up to that point.

matt