在 Linux 上使用 ncurses 的背景色
Background color using ncurses on Linux
这里的第一篇文章,所以我对任何错误表示歉意。
基本上,当我运行代码时,除了更改背景颜色外,一切正常。由于某种原因,它总是灰色的。我正在尝试将其更改为黑色,但它不起作用,我不确定为什么。
我认为应该更改背景颜色的代码的主要部分是:Wattron(mainWindow, COLOR_BLACK);
任何帮助弄清楚如何将我的背景更改为黑色将不胜感激。谢谢大家!
以下是我到目前为止所拥有的,以防它有助于为我的问题提供一些背景:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <curses.h>
#include <time.h>
// Variables
int nlines;
int ncols;
int x;
int y;
int y0;
int x0;
int input;
// Constants
const int MAX_LINES = 10;
const int MAX_COLUMNS = 10;
// Main function
int main(void) {
WINDOW * mainWindow;
// Initialize ncurses
if ( (mainWindow = initscr()) == NULL) {
fprintf(stderr, "Could not initialize ncurses!n");
exit(EXIT_FAILURE);
}
// Call function to use color
start_color();
// Create my own color pairs
init_pair(1, COLOR_CYAN, COLOR_BLACK);
init_pair(2, COLOR_BLUE, COLOR_RED);
// First clear off the screen
clear();
// Move the cursor
y = 8;
x = 30;
move(y, x);
// Refresh
refresh();
// Test output - working
// printw("Testing...");
waddch(mainWindow, 'T' | A_UNDERLINE | COLOR_PAIR(1));
waddch(mainWindow, 'E' | A_UNDERLINE | COLOR_PAIR(2));
waddch(mainWindow, 'S' | A_UNDERLINE | COLOR_PAIR(1));
waddch(mainWindow, 'T' | A_UNDERLINE | COLOR_PAIR(2));
waddch(mainWindow, 'I' | A_UNDERLINE | COLOR_PAIR(1));
waddch(mainWindow, 'N' | A_UNDERLINE | COLOR_PAIR(2));
waddch(mainWindow, 'G' | A_UNDERLINE | COLOR_PAIR(1));
waddch(mainWindow, '.' | A_UNDERLINE | COLOR_PAIR(2));
waddch(mainWindow, '.' | A_UNDERLINE | COLOR_PAIR(1));
waddch(mainWindow, '.' | A_UNDERLINE | COLOR_PAIR(1));
waddch(mainWindow, '.' | A_UNDERLINE | COLOR_PAIR(2));
// Make background a different color
wattron(mainWindow, COLOR_BLACK);
// Hold until user inputs a character
input = getch();
// Clean up
delwin(mainWindow);
endwin();
refresh();
return EXIT_SUCCESS;
}
你需要
打电话给wbkgd(WINDOW *win, chtype ch)
在调用wattron(WINDOW* win, chtype ch)
中,您不能将COLOR_BLACK用作ch
COLOR_BLACK因为它是一个整数,而不是一个属性(值为 chtype
)。您应该使用以下COLOR_PAIR
调用此函数:
wattron(mainWindow, COLOR_PAIR(0)); // The pair number 0 is the terminal's default pair (white foreground, black background).
请注意,wattron
仅启用指定的属性。如果要设置窗口的背景(每个单元格的重置属性),则最好使用wbkgd(WINDOW *win, chtype ch)
。您可以在 wbkgd(3ncurses) 手册中找到它的文档。
我帮助最大的ncurses教程就在这里。我建议您阅读第 10 种颜色部分。
相关文章:
- 无法同时编译 ncurses 和字符串
- ncurses 找不到任何关于cchar_t的文档
- 无法将 ncurses 函数与LD_PRELOAD挂钩
- Ncurses CTRL + s hangs getch()
- 如果我有五个 Win32 静态控件,如何使用特定的前景色设置其中一个?
- ncurses getch() 奇怪的输出?
- Ncurses C++打印前景色/背景色交换的文本
- 在设置QStylesHeet之后,如何获得Qwidget背景色
- 如何设置 RTF 编辑控件的背景色
- Visual C++按钮的透明背景色
- 更改MFC中CListCtrl整列的背景色
- 使用 QPropertyAnimation 更改 QPushButton 的背景色
- 在 Linux 上使用 ncurses 的背景色
- 在给定前景色和背景色的情况下,我如何计算第三种颜色
- 获取窗口的背景色
- c++ Win32单选按钮背景色
- 尝试使用GetObject();获取默认背景色
- 如何在QTableView中设置一些特殊行的背景色
- 在PDCurses中设置整个窗口的背景色
- 更改编辑控件的背景色的困难