Statusbar not working

Hello.

I have a BBS terminal, and at the bottom of the screen, there should
be a statusbar. Whenever I call draw_statusbar() it displays the statusbar, but it doesn't stay at the bottom of the screen.

Here is some code.

....
....
....

void startup(void)
{
   printf("\033(U");  /* set to ibm character set */
   initscr();         /* initialize ncurses */
   start_color();
   COLOR_PAIRS = 72; /* needed to fix the 64 color pair bug */
   cbreak();
   noecho();         /* don't echo input */
   nonl();
   use_sbar = (LINES > 24) ? 1 : 0;  /* only use statbar on big terms */
   win = newwin(screenlen, COLS, 0, 0);  /* configurable later? */
   if (win == NULL)
   {
       printf("\nError creating main window!\n");
       exit(2);
   }
   scrollok(win, TRUE);
   nodelay(win, TRUE);
   keypad(win, TRUE);
/*   setkeymode(); */
   if (use_sbar)
   {
       statusbar = newwin(1, COLS, screenlen, 0);
       if (statusbar == NULL)
       {
           delwin(win);
           endwin();
           printf("\nError creating status bar window!\n");
           exit(3);
       }
   }
}


void draw_statusbar(void)
{
   int i;
   char sbar[79];
   wattrset(statusbar, crt2curses(0x7F)); 
 /*  wcolor_set(statusbar, crt2curses(0x1F), NULL); */
   sprintf(sbar, " %s %s", appname, version);
   for (i = strlen(sbar); i < 80; i++) sbar[i] = 32; 
   mvwaddstr(statusbar, 0,0, sbar);
   touchwin(statusbar);
   wrefresh(statusbar);
   touchwin(win);
   textattr(0x07);
}

int main(int argc, char *argv[])
{
    int port;
    if (argc < 2) usage();
    if (argc == 2) port = 23; else port = atoi(argv[2]);
    startup();
    if (use_sbar) draw_statusbar();
    session(argv[1], port);
    quit();
    return 0;
}

Thank you for your time.

Hi @ignatius,

without knowing the full code it becomes difficult to figure out the cause of the wrong behaviour. I only see that you define sbar[79], but the loop runs until i == 79. So it has to be sbar[80].

Two tiny tips:

  • Instead of use_sbar = (LINES > 24) ? 1 : 0; you can simply write use_bar = LINES > 24;
  • Instead of if (argc == 2) port = 23 ... simplier port = (argc > 2) ? atoi(argv[2]) : 23;

"Doesn't stay at the bottom": does it rack up into the line above, or disappear, or what?

You don't show any of session(). I'm guessing it does something bad to the screen. Maybe test with a sleep (10) in there to see if that delays the bad event.

In particular, you create a newwin() for the whole screen, and a newwin() for the status bar. But session() does not know whether the status bar exists, and it may assume it has the whole space.

You also seem to have win declared global, which makes me think session() is using the whole screen. I would suggest making a newwin() for session() within main, and passing that as an arg to session().

At lines 606 and 1293, I see puts("e[2J"); where puts("\e[2J"); is obviously intended.

There are hard-coded (and therefore terminal-dependent) terminal commands throughout the code, and five haymakers at lines 694, 7340, 1235, 1243 and 1249. One of these [ function intro() ] is over 1700 non-graphic bytes long. These are completely unverifiable, so their effect on your specific terminal and its status bar cannot be predicted.

The code mixes those raw terminal sequences with ncurses functions, which seems unlikely to be stable. As ncurses cannot know what you have written to the terminal, it will refresh only what it wrote itself.

First off, thank you for your insight. I appreciate it. For what it's worth, I commented out all of the code that displays that raw data. And it made absolutely no difference. It's still not behaving as it should.

Hi @ignatius,

there are some local includes:

#include "common_bufsiz.h"
#include "misc.h"
#include "global.h"
#include "transfer.h"

Could you please post that code too, maybe via pastebin or as a zip?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.