0

I'm trying to display a statusbar using ncurses with "---" between items, like most terminal programs do.

I have the following code so far:

#include <iostream>
#include <cmath>
#include <string>
#include <curses.h>

using namespace std;

int main() {
    initscr();
    start_color();

    init_pair(3, COLOR_WHITE, COLOR_RED);

    getch();
    attron(COLOR_PAIR(3));

    string a = "--- Tickets: 455";

    a.append(70, '-');

    mvprintw(LINES-1, 0, a.c_str());

    getch();

    endwin();
}

The mvprintw should output the whole width of the screen until the right border. But in fact, only one "-" is appended.

I'm not sure if this is a an ncurses problem or if strings are not converted to c style strings properly. Could someone help me identify the issue?

Pille
  • 57
  • 2
  • 8
  • I figured out that removing the for loop and append with a.append(5, '-') i get what I want - but if I append more than 6 characters, only one '-' is appended. – Pille Nov 25 '19 at 02:09
  • Unable to reproduce, I get the expected output; but I'm almost positive that you simply need to add a `refresh();` before calling `getch()` the 2nd time. See curses documentation for more information. Maybe my version of curses has `getch`()` automatically flush everything out. – Sam Varshavchik Nov 25 '19 at 02:18
  • Possible duplicate of [Borders don't draw properly when window has more than 8 columns](https://stackoverflow.com/questions/54114075/borders-dont-draw-properly-when-window-has-more-than-8-columns). It's been a couple of years, but some developers were slow to followup on their bug. – Thomas Dickey Nov 25 '19 at 09:11
  • I figured out that this has to do with my TERM variable. In fact I use "st" as terminal - so what would be the proper term variable then? – Pille Nov 25 '19 at 14:13

0 Answers0