1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use inquire::{self, error::InquireResult};
use is_terminal::IsTerminal;
use std::fmt::Display;

pub mod command;
pub mod progress;

/// Check if STDIN is a TTY
pub fn is_stdin_tty() -> bool {
    std::io::stdin().is_terminal()
}

/// Check if STDOUT is a TTY
pub fn is_stdout_tty() -> bool {
    std::io::stdout().is_terminal()
}

pub fn choose_option<T: Display>(message: &str, options: Vec<T>) -> InquireResult<T> {
    inquire::Select::new(message, options)
        .with_vim_mode(true)
        .with_help_message("↑↓ to move, press Ctrl+C to abort and exit")
        .prompt()
}

pub fn is_user_cancellation_error(err: &InquireError) -> bool {
    matches!(
        err,
        InquireError::OperationCanceled | InquireError::OperationInterrupted
    )
}

pub use inquire::*;