Professional Web Applications Themes

ncurses Line Input - UNIX Programming

Hi all, I have a problem with line input when using ncurses. I have a parent window and 2 subwindows defined as win1 = newwin(lines, cols, 0, 0); win2 = subwin(win1, 3, cols, lines - 4, 0 ); win4 = subwin(win1, lines -4, (cols /8) * 7, 0, 0); What I am trying to do is allow the user to enter data in win2 and have it appear in win4, (a basis of a chat client). The problem is however, that when the user types a message into win2, when the text reaches the right hand side of the screen, ...

  1. #1

    Default ncurses Line Input

    Hi all, I have a problem with line input when using ncurses.
    I have a parent window and 2 subwindows defined as

    win1 = newwin(lines, cols, 0, 0);
    win2 = subwin(win1, 3, cols, lines - 4, 0 );
    win4 = subwin(win1, lines -4, (cols /8) * 7, 0, 0);

    What I am trying to do is allow the user to enter data in win2 and have
    it appear in win4, (a basis of a chat client).

    The problem is however, that when the user types a message into win2,
    when the text reaches the right hand side of the screen, the function
    returns.
    What I want to do is impiment some sort of text buffering like x
    where no matter how much you type, it wont return when you reach the end
    of the columns in the teminal.

    here is my main driving loop for the program

    char *test;
    while(1) {
    box(win2, ACS_VLINE, ACS_HLINE);
    touchwin(win1);
    wrefresh(win2);
    test = mgetline(win2, 1, 5);
    mvwdelch(win2, 5, strlen(test));
    wclear(win2);
    addinput(win4, test);
    }

    mgetline is defined as

    char *mgetline(WINDOW *win, int x, int y)
    {
    char *line;
    int nalloc = 10;
    int nch = 0;
    int c;


    line = malloc(nalloc + 1);
    if(line == NULL)
    {
    printf("out of memory\n");
    exit(1);
    }


    while((c = mvwgetch(win, x, y)) != EOF)
    {
    if(c == '\n')
    break;


    if(nch >= nalloc)
    {
    char *newp;
    nalloc += 10;
    newp = realloc(line, nalloc + 1);
    if(newp == NULL)
    {
    printf("out of memory\n");
    exit(1);
    }
    line = newp;
    }
    line[nch++] = c;
    y++;
    }
    if(c == EOF && nch == 0)
    {
    free(line);
    return NULL;
    }


    line[nch] = '\0';


    return line;
    }

    and addinput is defined as

    void addinput(WINDOW *win, char *string)
    {
    int i;
    int OldY;
    char *input = "You Say:";

    /* Used For Debug
    /* FILE *fp;


    /* fp = fopen("test.txt", "ab");
    /* fprintf(fp, "%s\n", string);
    /* close(fp); */

    OldY = getmaxy(win);
    mvwprintw(win, OldY -2, 1, "%s %s", input, string);
    wrefresh(win);
    scrollok(win, TRUE);
    scroll(win);
    wrefresh(win);
    }

    I think my issue is with the definition of win2 (however im not sure), I
    think I need to make it wider than the actual terminal, but my attempts
    at doing this result in a core dump.

    I hope someone can help

    Thanks
    Mick
    Materialised Guest

  2. #2

    Default Re: ncurses Line Input

    Materialised <net> writes:
     

    Try to post the smallest code that will compile and run and still
    exhibit the problem, it'll be easier for others to help you if you do
    that.

    --
    GNU/Linux revenues last quarter: $1 Billion.
    micros~1 revenues last quarter: $4 Billion.
    It's no longer a question of windows or GNU, it's a question of *Unix* or GNU.
    Billy Guest

  3. #3

    Default Re: ncurses Line Input

    Billy O'Connor wrote: 
    >
    >
    > Try to post the smallest code that will compile and run and still
    > exhibit the problem, it'll be easier for others to help you if you do
    > that.
    >[/ref]
    See thats the problem, those 3 functions are essential for the program
    to compile and exhibit the behavior.
    If you would like to see the problem your self I have posted a cut down
    version of the source at:
    http://codegurus.org/~mick/ncursesproblem.c

    All socket functions have been removed in this version.
    Thanks
    Materialised Guest

Similar Threads

  1. Error style - input red line
    By Izzy1138 in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: May 21st, 06:27 AM
  2. Replies: 2
    Last Post: November 18th, 09:34 PM
  3. error "Input line too long" from 4GL 7.32UC1
    By hantao in forum Informix
    Replies: 3
    Last Post: December 8th, 09:14 PM
  4. Replies: 0
    Last Post: October 4th, 01:05 AM
  5. #25752 [NEW]: ncurses includes in ext/ncurses/php_ncurses.h conflicts with BSD curses.
    By suga at netbsd dot com dot br in forum PHP Development
    Replies: 0
    Last Post: October 3rd, 11:41 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139