Fix issue with default file paths not being respected; updated default file paths.

This commit is contained in:
ClementTsang 2020-02-20 23:10:52 -05:00
parent e7352ddef1
commit 0697d9dd56
7 changed files with 41 additions and 21 deletions

View file

@ -51,18 +51,18 @@ before_deploy:
cargo build --release --target $TARGET; cargo build --release --target $TARGET;
cp ./target/x86_64-pc-windows-msvc/release/btm btm; cp ./target/x86_64-pc-windows-msvc/release/btm btm;
strip btm; strip btm;
cp default_config.toml btm.toml; cp default_config.toml bottom.toml;
tar -czvf bottom_x86_64-pc-windows-msvc.tar.gz btm btm.toml; tar -czvf bottom_x86_64-pc-windows-msvc.tar.gz btm bottom.toml;
else else
cargo build --release; cargo build --release;
cp ./target/release/btm btm; cp ./target/release/btm btm;
strip btm; strip btm;
cp default_config.toml btm.toml; cp default_config.toml bottom.toml;
if [[ $TRAVIS_OS_NAME == "linux" ]]; then if [[ $TRAVIS_OS_NAME == "linux" ]]; then
tar -czvf bottom_x86_64-unknown-linux-gnu.tar.gz btm btm.toml; tar -czvf bottom_x86_64-unknown-linux-gnu.tar.gz btm bottom.toml;
tar -czvf bottom_source_code.tar.gz ./src ./Cargo.toml LICENSE tests sample_config.toml btm.toml; tar -czvf bottom_source_code.tar.gz ./src ./Cargo.toml LICENSE tests sample_config.toml bottom.toml;
elif [[ $TRAVIS_OS_NAME == "osx" ]]; then elif [[ $TRAVIS_OS_NAME == "osx" ]]; then
tar -czvf bottom_x86_64-apple-darwin.tar.gz btm btm.toml; tar -czvf bottom_x86_64-apple-darwin.tar.gz btm bottom.toml;
fi fi
fi fi

View file

@ -23,6 +23,7 @@ lto = true
[dependencies] [dependencies]
chrono = "0.4.10" chrono = "0.4.10"
clap = "2.33.0" clap = "2.33.0"
dirs = "2.0.2"
fern = "0.5.9" fern = "0.5.9"
futures-timer = "3.0.2" futures-timer = "3.0.2"
futures = "0.3.4" futures = "0.3.4"

View file

@ -107,7 +107,7 @@ Run using `btm`.
- `-s`, `--show_disabled_data` will show data entries in the graph legends even if the lines for that entry are disabled. - `-s`, `--show_disabled_data` will show data entries in the graph legends even if the lines for that entry are disabled.
- `-C`, `--config` takes in a file path leading to a TOML file. - `-C`, `--config` takes in a file path leading to a TOML file. By default it checks `~/.config/btm/btm.toml` or `./btm.toml` for Unix and Windows respectively.
### Keybindings ### Keybindings
@ -191,6 +191,7 @@ Note that `q` is disabled while in the search widget.
- [chrono](https://github.com/chronotope/chrono) - [chrono](https://github.com/chronotope/chrono)
- [clap](https://github.com/clap-rs/clap) - [clap](https://github.com/clap-rs/clap)
- [crossterm](https://github.com/TimonPost/crossterm) - [crossterm](https://github.com/TimonPost/crossterm)
- [dirs](https://github.com/soc/dirs-rs)
- [fern](https://github.com/daboross/fern) - [fern](https://github.com/daboross/fern)
- [futures-rs](https://github.com/rust-lang-nursery/futures-rs) - [futures-rs](https://github.com/rust-lang-nursery/futures-rs)
- [futures-timer](https://github.com/rustasync/futures-timer) - [futures-timer](https://github.com/rustasync/futures-timer)

View file

@ -34,5 +34,5 @@ Note some colours may not be compatible with the terminal you are using. For exa
bottom will check specific locations by default for a config file. bottom will check specific locations by default for a config file.
- For Unix-based systems: `~/.config/btm/btm.toml`. - For Unix-based systems: `$HOME/.config/bottom/bottom.toml`.
- For Windows: `./btm.toml`. - For Windows: `{FOLDERID_RoamingAppData}\bottom\bottom.toml` (for example, `C:\Users\Clement\AppData\Roaming\bottom\bottom.toml`).

View file

@ -6,8 +6,8 @@ pub const MAX_KEY_TIMEOUT_IN_MILLISECONDS: u128 = 1000;
pub const NUM_COLOURS: i32 = 256; pub const NUM_COLOURS: i32 = 256;
// Config and flags // Config and flags
pub const DEFAULT_UNIX_CONFIG_FILE_PATH: &str = "~/.config/btm/btm.toml"; pub const DEFAULT_UNIX_CONFIG_FILE_PATH: &str = ".config/bottom/bottom.toml";
pub const DEFAULT_WINDOWS_CONFIG_FILE_PATH: &str = "./btm.toml"; pub const DEFAULT_WINDOWS_CONFIG_FILE_PATH: &str = "bottom/bottom.toml";
// Help text // Help text
pub const GENERAL_HELP_TEXT: [&str; 15] = [ pub const GENERAL_HELP_TEXT: [&str; 15] = [

View file

@ -213,7 +213,6 @@ fn main() -> error::Result<()> {
let mut first_run = true; let mut first_run = true;
loop { loop {
// TODO: [OPT] this should not block...
if let Ok(recv) = rx.recv_timeout(Duration::from_millis(TICK_RATE_IN_MILLISECONDS)) { if let Ok(recv) = rx.recv_timeout(Duration::from_millis(TICK_RATE_IN_MILLISECONDS)) {
match recv { match recv {
Event::KeyInput(event) => { Event::KeyInput(event) => {
@ -408,15 +407,28 @@ fn create_logger() -> error::Result<()> {
} }
fn create_config(flag_config_location: Option<&str>) -> error::Result<Config> { fn create_config(flag_config_location: Option<&str>) -> error::Result<Config> {
let config_path = std::path::Path::new(flag_config_location.unwrap_or( use std::ffi::OsString;
if cfg!(target_os = "windows") { let config_path = if let Some(conf_loc) = flag_config_location {
DEFAULT_WINDOWS_CONFIG_FILE_PATH OsString::from(conf_loc)
} else if cfg!(target_os = "windows") {
if let Some(home_path) = dirs::config_dir() {
let mut path = home_path;
path.push(DEFAULT_WINDOWS_CONFIG_FILE_PATH);
path.into_os_string()
} else { } else {
DEFAULT_UNIX_CONFIG_FILE_PATH OsString::new()
}, }
)); } else if let Some(home_path) = dirs::home_dir() {
let mut path = home_path;
path.push(DEFAULT_UNIX_CONFIG_FILE_PATH);
path.into_os_string()
} else {
OsString::new()
};
if let Ok(config_str) = std::fs::read_to_string(config_path) { let path = std::path::Path::new(&config_path);
if let Ok(config_str) = std::fs::read_to_string(path) {
Ok(toml::from_str(config_str.as_str())?) Ok(toml::from_str(config_str.as_str())?)
} else { } else {
Ok(Config::default()) Ok(Config::default())

View file

@ -4,6 +4,8 @@ use std::process::Command;
// These tests are mostly here just to ensure that invalid results will be caught when passing arguments... // These tests are mostly here just to ensure that invalid results will be caught when passing arguments...
// TODO: [TEST] Allow for release testing.
//======================RATES======================// //======================RATES======================//
fn get_os_binary_loc() -> String { fn get_os_binary_loc() -> String {
@ -36,7 +38,9 @@ fn test_large_rate() -> Result<(), Box<dyn std::error::Error>> {
.arg("18446744073709551616") .arg("18446744073709551616")
.assert() .assert()
.failure() .failure()
.stderr(predicate::str::contains("rate to be less than unsigned INT_MAX.")); .stderr(predicate::str::contains(
"rate to be less than unsigned INT_MAX.",
));
Ok(()) Ok(())
} }
@ -48,7 +52,9 @@ fn test_negative_rate() -> Result<(), Box<dyn std::error::Error>> {
.arg("-1000") .arg("-1000")
.assert() .assert()
.failure() .failure()
.stderr(predicate::str::contains("wasn't expected, or isn't valid in this context")); .stderr(predicate::str::contains(
"wasn't expected, or isn't valid in this context",
));
Ok(()) Ok(())
} }