如何在ncurses
上获得带有黑色文字的明亮白色背景,与nano
中的标题栏类似?尽管出现the advice in another question(这与在黑色背景上获得明亮的白色文字有关,与我想达到的目的相反),但我仍然可以实现这一目标,这是一种丑陋的米色背景。如何使用ncurses获得明亮的白色背景色?
图片:
GNU nano的标题栏,我想要的。
我得到下面的程序是什么。 (与gcc -lncursesw -I/usr/include minimal_example.c
建设)
#include <locale.h>
#include <ncurses.h>
int main() {
setlocale(LC_ALL, "");
// Initialize curses library
initscr();
// Enable colors
start_color();
// Attempt recommendation in https://stackoverflow.com/questions/1896162/how-to-get-a-brightwhite-color-in-ncurses and other places on the web
use_default_colors();
// Make the COLOR_PAIR 0xFF refer to a white foreground, black background window.
// Using -1 will not work in my case, because I want the opposite of the default (black text on white bg), not the default (white text on black bg).
init_pair(0xFF, COLOR_BLACK, COLOR_WHITE);
refresh();
// Get our term height and width.
int x;
int y;
// & not required because this is a macro
getmaxyx(stdscr, y, x);
// Create a new window.
// TODO: Resize the window when the term resizes.
WINDOW *window = newwin(y,x,0,0);
// Try some other attributes recommended online, no dice. Putting this after the call to wbkgd() just makes the text look strange, does not change the background.
wattron(window,A_BOLD|A_STANDOUT);
// Set window color.
wbkgd(window, COLOR_PAIR(0xff));
// Draw a nice box around the window.
box(window, 0, 0);
// Write some text.
mvwprintw(window, 1, 1, "背景:不白");
wrefresh(window);
// Wait for keypress to exit.
getch();
// De-initialize ncurses.
endwin();
return 0;
}
我想也许有什么错我的终端配置(termite
),但是我能够重现xfce4-terminal
和xterm
的问题,无论是使用默认配置。解决这个问题的唯一方法是将我的color7
和color15
设置为与相同的颜色,显然我不想这样做,因为这是非标准的,我想分发使用此代码的较大应用程序。
对于几乎所有终端(包括您在屏幕截图中显示的那个终端),您引用的答案都不正确。 –