slang-users mailing list

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

Re: Readline terminal input


On Sat, 1 Mar 2003 13:03:04 -0600, Joe Robertson wrote:

Hi.

> Hi All,
> 
> I want to write a small terminal program that just reads a few line inputs.
> Um, how do I do a 'readline' input?  gets?
> 
> Do I open a file STDIN for read, then use fgets?
> 
> I didn't want to 'take over' the terminal with smg.
> Anyone written a module/wrapper for gnu readline?
> 
> This kind of thing needs to be in the docs somewhere, simple line input.
> I'm interested to know how others are doing this task.

Well you have two options, either handle STDIN by yourself, or use
SLang_read_line(). I use both in two of my applications that are using
slang for tty handling. Here's a sample code :

SLang_RLine_Info_Type *bm_rli; /* readline stuff */
unsigned char rl_buf[512];     /* readline buffer */

Init the structure :

    bm_rli = (SLang_RLine_Info_Type *) malloc(sizeof(SLang_RLine_Info_Type));
    memset ((char *) bm_rli, 0, sizeof(SLang_RLine_Info_Type));
    bm_rli->buf = rl_buf;
    bm_rli->buf_len = 511;
    bm_rli->tab = 5;
    bm_rli->dhscroll = 10;
    bm_rli->getkey = SLang_getkey;
    bm_rli->tt_goto_column = NULL;
    bm_rli->update_hook = NULL;

A functin that does the reading :

    SLtt_set_cursor_visibility(1);

    bm_rli->edit_width = SLtt_Screen_Cols - 1;
    bm_rli->prompt = prompt; /* char * pointer passed to function */
    /* if buf has something insert it into edit buffer - another parameter */
    if (*buf)
        strmcpy(bm_rli->buf, buf, 511);
    else
        *bm_rli->buf = '\0';
    bm_rli->point = strlen(bm_rli->buf);
    i = SLang_read_line(bm_rli);
    if (i >= 0 && !SLang_Error && !SLKeyBoard_Quit)
    {
        SLang_rline_save_line(bm_rli);
        strmcpy(buf, bm_rli->buf, len);
    }

G.

> Thanks,
> Joe Robertson
> jmrobert5@xxxxxxxxx


-- 
Goran Koruga                            goran.koruga@xxxxxxxxx
HERMES Softlab, Litijska 51             phone: +386 1 586 5530
1000 Ljubljana, Slovenia


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