wbkgd不设置背景色

问题描述 投票:0回答:1

我正在使用Rust编写一个ncurses应用程序。

我试图设置一个子窗口的颜色,但是没有成功。我甚至不确定这个窗口是否已经创建,或者它只是不想设置颜色。

下面是一个最小的例子。

use ncurses::*;

fn main() {
    setlocale(LcCategory::all, "");
    initscr();
    keypad(stdscr(), true);
    start_color();
    init_pair(1, COLOR_RED, COLOR_RED);
    loop {
        let user_input = get_wch();
        match user_input.unwrap() {
            WchResult::Char(ch) => {
                match ch {
                    27 => break,
                    _ => {}
                }
            },
            WchResult::KeyCode(code) => {
                match code {
                    KEY_F5 => {
                        let ln = subwin(stdscr(), LINES(), 5, 0, 0);
                        wbkgd(ln, COLOR_PAIR(1));
                        refresh();
                    },
                    _ => {}
                }
            }
        }
    }
    endwin();
}

如你所见,我初始化了一个颜色对,然后调用了start_colors().

问题可能出在哪里?

rust ncurses
1个回答
0
投票

在这块

                    let ln = subwin(stdscr(), LINES(), 5, 0, 0);
                    wbkgd(ln, COLOR_PAIR(1));
                    refresh();

refresh 的结果,覆盖 subwin. 此外,你会得到更好的结果,通过 摄取 COLOR_PAIR 带空格(见 这个).

© www.soinside.com 2019 - 2024. All rights reserved.