Search code examples
cncurses

NCurses adds new line when output greater than terminal columns


I have noticed that when I print a line in ncurses that takes more than number of terminal columns, ncurses adds newline:

#include <ncurses.h>

int main()
{
        initscr();                      /* Start curses mode              */
        printw("Hello World aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!!");
        refresh();                      /* Print it on to the real screen */
        getch();                        /* Wait for user input */
        endwin();                       /* End curses mode                */

        return 0;
}

Now as the terminal has less columns my output looks like this:

Hello World aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!!

In my app I want to copy terminal output but when I do so, I'm getting newline where line breaks but I didn't put any new line when calling printw. Does ncurses add newlines automatically? How I can disable that? This is simple version of my problem as in my case, I'm using mvwaddnwstr to print wide characters but problem stays.


Solution

  • printw, waddstr (or waddwstr) ultimately call waddch (or wadd_wch), which wraps at the right margin. You could use (but less convenient) waddchstr or wadd_wchstr, which do not wrap.