I'm using Rust for my ncurses app.
When the user presses F5, line numbers window should be toggled. When the user presses the F5 key for the first time, the window appears as it is supposed to. However, on second key press, the window does not go away, it's still there, as if the delwin call does not succeed. I tried refreshing the screen after it, but have had no success.
Here's a minimal example:
use ncurses::*;
struct LineNumbers {
window: WINDOW,
shown: bool
}
impl LineNumbers {
fn new() -> LineNumbers {
LineNumbers {
window: newwin(LINES(), 5, 0, 0),
shown: false
}
}
fn toggle(&mut self) {
if self.shown == true {
self.hide();
} else {
self.show();
}
}
fn show(&mut self) {
self.shown = true;
wbkgd(self.window, COLOR_PAIR(1));
wrefresh(self.window);
}
fn hide(&mut self) {
self.shown = false;
delwin(self.window);
refresh();
}
}
fn main() {
setlocale(LcCategory::all, "");
initscr();
keypad(stdscr(), true);
start_color();
init_pair(1, COLOR_RED, COLOR_RED);
let mut ln = LineNumbers::new();
loop {
let user_input = get_wch();
match user_input.unwrap() {
WchResult::Char(ch) => {
match ch {
27 => break,
_ => {}
}
},
WchResult::KeyCode(code) => {
match code {
KEY_F5 => {
ln.toggle();
},
_ => {}
}
}
}
}
endwin();
}
What could be the issue?