Search code examples
ncurses

How can I put a string with attributes on the screen with auto-wrapping and cursor advancing with ncurses?


As described here, add_wchstr functions do not advance the current cursor position or do auto-wrapping.

But if I want to output text like addwstr do, but with format attributes, what should I call?

If ncurses is stupidly missing such feature, I consider implementing it manually (Simply calling add_wch for each character and advance the cursor position). But the key problems are:

How can I indicate whether an auto-wrapping is required?

How can I indicate whether a character is displayed over 2 cells (full-width characters) so that I should correctly call add_wch twice (or any other alternative solutions that displays full-witdh characters correctly)?

How can I indicate where the current cursor postion should be advanced to?


Solution

  • You can set

    • the window attributes with wattrset/wattr_set,

      These routines manipulate the current attributes of the named window, which then apply to all characters that are written into the window with waddch, waddstr and wprintw. Attributes are a property of the character, and move with the character through any scrolling and in- sert/delete line/character operations. To the extent possible, they are displayed as appropriate modifications to the graphic rendition of characters put on the screen.

    or

    • the background character with wkbgdset/wbkgdset.
        The bkgdset and wbkgdset routines  manipulate  the  background  of  the
      

      named window. The window background is a chtype consisting of any com- bination of attributes (i.e., rendition) and a character. The attribute part of the background is combined (OR'ed) with all non-blank characters that are written into the window with waddch. Both the character and attribute parts of the background are combined with the blank characters. The background becomes a property of the character and moves with the character through any scrolling and insert/delete line/character operations.