Hi!
I've been working on a TUI and I'm trying to make a bool true if you press the right arrow key (this is to switch to a different menu), but for some reason, I have to press the right arrow key twice.
Full code:
extern crate termion;
use std::io::{stdin, stdout, Write};
use termion::event::Key;
use termion::input::TermRead;
use termion::raw::IntoRawMode;
fn main() {
let stdin = stdin();
let mut stdout = stdout().into_raw_mode().unwrap();
struct Area {
selection: i32,
menu: i32,
go: bool,
}
let mut area = Area {
selection: 0,
menu: 0,
go: false,
};
for c in stdin.keys() {
match c.unwrap() {
Key::Ctrl('q') => break,
Key::Down if area.selection > 0 => area.selection -= 1,
Key::Up if area.selection < 2 => area.selection += 1,
Key::Right => area.go = true,
_ => (),
};
if area.menu == 0 {
println!(
"{}{}FIRST TIME SETUP {}",
termion::cursor::Goto(4, 2),
termion::clear::All,
termion::cursor::Hide,
);
println!(
"{}CONFIGURATION {}",
termion::cursor::Goto(4, 4),
termion::cursor::Hide
);
println!(
"{}RUN AIO-BACKUP {}",
termion::cursor::Goto(4, 6),
termion::cursor::Hide
);
match area.selection {
2 => {
println!(
"{}---> {}",
termion::cursor::Goto(21, 2),
termion::cursor::Hide
);
if area.go == true {
area.menu = 1;
}
}
1 => {
println!(
"{}---> {}",
termion::cursor::Goto(21, 4),
termion::cursor::Hide
);
if area.go == true {
area.go = false;
area.menu = 2;
}
}
0 => {
println!(
"{}---> {}",
termion::cursor::Goto(21, 6),
termion::cursor::Hide
);
if area.go == true {
area.go = false;
area.menu = 3;
}
}
_ => (),
}
} else if area.menu == 1 {
println!( }"{}{}Test, menu one {}",
termion::clear::All,
termion::cursor::Goto(4, 2),
termion::cursor::Hide,
);
}
stdout.flush().unwrap();
write!(stdout, "{}", termion::cursor::Show).unwrap();
}
And just so you know, I haven't finished all the menus yet, that's why most of the time it just leads to an empty menu