如何在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
設置爲與相同的顏色,顯然我不想這樣做,因爲這是非標準的,我想分發使用此代碼的較大應用程序。
對於幾乎所有終端(包括您在屏幕截圖中顯示的那個終端),您引用的答案都不正確。 –