slang-users mailing list

[2015 Date Index] [2015 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: [slang-users] slsh_readline


Morten Bo Johansen <mbj@xxxxxxxxxxx> wrote:
> Is it possible to construct a prompt with slsh_readline that
> emulates the jed function,
>
>   String read_mini (String prompt, String dflt, String init);

I looked into seeing what it would take to add this feature, but the
most straightforward way would break both ABI and API compatibility.  So
the feature will have to wait until version 3.

Instead, you can try the following approach which stuffs the history
buffer with the init string.  This assumes that you are using slang's
readline and not GNU's.

In the example below, "foobar" will get added to the history.  If you
want to edit it, press the UP arrow.  I had hoped for a better
solution, but this one is the least kludgy.

I hope this helps.
Thanks,
--John

slsh_readline_init ("MYAPP");

private variable My_Rline_History = NULL;
public define myapp_rline_open_hook ()  % must be public
{
   if (My_Rline_History != NULL)
     rline_set_history (My_Rline_History);
}

define my_readline (prompt, initbuf)
{
   My_Rline_History = [initbuf];
   variable rli = slsh_readline_new ("myapp");
   return slsh_readline (rli, prompt);
}

define slsh_main ()
{
   message (my_readline ("test", "myapp> ", "foobar"));
}
_______________________________________________
For list information, visit <http://jedsoft.org/slang/mailinglists.html>.


[2015 date index] [2015 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]