如何使用 ncurses 自动换行和光标前进将带有属性的字符串放在屏幕上?
How can I put a string with attributes on the screen with auto-wrapping and cursor advancing with ncurses?
如 here 所述,add_wchstr 函数不会前进当前光标位置或进行自动换行。
但是如果我想像addwstr那样输出文本,但是带有格式属性,我应该怎么调用呢?
如果 ncurses 愚蠢地缺少这样的功能,我考虑手动实现它(只需为每个字符调用 add_wch 并推进光标位置)。但关键问题是:
如何指示是否需要自动换行?
如何指示字符是否显示在 2 个单元格(全角字符)上,以便我应该正确调用 add_wch 两次(或任何其他正确显示全角字符的替代解决方案)?
如何指示当前光标位置应该前进到哪里?
您可以设置
- window 属性与 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.
或
- 背景字符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.
如 here 所述,add_wchstr 函数不会前进当前光标位置或进行自动换行。
但是如果我想像addwstr那样输出文本,但是带有格式属性,我应该怎么调用呢?
如果 ncurses 愚蠢地缺少这样的功能,我考虑手动实现它(只需为每个字符调用 add_wch 并推进光标位置)。但关键问题是:
如何指示是否需要自动换行?
如何指示字符是否显示在 2 个单元格(全角字符)上,以便我应该正确调用 add_wch 两次(或任何其他正确显示全角字符的替代解决方案)?
如何指示当前光标位置应该前进到哪里?
您可以设置
- window 属性与 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.
或
- 背景字符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.