I am trying to detect user input by using crossterm
, when Ctrl R is pressed it should go back to the main function. If I press any key, (not just the Ctrl R , it simply exits.
The following error message appears:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: NotConnected, error: "Not a terminal" }', src\prompts\confirm.rs:8:10.
The error, though, somehow happens not in the return_to_main
file, which has the following code:
use crossterm::event::{Event, KeyCode, KeyEvent};
use crossterm::terminal::disable_raw_mode;
use crossterm::{event, terminal};
use std::time::Duration;
pub fn return_to_main() -> crossterm::Result<()> {
terminal::enable_raw_mode()?;
loop {
if event::poll(Duration::from_millis(1000))? {
if let Event::Key(event) = event::read()? {
match event {
KeyEvent {
code: KeyCode::Char('r'),
modifiers: event::KeyModifiers::CONTROL,
kind: _,
state: _,
} => return Ok(()),
_ => (),
}
}
}
disable_raw_mode()?;
}
}
but in the confirm.rs
file which has the following code. (module for confirming something)
use dialoguer::{theme::ColorfulTheme, Confirm};
pub fn confirm(prompt: &str) -> bool {
Confirm::with_theme(&ColorfulTheme::default())
.with_prompt(prompt)
.default(true)
.interact()
.unwrap()
}
Note: without enabling raw mode this code works completely fine.