diff --git a/CHANGELOG.md b/CHANGELOG.md index 99042bafa..9ab8a259b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#711](https://github.com/ClementTsang/bottom/pull/711): Fix building in Rust beta 1.61 due to `as_ref()` calls causing type inference issues. - - [#717](https://github.com/ClementTsang/bottom/pull/717): Fix clicking on empty space in tables selecting the very last entry of a list in some cases. +- [#717](https://github.com/ClementTsang/bottom/pull/717): Fix clicking on empty space in tables selecting the very last entry of a list in some cases. ## Changes @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#676](https://github.com/ClementTsang/bottom/pull/676): Adds support for NVIDIA GPU temperature sensors. +- [#760](https://github.com/ClementTsang/bottom/pull/760): Adds a check for whether bottom is being run in a terminal. + ## [0.6.8] - 2022-02-01 ## Bug Fixes diff --git a/src/bin/main.rs b/src/bin/main.rs index e3a863151..4e274ca0d 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -33,6 +33,10 @@ fn main() -> Result<()> { utils::logging::init_logger(log::LevelFilter::Debug, std::ffi::OsStr::new("debug.log"))?; } + // Check if the current environment is in a terminal. + check_if_terminal(); + + // 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) diff --git a/src/lib.rs b/src/lib.rs index 15b92f24f..6befaf157 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ extern crate log; use std::{ boxed::Box, fs, - io::{stdout, Write}, + io::{stderr, stdout, Write}, panic::PanicInfo, path::PathBuf, sync::Arc, @@ -271,15 +271,22 @@ pub fn cleanup_terminal( )?; terminal.show_cursor()?; - // if is_debug { - // let mut tmp_dir = std::env::temp_dir(); - // tmp_dir.push("bottom_debug.log"); - // println!("Your debug file is located at {:?}", tmp_dir.as_os_str()); - // } - Ok(()) } +/// Check and report to the user if the current environment is not a terminal. +pub fn check_if_terminal() { + use crossterm::tty::IsTty; + + if !stdout().is_tty() { + eprintln!( + "Warning: bottom is not being output to a terminal. Things might not work properly." + ); + stderr().flush().unwrap(); + thread::sleep(Duration::from_secs(1)); + } +} + /// A panic hook to properly restore the terminal in the case of a panic. /// Based on [spotify-tui's implementation](https://github.com/Rigellute/spotify-tui/blob/master/src/main.rs). pub fn panic_hook(panic_info: &PanicInfo<'_>) {