Skip to content

Commit

Permalink
simplify and just output message
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang committed Jun 29, 2022
1 parent 76d4922 commit 85c21d3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn main() -> Result<()> {
utils::logging::init_logger(log::LevelFilter::Debug, std::ffi::OsStr::new("debug.log"))?;
}

// Read from config file.
let config_path = read_config(matches.value_of("config_location"))
.context("Unable to access the given config file location.")?;
let mut config: Config = create_or_get_config(&config_path)
Expand All @@ -58,7 +59,7 @@ fn main() -> Result<()> {
canvas::Painter::init(widget_layout, &config, get_color_scheme(&matches, &config)?)?;

// Check if the current environment is in a terminal.
if !check_if_terminal_and_wait() {
if !check_if_terminal() {
return Ok(());
}

Expand Down Expand Up @@ -114,7 +115,6 @@ fn main() -> Result<()> {
enable_raw_mode()?;

let mut terminal = Terminal::new(CrosstermBackend::new(stdout_val))?;

terminal.clear()?;
terminal.hide_cursor()?;

Expand Down
16 changes: 3 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,26 +274,16 @@ pub fn cleanup_terminal(
Ok(())
}

/// Check and report to the user if the current environment is not a terminal. If it isn't a terminal, wait
/// for user input and return `false` if the caller should bail. Otherwise, return `true`.
pub fn check_if_terminal_and_wait() -> bool {
/// Check and report to the user if the current environment is not a terminal.
pub fn check_if_terminal() -> bool {
use crossterm::tty::IsTty;

let out = stdout();
if !out.is_tty() {
println!(
"Warning: bottom is not being output to a terminal. Things might not work properly."
);
println!("Press Ctrl-c or input q to exit, or any other key to continue.");

match read().unwrap() {
Event::Key(event) => match event.modifiers {
KeyModifiers::NONE => !matches!(event.code, KeyCode::Char('q')),
KeyModifiers::CONTROL => !matches!(event.code, KeyCode::Char('c')),
_ => true,
},
_ => true,
}
false
} else {
true
}
Expand Down

0 comments on commit 85c21d3

Please sign in to comment.