diff --git a/CHANGELOG.md b/CHANGELOG.md index 2db85377..9435a609 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,15 +17,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changes -- Changed default colours for highlighted borders and table headers to cyan - this is mostly to deal with Powershell colour conflicts. +- Changed default colours for highlighted borders and table headers to light blue - this is mostly to deal with Powershell colour conflicts. - Updated the widget type keyword list to accept the following keywords as existing types: + - `"memory"` - `"network"` - `"process"` - `"processes"` - `"temperature"` +- Removed an (undocumented) feature in allowing modifying total RX/TX colours. This is mainly due to the legend change. + +- [#117](https://github.com/ClementTsang/bottom/issues/117): Update tui to 0.9: + + - Use custom legend-hiding to stop hiding legends for memory and network widgets. + + - In addition, changed to using only legends within the graph for network, as well as redesigned the legend. + The old legend style can still be used via the `--use_old_network_legend` flag or `use_old_network_legend = true` config option. + + - Allow for option to hide the header gap on tables via `--hide_table_gap` or `hide_table_gap = true`. + + - Switch to stateful widget style for tables. + + - Switch to using tui-rs' new built in linear interpolation rather than doing it manually. + ### Bug Fixes - Fixed `dd` not working on non-first entries. diff --git a/Cargo.lock b/Cargo.lock index 652740e7..f0bdec28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -48,8 +48,8 @@ name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hermit-abi 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "hermit-abi 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -65,7 +65,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "backtrace-sys 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -75,7 +75,7 @@ version = "0.1.35" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -91,7 +91,7 @@ dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "mach 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -132,11 +132,11 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "predicates 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)", - "sysinfo 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", + "sysinfo 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tui 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tui 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "typed-builder 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -201,7 +201,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -210,7 +210,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-foundation-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -266,21 +266,6 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "crossterm" -version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crossterm_winapi 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", - "signal-hook 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "crossterm" version = "0.17.3" @@ -289,21 +274,13 @@ dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossterm_winapi 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "signal-hook 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "crossterm_winapi" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "crossterm_winapi" version = "0.6.1" @@ -318,7 +295,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "darwin-libproc-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -327,7 +304,7 @@ name = "darwin-libproc-sys" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -350,7 +327,7 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "redox_users 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -483,7 +460,7 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -514,7 +491,7 @@ dependencies = [ "futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "futures-util 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "mach 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -531,7 +508,7 @@ dependencies = [ "heim-common 0.0.10 (registry+https://github.com/rust-lang/crates.io-index)", "heim-runtime 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "mach 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -546,7 +523,7 @@ dependencies = [ "core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "heim-common 0.0.10 (registry+https://github.com/rust-lang/crates.io-index)", "heim-runtime 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "mach 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "widestring 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -561,7 +538,7 @@ dependencies = [ "heim-common 0.0.10 (registry+https://github.com/rust-lang/crates.io-index)", "heim-runtime 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "mach 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "platforms 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -576,7 +553,7 @@ dependencies = [ "heim-common 0.0.10 (registry+https://github.com/rust-lang/crates.io-index)", "heim-runtime 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "mach 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -591,7 +568,7 @@ dependencies = [ "heim-common 0.0.10 (registry+https://github.com/rust-lang/crates.io-index)", "heim-runtime 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "macaddr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -609,7 +586,7 @@ dependencies = [ "heim-net 0.0.10 (registry+https://github.com/rust-lang/crates.io-index)", "heim-runtime 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "mach 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "ntapi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -652,10 +629,10 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -668,15 +645,7 @@ name = "iovec" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "itertools" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -708,7 +677,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.68" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -737,7 +706,7 @@ name = "mach" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -745,7 +714,7 @@ name = "mach" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -776,7 +745,7 @@ dependencies = [ "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -801,7 +770,7 @@ version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -813,7 +782,7 @@ dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -825,7 +794,7 @@ dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -871,11 +840,11 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hermit-abi 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "hermit-abi 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -907,7 +876,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -932,7 +901,7 @@ dependencies = [ "float-cmp 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "normalize-line-endings 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1004,7 +973,7 @@ dependencies = [ "crossbeam-queue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1024,7 +993,7 @@ dependencies = [ [[package]] name = "regex" -version = "1.3.6" +version = "1.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1103,7 +1072,7 @@ name = "signal-hook" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", "signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1114,7 +1083,7 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arc-swap 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1144,12 +1113,12 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.13.1" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "doc-comment 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "ntapi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "once_cell 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1177,7 +1146,7 @@ name = "threadpool" version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1185,7 +1154,7 @@ name = "time" version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1205,15 +1174,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "tui" -version = "0.8.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "cassowary 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "crossterm 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)", + "crossterm 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "itertools 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1230,7 +1198,7 @@ dependencies = [ [[package]] name = "typenum" -version = "1.11.2" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1254,7 +1222,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", + "typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1264,7 +1232,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num-rational 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", + "typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1282,7 +1250,7 @@ name = "wait-timeout" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1363,9 +1331,7 @@ dependencies = [ "checksum crossbeam-epoch 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" "checksum crossbeam-queue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c695eeca1e7173472a32221542ae469b3e9aac3a4fc81f7696bcad82029493db" "checksum crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" -"checksum crossterm 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5750773d74a7dc612eac2ded3f55e9cdeeaa072210cd17c0192aedb48adb3618" "checksum crossterm 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ccdd8ef63a44e821956c6a276eca0faaa889d6a067dfcdbd5bfe85dce3a1d250" -"checksum crossterm_winapi 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8777c700901e2d5b50c406f736ed6b8f9e43645c7e104ddb74f8bc42b8ae62f6" "checksum crossterm_winapi 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "057b7146d02fb50175fd7dbe5158f6097f33d02831f43b4ee8ae4ddf67b68f5c" "checksum darwin-libproc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9fb90051930c9a0f09e585762152048e23ac74d20c10590ef7cf01c0343c3046" "checksum darwin-libproc-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "57cebb5bde66eecdd30ddc4b9cd208238b15db4982ccc72db59d699ea10867c1" @@ -1399,15 +1365,14 @@ dependencies = [ "checksum heim-runtime 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "00bd0a5a5e4af50d5d7d9537d3ecf02dca42c26bbbd8dd76621c5116dab14f69" "checksum heim-sensors 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2f1250df4d79d4238261588e5aaf1de0e7853dbe632f5bd6868e394d1e730024" "checksum heim-virt 0.0.10 (registry+https://github.com/rust-lang/crates.io-index)" = "e4b6ac6721ba5856659a197934ce522250a3ddd2e8646daa5660b41f1ba96457" -"checksum hermit-abi 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e" +"checksum hermit-abi 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8a0d737e0f947a1864e93d33fdef4af8445a00d1ed8dc0c8ddb73139ea6abf15" "checksum hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "023b39be39e3a2da62a94feb433e91e8bcd37676fbc8bea371daf52b7a769a3e" "checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -"checksum itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484" "checksum itertools 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" -"checksum libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)" = "dea0c0405123bba743ee3f91f49b1c7cfb684eef0da0a50110f758ccf24cdff0" +"checksum libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)" = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005" "checksum lock_api 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" "checksum macaddr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "baee0bbc17ce759db233beb01648088061bf678383130602a298e6998eedb2d8" @@ -1426,7 +1391,7 @@ dependencies = [ "checksum num-integer 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba" "checksum num-rational 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" "checksum num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" -"checksum num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46203554f085ff89c235cd12f7075f3233af9b11ed7c9e16dfe2560d03313ce6" +"checksum num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" "checksum once_cell 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b" "checksum ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "18869315e81473c951eb56ad5558bbc56978562d3ecfb87abb7a1e944cea4518" "checksum parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" @@ -1445,7 +1410,7 @@ dependencies = [ "checksum rayon-core 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "08a89b46efaf957e52b18062fb2f4660f8b8a4dde1807ca002690868ef2c85a9" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum redox_users 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "09b23093265f8d200fa7b4c2c76297f47e681c655f6f1285a8780d6a022f7431" -"checksum regex 1.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7f6946991529684867e47d86474e3a6d0c0ab9b82d5821e314b1ede31fa3a4b3" +"checksum regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692" "checksum regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)" = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae" "checksum rust-argon2 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2bc8af4bda8e1ff4932523b94d3dd20ee30a87232323eda55903ffd71d2fb017" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" @@ -1461,16 +1426,16 @@ dependencies = [ "checksum smallvec 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05720e22615919e4734f6a99ceae50d00226c3c5aca406e102ebc33298214e0a" "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" "checksum syn 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03" -"checksum sysinfo 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8edb5068ab4f00d7f7e78cae194235a4f45671fb5a19b344731b9ab5478e0a6f" +"checksum sysinfo 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d070254b7172eee9eb3990bea8f72aeabfe1226c40bf71a52e4fe75777812e9a" "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" "checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" "checksum threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a" "checksum treeline 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" -"checksum tui 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6b871b61f4c4b81e630215cd12e0ec29953d4545898e21a9e023b7520a74a9f9" +"checksum tui 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b7de74b91c6cb83119a2140e7c215d95d9e54db27b58a500a2cbdeec4987b0a2" "checksum typed-builder 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "78cea224ddd4282dfc40d1edabbd0c020a12e946e3a48e2c2b8f6ff167ad29fe" -"checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" +"checksum typenum 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" "checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" "checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" diff --git a/Cargo.toml b/Cargo.toml index b47a4af7..422c8ab9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,9 +33,9 @@ heim = "0.0.10" itertools = "0.9.0" log = "0.4.8" regex = "1.3" -sysinfo = "0.13" +sysinfo = "0.14" toml = "0.5.6" -tui = {version = "0.8", features = ["crossterm"], default-features = false } +tui = {version = "0.9", features = ["crossterm"], default-features = false } typed-builder = "0.5.1" lazy_static = "1.4.0" backtrace = "0.3" diff --git a/README.md b/README.md index 904adf5c..8767a79e 100644 --- a/README.md +++ b/README.md @@ -126,29 +126,35 @@ Run using `btm`. ### Flags ``` --h, --help Prints help information, including flags and options --a, --avg_cpu Shows the average CPU usage in addition to per-core --m, --dot-marker Uses a dot marker instead of the default braille marker --c, --celsius Displays the temperature type in Celsius [default] --f, --fahrenheit Displays the temperature type in Fahrenheit --k, --kelvin Displays the temperature type in Kelvin --l, --left_legend Displays the CPU legend to the left rather than the right --u, --current_usage Sets process CPU usage to be based on current total CPU usage --g, --group Groups together processes with the same name by default --S, --case_sensitive Search defaults to matching cases --W, --whole Search defaults to searching for the whole word --R, --regex Search defaults to using regex --s, --show_disabled_data Shows disabled CPU entries in the CPU legend --b, --basic Enables basic mode, removing charts and condensing data +-h, --help Prints help information, including flags and options +-a, --avg_cpu Shows the average CPU usage in addition to per-core +-m, --dot-marker Uses a dot marker instead of the default braille marker +-c, --celsius Displays the temperature type in Celsius [default] +-f, --fahrenheit Displays the temperature type in Fahrenheit +-k, --kelvin Displays the temperature type in Kelvin +-l, --left_legend Displays the CPU legend to the left rather than the right +-u, --current_usage Sets process CPU usage to be based on current total CPU usage +-g, --group Groups together processes with the same name by default +-S, --case_sensitive Search defaults to matching cases +-W, --whole Search defaults to searching for the whole word +-R, --regex Search defaults to using regex +-s, --show_disabled_data Shows disabled CPU entries in the CPU legend +-b, --basic Enables basic mode, removing charts and condensing data + --autohide_time Automatically hide the time scaling in graphs after being shown for a brief moment when + zoomed in/out. If time is disabled via --hide_time then this will have no effect. + --use_old_network_legend Use the older (pre-0.4) network legend which is separate from the network chart + --hide_table_gap Hides the spacing between table headers and data ``` ### Options ``` --r, --rate Set the refresh rate in milliseconds [default: 1000] --C, --config Use the specified config file; if it does not exist it is automatically created --t, --default_time_value Sets the default time interval for charts in milliseconds [default: 60000] --d, --time_delta Sets the default amount each zoom in/out action changes by in milliseconds [default: 15000] +-r, --rate Set the refresh rate in milliseconds [default: 1000] +-C, --config Use the specified config file; if it does not exist it is automatically created +-t, --default_time_value Sets the default time interval for charts in milliseconds [default: 60000] +-d, --time_delta Sets the default amount each zoom in/out action changes by in milliseconds [default: 15000] + --default_widget_count Which number of the selected widget type to select, from left to right, top to bottom. Defaults to 1. + --default_widget_type The default widget type to select by default. ``` ### Keybindings @@ -287,6 +293,8 @@ These are the following supported flag config values: | `regex` | Boolean | | `show_disabled_data` | Boolean | | `basic` | Boolean | +| `hide_table_count`| Boolean | +| `use_old_network_legend`| Boolean | | `rate` | Unsigned Int (represents milliseconds) | | `default_time_value` | Unsigned Int (represents milliseconds) | | `time_delta` | Unsigned Int (represents milliseconds) | diff --git a/src/app.rs b/src/app.rs index d2aeb005..4f32b398 100644 --- a/src/app.rs +++ b/src/app.rs @@ -3,6 +3,8 @@ use std::{cmp::max, collections::HashMap, time::Instant}; use unicode_segmentation::GraphemeCursor; use unicode_width::{UnicodeWidthChar, UnicodeWidthStr}; +use tui::widgets::TableState; + use typed_builder::*; use data_farmer::*; @@ -47,6 +49,7 @@ pub struct AppScrollWidgetState { pub current_scroll_position: u64, pub previous_scroll_position: u64, pub scroll_direction: ScrollDirection, + pub table_state: TableState, } #[derive(Default)] @@ -90,6 +93,8 @@ pub struct AppConfigFields { pub time_interval: u64, pub hide_time: bool, pub autohide_time: bool, + pub use_old_network_legend: bool, + pub table_gap: u16, } /// AppSearchState deals with generic searching (I might do this in the future). diff --git a/src/app/data_farmer.rs b/src/app/data_farmer.rs index 2d4d9273..9b5a30bb 100644 --- a/src/app/data_farmer.rs +++ b/src/app/data_farmer.rs @@ -21,18 +21,14 @@ use crate::data_harvester::{ pub type TimeOffset = f64; pub type Value = f64; -pub type JoinedDataPoints = (Value, Vec<(TimeOffset, Value)>); #[derive(Debug, Default)] pub struct TimedData { - pub rx_data: JoinedDataPoints, - pub tx_data: JoinedDataPoints, - pub cpu_data: Vec, - pub mem_data: JoinedDataPoints, - pub swap_data: JoinedDataPoints, - // Unused for now - // pub io_data : JoinedDataPoints - // pub temp_data: JoinedDataPoints, + pub rx_data: Value, + pub tx_data: Value, + pub cpu_data: Vec, + pub mem_data: Value, + pub swap_data: Value, } /// AppCollection represents the pooled data stored within the main app @@ -121,19 +117,19 @@ impl DataCollection { // Network if let Some(network) = &harvested_data.network { - self.eat_network(network, harvested_time, &mut new_entry); + self.eat_network(network, &mut new_entry); } // Memory and Swap if let Some(memory) = &harvested_data.memory { if let Some(swap) = &harvested_data.swap { - self.eat_memory_and_swap(memory, swap, harvested_time, &mut new_entry); + self.eat_memory_and_swap(memory, swap, &mut new_entry); } } // CPU if let Some(cpu) = &harvested_data.cpu { - self.eat_cpu(cpu, harvested_time, &mut new_entry); + self.eat_cpu(cpu, &mut new_entry); } // Temp @@ -164,7 +160,7 @@ impl DataCollection { } fn eat_memory_and_swap( - &mut self, memory: &mem::MemHarvest, swap: &mem::MemHarvest, harvested_time: Instant, + &mut self, memory: &mem::MemHarvest, swap: &mem::MemHarvest, new_entry: &mut TimedData, ) { // Memory @@ -172,13 +168,7 @@ impl DataCollection { 0 => 0f64, total => (memory.mem_used_in_mb as f64) / (total as f64) * 100.0, }; - let mem_joining_pts = if let Some((time, last_pt)) = self.timed_data_vec.last() { - generate_joining_points(*time, last_pt.mem_data.0, harvested_time, mem_percent) - } else { - Vec::new() - }; - let mem_pt = (mem_percent, mem_joining_pts); - new_entry.mem_data = mem_pt; + new_entry.mem_data = mem_percent; // Swap if swap.mem_total_in_mb > 0 { @@ -186,13 +176,7 @@ impl DataCollection { 0 => 0f64, total => (swap.mem_used_in_mb as f64) / (total as f64) * 100.0, }; - let swap_joining_pt = if let Some((time, last_pt)) = self.timed_data_vec.last() { - generate_joining_points(*time, last_pt.swap_data.0, harvested_time, swap_percent) - } else { - Vec::new() - }; - let swap_pt = (swap_percent, swap_joining_pt); - new_entry.swap_data = swap_pt; + new_entry.swap_data = swap_percent; } // In addition copy over latest data for easy reference @@ -201,7 +185,7 @@ impl DataCollection { } fn eat_network( - &mut self, network: &network::NetworkHarvest, harvested_time: Instant, + &mut self, network: &network::NetworkHarvest, new_entry: &mut TimedData, ) { // RX @@ -210,14 +194,7 @@ impl DataCollection { } else { 0.0 }; - - let rx_joining_pts = if let Some((time, last_pt)) = self.timed_data_vec.last() { - generate_joining_points(*time, last_pt.rx_data.0, harvested_time, logged_rx_val) - } else { - Vec::new() - }; - let rx_pt = (logged_rx_val, rx_joining_pts); - new_entry.rx_data = rx_pt; + new_entry.rx_data = logged_rx_val; // TX let logged_tx_val = if network.tx as f64 > 0.0 { @@ -225,38 +202,20 @@ impl DataCollection { } else { 0.0 }; - - let tx_joining_pts = if let Some((time, last_pt)) = self.timed_data_vec.last() { - generate_joining_points(*time, last_pt.tx_data.0, harvested_time, logged_tx_val) - } else { - Vec::new() - }; - let tx_pt = (logged_tx_val, tx_joining_pts); - new_entry.tx_data = tx_pt; + new_entry.tx_data = logged_tx_val; // In addition copy over latest data for easy reference self.network_harvest = network.clone(); } fn eat_cpu( - &mut self, cpu: &[cpu::CPUData], harvested_time: Instant, new_entry: &mut TimedData, + &mut self, cpu: &[cpu::CPUData], new_entry: &mut TimedData, ) { // Note this only pre-calculates the data points - the names will be // within the local copy of cpu_harvest. Since it's all sequential // it probably doesn't matter anyways. - if let Some((time, last_pt)) = self.timed_data_vec.last() { - for (cpu, last_pt_data) in cpu.iter().zip(&last_pt.cpu_data) { - let cpu_joining_pts = - generate_joining_points(*time, last_pt_data.0, harvested_time, cpu.cpu_usage); - let cpu_pt = (cpu.cpu_usage, cpu_joining_pts); - new_entry.cpu_data.push(cpu_pt); - } - } else { - for cpu in cpu.iter() { - let cpu_pt = (cpu.cpu_usage, Vec::new()); - new_entry.cpu_data.push(cpu_pt); - } - } + cpu.iter() + .for_each(|cpu| new_entry.cpu_data.push(cpu.cpu_usage)); self.cpu_harvest = cpu.to_vec(); } @@ -309,36 +268,3 @@ impl DataCollection { self.battery_harvest = list_of_batteries.to_vec(); } } - -pub fn generate_joining_points( - start_x: Instant, start_y: f64, end_x: Instant, end_y: f64, -) -> Vec<(TimeOffset, Value)> { - let mut points: Vec<(TimeOffset, Value)> = Vec::new(); - - // Convert time floats first: - let tmp_time_diff = (end_x).duration_since(start_x).as_millis() as f64; - let time_difference = if tmp_time_diff == 0.0 { - 0.001 - } else { - tmp_time_diff - }; - let value_difference = end_y - start_y; - - // Let's generate... about this many points! - let num_points = std::cmp::min( - std::cmp::max( - (value_difference.abs() / time_difference * 2000.0) as u64, - 50, - ), - 2000, - ); - - for itx in (0..num_points).step_by(2) { - points.push(( - time_difference - (itx as f64 / num_points as f64 * time_difference), - start_y + (itx as f64 / num_points as f64 * value_difference), - )); - } - - points -} diff --git a/src/canvas.rs b/src/canvas.rs index a14f29de..9e4aaf30 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -69,10 +69,11 @@ pub struct Painter { layout_constraints: Vec>>>, widget_layout: BottomLayout, derived_widget_draw_locs: Vec>>>, + table_height_offset: i64, } impl Painter { - pub fn init(widget_layout: BottomLayout) -> Self { + pub fn init(widget_layout: BottomLayout, table_gap: u16) -> Self { // Now for modularity; we have to also initialize the base layouts! // We want to do this ONCE and reuse; after this we can just construct // based on the console size. @@ -154,6 +155,7 @@ impl Painter { layout_constraints, widget_layout, derived_widget_draw_locs: Vec::new(), + table_height_offset: 4 + table_gap as i64, } } @@ -347,6 +349,7 @@ impl Painter { app_state, rect[0], app_state.current_widget.widget_id, + false, ), Proc => self.draw_process_and_search( &mut f, diff --git a/src/canvas/canvas_colours.rs b/src/canvas/canvas_colours.rs index 169bde02..c38b487d 100644 --- a/src/canvas/canvas_colours.rs +++ b/src/canvas/canvas_colours.rs @@ -35,8 +35,10 @@ impl Default for CanvasColours { CanvasColours { currently_selected_text_colour: Color::Black, currently_selected_bg_colour: Color::Cyan, - currently_selected_text_style: Style::default().fg(Color::Black).bg(Color::Cyan), - table_header_style: Style::default().fg(Color::Cyan), + currently_selected_text_style: Style::default() + .fg(Color::Black) + .bg(STANDARD_HIGHLIGHT_COLOUR), + table_header_style: Style::default().fg(STANDARD_HIGHLIGHT_COLOUR), ram_style: Style::default().fg(STANDARD_FIRST_COLOUR), swap_style: Style::default().fg(STANDARD_SECOND_COLOUR), rx_style: Style::default().fg(STANDARD_FIRST_COLOUR), @@ -46,7 +48,7 @@ impl Default for CanvasColours { avg_colour_style: Style::default().fg(AVG_COLOUR), cpu_colour_styles: Vec::new(), border_style: Style::default().fg(text_colour), - highlighted_border_style: Style::default().fg(Color::Cyan), + highlighted_border_style: Style::default().fg(STANDARD_HIGHLIGHT_COLOUR), text_style: Style::default().fg(text_colour), widget_title_style: Style::default().fg(text_colour), graph_style: Style::default().fg(text_colour), @@ -103,15 +105,15 @@ impl CanvasColours { Ok(()) } - pub fn set_rx_total_colour(&mut self, colour: &str) -> error::Result<()> { - self.total_rx_style = get_style_from_config(colour)?; - Ok(()) - } + // pub fn set_rx_total_colour(&mut self, colour: &str) -> error::Result<()> { + // self.total_rx_style = get_style_from_config(colour)?; + // Ok(()) + // } - pub fn set_tx_total_colour(&mut self, colour: &str) -> error::Result<()> { - self.total_tx_style = get_style_from_config(colour)?; - Ok(()) - } + // pub fn set_tx_total_colour(&mut self, colour: &str) -> error::Result<()> { + // self.total_tx_style = get_style_from_config(colour)?; + // Ok(()) + // } pub fn set_avg_cpu_colour(&mut self, colour: &str) -> error::Result<()> { self.avg_colour_style = get_style_from_config(colour)?; diff --git a/src/canvas/canvas_colours/colour_utils.rs b/src/canvas/canvas_colours/colour_utils.rs index 83c3f18a..0d1af937 100644 --- a/src/canvas/canvas_colours/colour_utils.rs +++ b/src/canvas/canvas_colours/colour_utils.rs @@ -11,6 +11,7 @@ pub const STANDARD_FIRST_COLOUR: Color = Color::LightMagenta; pub const STANDARD_SECOND_COLOUR: Color = Color::LightYellow; pub const STANDARD_THIRD_COLOUR: Color = Color::LightCyan; pub const STANDARD_FOURTH_COLOUR: Color = Color::LightGreen; +pub const STANDARD_HIGHLIGHT_COLOUR: Color = Color::LightBlue; pub const AVG_COLOUR: Color = Color::Red; lazy_static! { diff --git a/src/canvas/dialogs/dd_dialog.rs b/src/canvas/dialogs/dd_dialog.rs index f73f1cea..2e952fae 100644 --- a/src/canvas/dialogs/dd_dialog.rs +++ b/src/canvas/dialogs/dd_dialog.rs @@ -4,7 +4,7 @@ use tui::{ backend::Backend, layout::{Alignment, Rect}, terminal::Frame, - widgets::{Block, Borders, Paragraph, Text, Widget}, + widgets::{Block, Borders, Paragraph, Text}, }; use crate::{app::App, canvas::Painter}; @@ -70,19 +70,21 @@ impl KillDialog for Painter { "─".repeat(repeat_num as usize) ); - Paragraph::new(dd_text.iter()) - .block( - Block::default() - .title(&dd_title) - .title_style(self.colours.border_style) - .style(self.colours.border_style) - .borders(Borders::ALL) - .border_style(self.colours.border_style), - ) - .style(self.colours.text_style) - .alignment(Alignment::Center) - .wrap(true) - .render(f, draw_loc); + f.render_widget( + Paragraph::new(dd_text.iter()) + .block( + Block::default() + .title(&dd_title) + .title_style(self.colours.border_style) + .style(self.colours.border_style) + .borders(Borders::ALL) + .border_style(self.colours.border_style), + ) + .style(self.colours.text_style) + .alignment(Alignment::Center) + .wrap(true), + draw_loc, + ); return true; } @@ -106,18 +108,20 @@ impl KillDialog for Painter { ); let error_title = format!(" Error ─{}─ Esc to close ", "─".repeat(repeat_num as usize)); - Paragraph::new(dd_text.iter()) - .block( - Block::default() - .title(&error_title) - .title_style(self.colours.border_style) - .style(self.colours.border_style) - .borders(Borders::ALL) - .border_style(self.colours.border_style), - ) - .style(self.colours.text_style) - .alignment(Alignment::Center) - .wrap(true) - .render(f, draw_loc); + f.render_widget( + Paragraph::new(dd_text.iter()) + .block( + Block::default() + .title(&error_title) + .title_style(self.colours.border_style) + .style(self.colours.border_style) + .borders(Borders::ALL) + .border_style(self.colours.border_style), + ) + .style(self.colours.text_style) + .alignment(Alignment::Center) + .wrap(true), + draw_loc, + ); } } diff --git a/src/canvas/dialogs/help_dialog.rs b/src/canvas/dialogs/help_dialog.rs index 82b40e7b..8dbca876 100644 --- a/src/canvas/dialogs/help_dialog.rs +++ b/src/canvas/dialogs/help_dialog.rs @@ -4,7 +4,7 @@ use tui::{ backend::Backend, layout::{Alignment, Rect}, terminal::Frame, - widgets::{Block, Borders, Paragraph, Widget}, + widgets::{Block, Borders, Paragraph}, }; use crate::{ @@ -33,25 +33,27 @@ impl HelpDialog for Painter { "─".repeat(repeat_num as usize) ); - Paragraph::new( - match app_state.help_dialog_state.current_category { - AppHelpCategory::General => &self.styled_general_help_text, - AppHelpCategory::Process => &self.styled_process_help_text, - AppHelpCategory::Search => &self.styled_search_help_text, - } - .iter(), - ) - .block( - Block::default() - .title(&help_title) - .title_style(self.colours.border_style) - .style(self.colours.border_style) - .borders(Borders::ALL) - .border_style(self.colours.border_style), - ) - .style(self.colours.text_style) - .alignment(Alignment::Left) - .wrap(true) - .render(f, draw_loc); + f.render_widget( + Paragraph::new( + match app_state.help_dialog_state.current_category { + AppHelpCategory::General => &self.styled_general_help_text, + AppHelpCategory::Process => &self.styled_process_help_text, + AppHelpCategory::Search => &self.styled_search_help_text, + } + .iter(), + ) + .block( + Block::default() + .title(&help_title) + .title_style(self.colours.border_style) + .style(self.colours.border_style) + .borders(Borders::ALL) + .border_style(self.colours.border_style), + ) + .style(self.colours.text_style) + .alignment(Alignment::Left) + .wrap(true), + draw_loc, + ); } } diff --git a/src/canvas/widgets/basic_table_arrows.rs b/src/canvas/widgets/basic_table_arrows.rs index 05392fb4..8284c691 100644 --- a/src/canvas/widgets/basic_table_arrows.rs +++ b/src/canvas/widgets/basic_table_arrows.rs @@ -9,7 +9,7 @@ use tui::{ backend::Backend, layout::{Constraint, Layout, Rect}, terminal::Frame, - widgets::{Block, Paragraph, Text, Widget}, + widgets::{Block, Paragraph, Text}, }; pub trait BasicTableArrows { @@ -59,8 +59,9 @@ impl BasicTableArrows for Painter { .horizontal_margin(1) .split(draw_loc); - Paragraph::new(arrow_text.iter()) - .block(Block::default()) - .render(f, margined_draw_loc[0]); + f.render_widget( + Paragraph::new(arrow_text.iter()).block(Block::default()), + margined_draw_loc[0], + ); } } diff --git a/src/canvas/widgets/battery_display.rs b/src/canvas/widgets/battery_display.rs index fcf191fd..90ae57f3 100644 --- a/src/canvas/widgets/battery_display.rs +++ b/src/canvas/widgets/battery_display.rs @@ -9,7 +9,7 @@ use tui::{ backend::Backend, layout::{Constraint, Rect}, terminal::Frame, - widgets::{Block, Borders, Paragraph, Row, Table, Tabs, Text, Widget}, + widgets::{Block, Borders, Paragraph, Row, Table, Tabs, Text}, }; pub trait BatteryDisplayWidget { @@ -106,39 +106,45 @@ impl BatteryDisplayWidget for Painter { }); // Draw - Table::new([""].iter(), battery_rows) - .block(battery_block) - .header_style(self.colours.table_header_style) - .widths([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) - .render(f, draw_loc); + f.render_widget( + Table::new([""].iter(), battery_rows) + .block(battery_block) + .header_style(self.colours.table_header_style) + .widths([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()), + draw_loc, + ); } else { - Paragraph::new( - [Text::Styled( - "No data found for this battery".into(), - self.colours.text_style, - )] - .iter(), - ) - .block(battery_block) - .render(f, draw_loc); + f.render_widget( + Paragraph::new( + [Text::Styled( + "No data found for this battery".into(), + self.colours.text_style, + )] + .iter(), + ) + .block(battery_block), + draw_loc, + ); } // if app_state.canvas_data.battery_data.len() > 1 { - Tabs::default() - .block(battery_block) - .titles( - (app_state - .canvas_data - .battery_data - .iter() - .map(|battery| &battery.battery_name)) - .collect::>() - .as_ref(), - ) - .divider(tui::symbols::line::VERTICAL) - .style(self.colours.text_style) - .highlight_style(self.colours.currently_selected_text_style) - .select(battery_widget_state.currently_selected_battery_index) - .render(f, draw_loc); + f.render_widget( + Tabs::default() + .block(battery_block) + .titles( + (app_state + .canvas_data + .battery_data + .iter() + .map(|battery| &battery.battery_name)) + .collect::>() + .as_ref(), + ) + .divider(tui::symbols::line::VERTICAL) + .style(self.colours.text_style) + .highlight_style(self.colours.currently_selected_text_style) + .select(battery_widget_state.currently_selected_battery_index), + draw_loc, + ); // } } } diff --git a/src/canvas/widgets/cpu_basic.rs b/src/canvas/widgets/cpu_basic.rs index 5f5655d6..a3299d7f 100644 --- a/src/canvas/widgets/cpu_basic.rs +++ b/src/canvas/widgets/cpu_basic.rs @@ -11,7 +11,7 @@ use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, terminal::Frame, - widgets::{Block, Paragraph, Text, Widget}, + widgets::{Block, Paragraph, Text}, }; pub trait CpuBasicWidget { @@ -37,10 +37,12 @@ impl CpuBasicWidget for Painter { // the desired lengths. if app_state.current_widget.widget_id == widget_id { - Block::default() - .borders(*SIDE_BORDERS) - .border_style(self.colours.highlighted_border_style) - .render(f, draw_loc); + f.render_widget( + Block::default() + .borders(*SIDE_BORDERS) + .border_style(self.colours.highlighted_border_style), + draw_loc, + ); } let num_cpus = cpu_data.len(); @@ -125,9 +127,10 @@ impl CpuBasicWidget for Painter { .horizontal_margin(1) .split(*chunk); - Paragraph::new(cpu_column.iter()) - .block(Block::default()) - .render(f, margined_loc[0]); + f.render_widget( + Paragraph::new(cpu_column.iter()).block(Block::default()), + margined_loc[0], + ); } } } diff --git a/src/canvas/widgets/cpu_graph.rs b/src/canvas/widgets/cpu_graph.rs index adb9f74c..cefed8a2 100644 --- a/src/canvas/widgets/cpu_graph.rs +++ b/src/canvas/widgets/cpu_graph.rs @@ -15,8 +15,9 @@ use crate::{ use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, + symbols::Marker, terminal::Frame, - widgets::{Axis, Block, Borders, Chart, Dataset, Marker, Row, Table, Widget}, + widgets::{Axis, Block, Borders, Chart, Dataset, Row, Table}, }; const CPU_SELECT_LEGEND_HEADER: [&str; 2] = ["CPU", "Show"]; @@ -145,7 +146,7 @@ impl CpuGraphWidget for Painter { .enumerate() .rev() .filter_map(|(itx, (cpu, cpu_show_vec))| { - if *cpu_show_vec { + if *cpu_show_vec && !cpu.cpu_data.is_empty() { Some( Dataset::default() .marker(if use_dot { @@ -159,7 +160,8 @@ impl CpuGraphWidget for Painter { self.colours.cpu_colour_styles [itx % self.colours.cpu_colour_styles.len()] }) - .data(&cpu.cpu_data[..]), + .data(&cpu.cpu_data[..]) + .graph_type(tui::widgets::GraphType::Line), ) } else { None @@ -187,22 +189,24 @@ impl CpuGraphWidget for Painter { self.colours.border_style }; - Chart::default() - .block( - Block::default() - .title(&title) - .title_style(if app_state.is_expanded { - border_style - } else { - self.colours.widget_title_style - }) - .borders(Borders::ALL) - .border_style(border_style), - ) - .x_axis(x_axis) - .y_axis(y_axis) - .datasets(&dataset_vector) - .render(f, draw_loc); + f.render_widget( + Chart::default() + .block( + Block::default() + .title(&title) + .title_style(if app_state.is_expanded { + border_style + } else { + self.colours.widget_title_style + }) + .borders(Borders::ALL) + .border_style(border_style), + ) + .x_axis(x_axis) + .y_axis(y_axis) + .datasets(&dataset_vector), + draw_loc, + ); } } @@ -214,7 +218,7 @@ impl CpuGraphWidget for Painter { cpu_widget_state.is_legend_hidden = false; let cpu_data: &mut [ConvertedCpuData] = &mut app_state.canvas_data.cpu_data; - let num_rows = max(0, i64::from(draw_loc.height) - 5) as u64; + let num_rows = max(0, i64::from(draw_loc.height) - self.table_height_offset) as u64; let start_position = get_start_position( num_rows, &cpu_widget_state.scroll_state.scroll_direction, @@ -222,13 +226,13 @@ impl CpuGraphWidget for Painter { cpu_widget_state.scroll_state.current_scroll_position, app_state.is_resized, ); + let is_on_widget = widget_id == app_state.current_widget.widget_id; let sliced_cpu_data = &cpu_data[start_position as usize..]; let mut offset_scroll_index = (cpu_widget_state.scroll_state.current_scroll_position - start_position) as usize; let show_disabled_data = app_state.app_config_fields.show_disabled_data; - let current_widget_id = app_state.current_widget.widget_id; let show_avg_cpu = app_state.app_config_fields.show_average_cpu; let cpu_rows = sliced_cpu_data.iter().enumerate().filter_map(|(itx, cpu)| { @@ -264,7 +268,7 @@ impl CpuGraphWidget for Painter { } else { Some(Row::StyledData( cpu_string_row.into_iter(), - if current_widget_id == widget_id { + if is_on_widget { if itx == offset_scroll_index { self.colours.currently_selected_text_style } else if show_avg_cpu && itx == 0 { @@ -312,37 +316,44 @@ impl CpuGraphWidget for Painter { "".to_string() }; - let title_and_border_style = if app_state.current_widget.widget_id == widget_id { - self.colours.highlighted_border_style + let (border_and_title_style, highlight_style) = if is_on_widget { + ( + self.colours.highlighted_border_style, + self.colours.currently_selected_text_style, + ) } else { - self.colours.border_style + (self.colours.border_style, self.colours.text_style) }; // Draw - Table::new( - if cpu_widget_state.is_showing_tray { - CPU_SELECT_LEGEND_HEADER - } else { - CPU_LEGEND_HEADER - } - .iter(), - cpu_rows, - ) - .block( - Block::default() - .title(&title) - .title_style(title_and_border_style) - .borders(Borders::ALL) - .border_style(title_and_border_style), - ) - .header_style(self.colours.table_header_style) - .widths( - &(intrinsic_widths - .iter() - .map(|calculated_width| Constraint::Length(*calculated_width as u16)) - .collect::>()), - ) - .render(f, draw_loc); + f.render_widget( + Table::new( + if cpu_widget_state.is_showing_tray { + CPU_SELECT_LEGEND_HEADER + } else { + CPU_LEGEND_HEADER + } + .iter(), + cpu_rows, + ) + .block( + Block::default() + .title(&title) + .title_style(border_and_title_style) + .borders(Borders::ALL) + .border_style(border_and_title_style), + ) + .header_style(self.colours.table_header_style) + .highlight_style(highlight_style) + .widths( + &(intrinsic_widths + .iter() + .map(|calculated_width| Constraint::Length(*calculated_width as u16)) + .collect::>()), + ) + .header_gap(app_state.app_config_fields.table_gap), + draw_loc, + ); } } } diff --git a/src/canvas/widgets/disk_table.rs b/src/canvas/widgets/disk_table.rs index fbceea15..13d24358 100644 --- a/src/canvas/widgets/disk_table.rs +++ b/src/canvas/widgets/disk_table.rs @@ -4,7 +4,7 @@ use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, terminal::Frame, - widgets::{Block, Borders, Row, Table, Widget}, + widgets::{Block, Borders, Row, Table}, }; use crate::{ @@ -39,7 +39,7 @@ impl DiskTableWidget for Painter { ) { if let Some(disk_widget_state) = app_state.disk_state.widget_states.get_mut(&widget_id) { let disk_data: &mut [Vec] = &mut app_state.canvas_data.disk_data; - let num_rows = max(0, i64::from(draw_loc.height) - 5) as u64; + let num_rows = max(0, i64::from(draw_loc.height) - self.table_height_offset) as u64; let start_position = get_start_position( num_rows, &disk_widget_state.scroll_state.scroll_direction, @@ -47,34 +47,14 @@ impl DiskTableWidget for Painter { disk_widget_state.scroll_state.current_scroll_position, app_state.is_resized, ); + let is_on_widget = app_state.current_widget.widget_id == widget_id; + let disk_table_state = &mut disk_widget_state.scroll_state.table_state; + disk_table_state.select(Some( + (disk_widget_state.scroll_state.current_scroll_position - start_position) as usize, + )); let sliced_vec = &mut disk_data[start_position as usize..]; - let mut disk_counter: i64 = 0; - - let current_widget_id = app_state.current_widget.widget_id; - let disk_rows = sliced_vec.iter().map(|disk| { - Row::StyledData( - disk.iter(), - if current_widget_id == widget_id - && disk_widget_state.scroll_state.current_scroll_position >= start_position - { - if disk_counter as u64 - == disk_widget_state.scroll_state.current_scroll_position - - start_position - { - disk_counter = -1; - self.colours.currently_selected_text_style - } else { - if disk_counter >= 0 { - disk_counter += 1; - } - self.colours.text_style - } - } else { - self.colours.text_style - }, - ) - }); + let disk_rows = sliced_vec.iter().map(|disk| Row::Data(disk.iter())); // Calculate widths // TODO: [PRETTY] Ellipsis on strings? @@ -101,10 +81,13 @@ impl DiskTableWidget for Painter { " Disk ".to_string() }; - let border_and_title_style = if app_state.current_widget.widget_id == widget_id { - self.colours.highlighted_border_style + let (border_and_title_style, highlight_style) = if is_on_widget { + ( + self.colours.highlighted_border_style, + self.colours.currently_selected_text_style, + ) } else { - self.colours.border_style + (self.colours.border_style, self.colours.text_style) }; let disk_block = if draw_border { @@ -117,7 +100,7 @@ impl DiskTableWidget for Painter { }) .borders(Borders::ALL) .border_style(border_and_title_style) - } else if app_state.current_widget.widget_id == widget_id { + } else if is_on_widget { Block::default() .borders(*SIDE_BORDERS) .border_style(self.colours.highlighted_border_style) @@ -127,27 +110,27 @@ impl DiskTableWidget for Painter { let margined_draw_loc = Layout::default() .constraints([Constraint::Percentage(100)].as_ref()) - .horizontal_margin( - if app_state.current_widget.widget_id == widget_id || draw_border { - 0 - } else { - 1 - }, - ) + .horizontal_margin(if is_on_widget || draw_border { 0 } else { 1 }) .direction(Direction::Horizontal) .split(draw_loc); // Draw! - Table::new(DISK_HEADERS.iter(), disk_rows) - .block(disk_block) - .header_style(self.colours.table_header_style) - .widths( - &(intrinsic_widths - .iter() - .map(|calculated_width| Constraint::Length(*calculated_width as u16)) - .collect::>()), - ) - .render(f, margined_draw_loc[0]); + f.render_stateful_widget( + Table::new(DISK_HEADERS.iter(), disk_rows) + .block(disk_block) + .header_style(self.colours.table_header_style) + .highlight_style(highlight_style) + .style(self.colours.text_style) + .widths( + &(intrinsic_widths + .iter() + .map(|calculated_width| Constraint::Length(*calculated_width as u16)) + .collect::>()), + ) + .header_gap(app_state.app_config_fields.table_gap), + margined_draw_loc[0], + disk_table_state, + ); } } } diff --git a/src/canvas/widgets/mem_basic.rs b/src/canvas/widgets/mem_basic.rs index 75ffcacf..132fd91d 100644 --- a/src/canvas/widgets/mem_basic.rs +++ b/src/canvas/widgets/mem_basic.rs @@ -10,7 +10,7 @@ use tui::{ backend::Backend, layout::{Constraint, Layout, Rect}, terminal::Frame, - widgets::{Block, Paragraph, Text, Widget}, + widgets::{Block, Paragraph, Text}, }; pub trait MemBasicWidget { @@ -32,10 +32,12 @@ impl MemBasicWidget for Painter { .split(draw_loc); if app_state.current_widget.widget_id == widget_id { - Block::default() - .borders(*SIDE_BORDERS) - .border_style(self.colours.highlighted_border_style) - .render(f, draw_loc); + f.render_widget( + Block::default() + .borders(*SIDE_BORDERS) + .border_style(self.colours.highlighted_border_style), + draw_loc, + ); } // +9 due to 3 + 4 + 2 + 2 columns for the name & space + percentage + bar bounds + margin spacing @@ -70,8 +72,9 @@ impl MemBasicWidget for Painter { Text::Styled(swap_label.into(), self.colours.swap_style), ]; - Paragraph::new(mem_text.iter()) - .block(Block::default()) - .render(f, margined_loc[0]); + f.render_widget( + Paragraph::new(mem_text.iter()).block(Block::default()), + margined_loc[0], + ); } } diff --git a/src/canvas/widgets/mem_graph.rs b/src/canvas/widgets/mem_graph.rs index db9eee0d..a15f01bc 100644 --- a/src/canvas/widgets/mem_graph.rs +++ b/src/canvas/widgets/mem_graph.rs @@ -4,9 +4,10 @@ use crate::{app::App, canvas::Painter, constants::*}; use tui::{ backend::Backend, - layout::Rect, + layout::{Constraint, Rect}, + symbols::Marker, terminal::Frame, - widgets::{Axis, Block, Borders, Chart, Dataset, Marker, Widget}, + widgets::{Axis, Block, Borders, Chart, Dataset}, }; pub trait MemGraphWidget { @@ -60,26 +61,37 @@ impl MemGraphWidget for Painter { .bounds([-0.5, 100.5]) .labels(&["0%", "100%"]); - let mem_canvas_vec: Vec> = vec![ - Dataset::default() - .name(&app_state.canvas_data.mem_label) - .marker(if app_state.app_config_fields.use_dot { - Marker::Dot - } else { - Marker::Braille - }) - .style(self.colours.ram_style) - .data(&mem_data), - Dataset::default() - .name(&app_state.canvas_data.swap_label) - .marker(if app_state.app_config_fields.use_dot { - Marker::Dot - } else { - Marker::Braille - }) - .style(self.colours.swap_style) - .data(&swap_data), - ]; + let mut mem_canvas_vec: Vec> = vec![]; + + if !mem_data.is_empty() { + mem_canvas_vec.push( + Dataset::default() + .name(&app_state.canvas_data.mem_label) + .marker(if app_state.app_config_fields.use_dot { + Marker::Dot + } else { + Marker::Braille + }) + .style(self.colours.ram_style) + .data(&mem_data) + .graph_type(tui::widgets::GraphType::Line), + ); + } + + if !swap_data.is_empty() { + mem_canvas_vec.push( + Dataset::default() + .name(&app_state.canvas_data.swap_label) + .marker(if app_state.app_config_fields.use_dot { + Marker::Dot + } else { + Marker::Braille + }) + .style(self.colours.swap_style) + .data(&swap_data) + .graph_type(tui::widgets::GraphType::Line), + ); + } let title = if app_state.is_expanded { const TITLE_BASE: &str = " Memory ── Esc to go back "; @@ -97,26 +109,29 @@ impl MemGraphWidget for Painter { " Memory ".to_string() }; - Chart::default() - .block( - Block::default() - .title(&title) - .title_style(if app_state.is_expanded { - self.colours.highlighted_border_style - } else { - self.colours.widget_title_style - }) - .borders(Borders::ALL) - .border_style(if app_state.current_widget.widget_id == widget_id { - self.colours.highlighted_border_style - } else { - self.colours.border_style - }), - ) - .x_axis(x_axis) - .y_axis(y_axis) - .datasets(&mem_canvas_vec) - .render(f, draw_loc); + f.render_widget( + Chart::default() + .block( + Block::default() + .title(&title) + .title_style(if app_state.is_expanded { + self.colours.highlighted_border_style + } else { + self.colours.widget_title_style + }) + .borders(Borders::ALL) + .border_style(if app_state.current_widget.widget_id == widget_id { + self.colours.highlighted_border_style + } else { + self.colours.border_style + }), + ) + .x_axis(x_axis) + .y_axis(y_axis) + .datasets(&mem_canvas_vec) + .hidden_legend_constraints((Constraint::Ratio(3, 4), Constraint::Ratio(3, 4))), + draw_loc, + ); } } } diff --git a/src/canvas/widgets/network_basic.rs b/src/canvas/widgets/network_basic.rs index 59432890..30c4e189 100644 --- a/src/canvas/widgets/network_basic.rs +++ b/src/canvas/widgets/network_basic.rs @@ -4,7 +4,7 @@ use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, terminal::Frame, - widgets::{Block, Paragraph, Text, Widget}, + widgets::{Block, Paragraph, Text}, }; pub trait NetworkBasicWidget { @@ -35,10 +35,12 @@ impl NetworkBasicWidget for Painter { .split(divided_loc[1]); if app_state.current_widget.widget_id == widget_id { - Block::default() - .borders(*SIDE_BORDERS) - .border_style(self.colours.highlighted_border_style) - .render(f, draw_loc); + f.render_widget( + Block::default() + .borders(*SIDE_BORDERS) + .border_style(self.colours.highlighted_border_style), + draw_loc, + ); } let rx_label = format!("RX: {}\n", &app_state.canvas_data.rx_display); @@ -56,12 +58,14 @@ impl NetworkBasicWidget for Painter { Text::Styled(total_tx_label.into(), self.colours.total_tx_style), ]; - Paragraph::new(net_text.iter()) - .block(Block::default()) - .render(f, net_loc[0]); + f.render_widget( + Paragraph::new(net_text.iter()).block(Block::default()), + net_loc[0], + ); - Paragraph::new(total_net_text.iter()) - .block(Block::default()) - .render(f, total_loc[0]); + f.render_widget( + Paragraph::new(total_net_text.iter()).block(Block::default()), + total_loc[0], + ); } } diff --git a/src/canvas/widgets/network_graph.rs b/src/canvas/widgets/network_graph.rs index b21e886e..d2d49c90 100644 --- a/src/canvas/widgets/network_graph.rs +++ b/src/canvas/widgets/network_graph.rs @@ -10,8 +10,9 @@ use crate::{ use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, + symbols::Marker, terminal::Frame, - widgets::{Axis, Block, Borders, Chart, Dataset, Marker, Row, Table, Widget}, + widgets::{Axis, Block, Borders, Chart, Dataset, Row, Table}, }; const NETWORK_HEADERS: [&str; 4] = ["RX", "TX", "Total RX", "Total TX"]; @@ -30,6 +31,7 @@ pub trait NetworkGraphWidget { fn draw_network_graph( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, + hide_legend: bool, ); fn draw_network_labels( @@ -41,24 +43,29 @@ impl NetworkGraphWidget for Painter { fn draw_network( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, ) { - let network_chunk = Layout::default() - .direction(Direction::Vertical) - .margin(0) - .constraints( - [ - Constraint::Length(max(draw_loc.height as i64 - 5, 0) as u16), - Constraint::Length(5), - ] - .as_ref(), - ) - .split(draw_loc); + if app_state.app_config_fields.use_old_network_legend { + let network_chunk = Layout::default() + .direction(Direction::Vertical) + .margin(0) + .constraints( + [ + Constraint::Length(max(draw_loc.height as i64 - 5, 0) as u16), + Constraint::Length(5), + ] + .as_ref(), + ) + .split(draw_loc); - self.draw_network_graph(f, app_state, network_chunk[0], widget_id); - self.draw_network_labels(f, app_state, network_chunk[1], widget_id); + self.draw_network_graph(f, app_state, network_chunk[0], widget_id, true); + self.draw_network_labels(f, app_state, network_chunk[1], widget_id); + } else { + self.draw_network_graph(f, app_state, draw_loc, widget_id, false); + } } fn draw_network_graph( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, + hide_legend: bool, ) { if let Some(network_widget_state) = app_state.net_state.widget_states.get_mut(&widget_id) { let network_data_rx: &[(f64, f64)] = &app_state.canvas_data.network_data_rx; @@ -118,57 +125,122 @@ impl NetworkGraphWidget for Painter { " Network ".to_string() }; - Chart::default() - .block( - Block::default() - .title(&title) - .title_style(if app_state.is_expanded { - self.colours.highlighted_border_style - } else { - self.colours.widget_title_style - }) - .borders(Borders::ALL) - .border_style(if app_state.current_widget.widget_id == widget_id { - self.colours.highlighted_border_style - } else { - self.colours.border_style - }), - ) - .x_axis(x_axis) - .y_axis(y_axis) - .datasets(&[ + let legend_constraints = if hide_legend { + (Constraint::Ratio(0, 1), Constraint::Ratio(0, 1)) + } else { + (Constraint::Ratio(3, 4), Constraint::Ratio(3, 4)) + }; + + let dataset = if app_state.app_config_fields.use_old_network_legend && !hide_legend { + let mut ret_val = vec![]; + + if !network_data_rx.is_empty() { + ret_val.push( + Dataset::default() + .name(format!("RX: {:7}", app_state.canvas_data.rx_display)) + .marker(if app_state.app_config_fields.use_dot { + Marker::Dot + } else { + Marker::Braille + }) + .style(self.colours.rx_style) + .data(&network_data_rx) + .graph_type(tui::widgets::GraphType::Line), + ); + } + + if !network_data_tx.is_empty() { + ret_val.push( + Dataset::default() + .name(format!("TX: {:7}", app_state.canvas_data.tx_display)) + .marker(if app_state.app_config_fields.use_dot { + Marker::Dot + } else { + Marker::Braille + }) + .style(self.colours.tx_style) + .data(&network_data_tx) + .graph_type(tui::widgets::GraphType::Line), + ); + ret_val.push( + Dataset::default() + .name(format!( + "Total RX: {:7}", + app_state.canvas_data.total_rx_display + )) + .style(self.colours.total_rx_style), + ); + } + + ret_val.push( Dataset::default() - .name(&format!("RX: {:7}", app_state.canvas_data.rx_display)) - .marker(if app_state.app_config_fields.use_dot { - Marker::Dot - } else { - Marker::Braille - }) - .style(self.colours.rx_style) - .data(&network_data_rx), - Dataset::default() - .name(&format!("TX: {:7}", app_state.canvas_data.tx_display)) - .marker(if app_state.app_config_fields.use_dot { - Marker::Dot - } else { - Marker::Braille - }) - .style(self.colours.tx_style) - .data(&network_data_tx), - Dataset::default() - .name(&format!( - "Total RX: {:7}", - app_state.canvas_data.total_rx_display - )) - .style(self.colours.total_rx_style), - Dataset::default() - .name(&format!( + .name(format!( "Total TX: {:7}", app_state.canvas_data.total_tx_display )) .style(self.colours.total_tx_style), - ]) - .render(f, draw_loc); + ); + + ret_val + } else { + let mut ret_val = vec![]; + + if !network_data_rx.is_empty() { + ret_val.push( + Dataset::default() + .name(&app_state.canvas_data.rx_display) + .marker(if app_state.app_config_fields.use_dot { + Marker::Dot + } else { + Marker::Braille + }) + .style(self.colours.rx_style) + .data(&network_data_rx) + .graph_type(tui::widgets::GraphType::Line), + ); + } + + if !network_data_tx.is_empty() { + ret_val.push( + Dataset::default() + .name(&app_state.canvas_data.tx_display) + .marker(if app_state.app_config_fields.use_dot { + Marker::Dot + } else { + Marker::Braille + }) + .style(self.colours.tx_style) + .data(&network_data_tx) + .graph_type(tui::widgets::GraphType::Line), + ); + } + + ret_val + }; + + f.render_widget( + Chart::default() + .block( + Block::default() + .title(&title) + .title_style(if app_state.is_expanded { + self.colours.highlighted_border_style + } else { + self.colours.widget_title_style + }) + .borders(Borders::ALL) + .border_style(if app_state.current_widget.widget_id == widget_id { + self.colours.highlighted_border_style + } else { + self.colours.border_style + }), + ) + .x_axis(x_axis) + .y_axis(y_axis) + .datasets(&dataset) + .hidden_legend_constraints(legend_constraints), + draw_loc, + ); } } @@ -201,22 +273,24 @@ impl NetworkGraphWidget for Painter { let intrinsic_widths = &(variable_intrinsic_results.0)[0..variable_intrinsic_results.1]; // Draw - Table::new(NETWORK_HEADERS.iter(), mapped_network) - .block(Block::default().borders(Borders::ALL).border_style( - if app_state.current_widget.widget_id == widget_id { - self.colours.highlighted_border_style - } else { - self.colours.border_style - }, - )) - .header_style(self.colours.table_header_style) - .style(self.colours.text_style) - .widths( - &(intrinsic_widths - .iter() - .map(|calculated_width| Constraint::Length(*calculated_width as u16)) - .collect::>()), - ) - .render(f, draw_loc); + f.render_widget( + Table::new(NETWORK_HEADERS.iter(), mapped_network) + .block(Block::default().borders(Borders::ALL).border_style( + if app_state.current_widget.widget_id == widget_id { + self.colours.highlighted_border_style + } else { + self.colours.border_style + }, + )) + .header_style(self.colours.table_header_style) + .style(self.colours.text_style) + .widths( + &(intrinsic_widths + .iter() + .map(|calculated_width| Constraint::Length(*calculated_width as u16)) + .collect::>()), + ), + draw_loc, + ); } } diff --git a/src/canvas/widgets/process_table.rs b/src/canvas/widgets/process_table.rs index bde4fe9b..0733b500 100644 --- a/src/canvas/widgets/process_table.rs +++ b/src/canvas/widgets/process_table.rs @@ -15,7 +15,7 @@ use tui::{ backend::Backend, layout::{Alignment, Constraint, Direction, Layout, Rect}, terminal::Frame, - widgets::{Block, Borders, Paragraph, Row, Table, Text, Widget}, + widgets::{Block, Borders, Paragraph, Row, Table, Text}, }; use unicode_segmentation::{GraphemeIndices, UnicodeSegmentation}; @@ -83,7 +83,7 @@ impl ProcessTableWidget for Painter { // hit the process we've currently scrolled to. // We also need to move the list - we can // do so by hiding some elements! - let num_rows = max(0, i64::from(draw_loc.height) - 5) as u64; + let num_rows = max(0, i64::from(draw_loc.height) - self.table_height_offset) as u64; let is_on_widget = widget_id == app_state.current_widget.widget_id; let position = get_start_position( @@ -102,43 +102,32 @@ impl ProcessTableWidget for Painter { }; let sliced_vec = &process_data[start_position as usize..]; - let mut process_counter: i64 = 0; + let proc_table_state = &mut proc_widget_state.scroll_state.table_state; + proc_table_state.select(Some( + (proc_widget_state.scroll_state.current_scroll_position - start_position) + as usize, + )); // Draw! + let is_proc_widget_grouped = proc_widget_state.is_grouped; let process_rows = sliced_vec.iter().map(|process| { - let stringified_process_vec: Vec = vec![ - if proc_widget_state.is_grouped { - process.group_pids.len().to_string() - } else { - process.pid.to_string() - }, - process.name.clone(), - format!("{:.1}%", process.cpu_usage), - format!("{:.1}%", process.mem_usage), - process.read_per_sec.to_string(), - process.write_per_sec.to_string(), - process.total_read.to_string(), - process.total_write.to_string(), - process.process_states.to_string(), - ]; - Row::StyledData( - stringified_process_vec.into_iter(), - if is_on_widget { - if process_counter as u64 - == proc_widget_state.scroll_state.current_scroll_position - - start_position - { - process_counter = -1; - self.colours.currently_selected_text_style + Row::Data( + vec![ + if is_proc_widget_grouped { + process.group_pids.len().to_string() } else { - if process_counter >= 0 { - process_counter += 1; - } - self.colours.text_style - } - } else { - self.colours.text_style - }, + process.pid.to_string() + }, + process.name.clone(), + format!("{:.1}%", process.cpu_usage), + format!("{:.1}%", process.mem_usage), + process.read_per_sec.to_string(), + process.write_per_sec.to_string(), + process.total_read.to_string(), + process.total_write.to_string(), + process.process_states.to_string(), + ] + .into_iter(), ) }); @@ -223,10 +212,13 @@ impl ProcessTableWidget for Painter { String::default() }; - let border_and_title_style = if is_on_widget { - self.colours.highlighted_border_style + let (border_and_title_style, highlight_style) = if is_on_widget { + ( + self.colours.highlighted_border_style, + self.colours.currently_selected_text_style, + ) } else { - self.colours.border_style + (self.colours.border_style, self.colours.text_style) }; let process_block = if draw_border { @@ -253,16 +245,24 @@ impl ProcessTableWidget for Painter { .direction(Direction::Horizontal) .split(draw_loc); - Table::new(process_headers.iter(), process_rows) - .block(process_block) - .header_style(self.colours.table_header_style) - .widths( - &(intrinsic_widths - .iter() - .map(|calculated_width| Constraint::Length(*calculated_width as u16)) - .collect::>()), - ) - .render(f, margined_draw_loc[0]); + f.render_stateful_widget( + Table::new(process_headers.iter(), process_rows) + .block(process_block) + .header_style(self.colours.table_header_style) + .highlight_style(highlight_style) + .style(self.colours.text_style) + .widths( + &(intrinsic_widths + .iter() + .map(|calculated_width| { + Constraint::Length(*calculated_width as u16) + }) + .collect::>()), + ) + .header_gap(app_state.app_config_fields.table_gap), + margined_draw_loc[0], + proc_table_state, + ); } } } @@ -490,12 +490,14 @@ impl ProcessTableWidget for Painter { .direction(Direction::Horizontal) .split(draw_loc); - Paragraph::new(search_text.iter()) - .block(process_search_block) - .style(self.colours.text_style) - .alignment(Alignment::Left) - .wrap(false) - .render(f, margined_draw_loc[0]); + f.render_widget( + Paragraph::new(search_text.iter()) + .block(process_search_block) + .style(self.colours.text_style) + .alignment(Alignment::Left) + .wrap(false), + margined_draw_loc[0], + ); } } } diff --git a/src/canvas/widgets/temp_table.rs b/src/canvas/widgets/temp_table.rs index f34c23c8..007d93b0 100644 --- a/src/canvas/widgets/temp_table.rs +++ b/src/canvas/widgets/temp_table.rs @@ -5,7 +5,7 @@ use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, terminal::Frame, - widgets::{Block, Borders, Row, Table, Widget}, + widgets::{Block, Borders, Row, Table}, }; use crate::{ @@ -40,7 +40,7 @@ impl TempTableWidget for Painter { if let Some(temp_widget_state) = app_state.temp_state.widget_states.get_mut(&widget_id) { let temp_sensor_data: &mut [Vec] = &mut app_state.canvas_data.temp_sensor_data; - let num_rows = max(0, i64::from(draw_loc.height) - 5) as u64; + let num_rows = max(0, i64::from(draw_loc.height) - self.table_height_offset) as u64; let start_position = get_start_position( num_rows, &temp_widget_state.scroll_state.scroll_direction, @@ -48,32 +48,14 @@ impl TempTableWidget for Painter { temp_widget_state.scroll_state.current_scroll_position, app_state.is_resized, ); + let is_on_widget = widget_id == app_state.current_widget.widget_id; + let temp_table_state = &mut temp_widget_state.scroll_state.table_state; + temp_table_state.select(Some( + (temp_widget_state.scroll_state.current_scroll_position - start_position) as usize, + )); let sliced_vec = &temp_sensor_data[start_position as usize..]; - let mut temp_row_counter: i64 = 0; - let current_widget_id = app_state.current_widget.widget_id; - - let temperature_rows = sliced_vec.iter().map(|temp_row| { - Row::StyledData( - temp_row.iter(), - if current_widget_id == widget_id { - if temp_row_counter as u64 - == temp_widget_state.scroll_state.current_scroll_position - - start_position - { - temp_row_counter = -1; - self.colours.currently_selected_text_style - } else { - if temp_row_counter >= 0 { - temp_row_counter += 1; - } - self.colours.text_style - } - } else { - self.colours.text_style - }, - ) - }); + let temperature_rows = sliced_vec.iter().map(|temp_row| Row::Data(temp_row.iter())); // Calculate widths let width = f64::from(draw_loc.width); @@ -100,25 +82,22 @@ impl TempTableWidget for Painter { " Temperatures ".to_string() }; + let (border_and_title_style, highlight_style) = if is_on_widget { + ( + self.colours.highlighted_border_style, + self.colours.currently_selected_text_style, + ) + } else { + (self.colours.border_style, self.colours.text_style) + }; + let temp_block = if draw_border { Block::default() .title(&title) - .title_style(if app_state.is_expanded { - if app_state.current_widget.widget_id == widget_id { - self.colours.highlighted_border_style - } else { - self.colours.border_style - } - } else { - self.colours.widget_title_style - }) + .title_style(border_and_title_style) .borders(Borders::ALL) - .border_style(if app_state.current_widget.widget_id == widget_id { - self.colours.highlighted_border_style - } else { - self.colours.border_style - }) - } else if app_state.current_widget.widget_id == widget_id { + .border_style(border_and_title_style) + } else if is_on_widget { Block::default() .borders(*SIDE_BORDERS) .border_style(self.colours.highlighted_border_style) @@ -128,27 +107,27 @@ impl TempTableWidget for Painter { let margined_draw_loc = Layout::default() .constraints([Constraint::Percentage(100)].as_ref()) - .horizontal_margin( - if app_state.current_widget.widget_id == widget_id || draw_border { - 0 - } else { - 1 - }, - ) + .horizontal_margin(if is_on_widget || draw_border { 0 } else { 1 }) .direction(Direction::Horizontal) .split(draw_loc); // Draw - Table::new(TEMP_HEADERS.iter(), temperature_rows) - .block(temp_block) - .header_style(self.colours.table_header_style) - .widths( - &(intrinsic_widths - .iter() - .map(|calculated_width| Constraint::Length(*calculated_width as u16)) - .collect::>()), - ) - .render(f, margined_draw_loc[0]); + f.render_stateful_widget( + Table::new(TEMP_HEADERS.iter(), temperature_rows) + .block(temp_block) + .header_style(self.colours.table_header_style) + .highlight_style(highlight_style) + .style(self.colours.text_style) + .widths( + &(intrinsic_widths + .iter() + .map(|calculated_width| Constraint::Length(*calculated_width as u16)) + .collect::>()), + ) + .header_gap(app_state.app_config_fields.table_gap), + margined_draw_loc[0], + temp_table_state, + ); } } } diff --git a/src/constants.rs b/src/constants.rs index 1fc0e972..7c019c22 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -150,6 +150,12 @@ pub const DEFAULT_CONFIG_CONTENT: &str = r##" # Use basic mode #basic = false +# Use the old network legend style +#use_old_network_legend = false + +# Remove space in tables +#hide_table_gap = false + ########################################################## # These are all the components that support custom theming. Note that colour support @@ -158,7 +164,7 @@ pub const DEFAULT_CONFIG_CONTENT: &str = r##" [colors] # Represents the colour of table headers (processes, CPU, disks, temperature). -#table_header_color="Cyan" +#table_header_color="Light Blue" # Represents the colour of the label each widget has. #widget_title_color="Gray" @@ -185,7 +191,7 @@ pub const DEFAULT_CONFIG_CONTENT: &str = r##" #border_color="Gray" # Represents the colour of the border of selected widgets. -#highlighted_border_color="Cyan" +#highlighted_border_color="Light Blue" # Represents the colour of most text. #text_color="Gray" @@ -194,7 +200,7 @@ pub const DEFAULT_CONFIG_CONTENT: &str = r##" #selected_text_color="Black" # Represents the background colour of text that is selected. -#selected_bg_color="Cyan" +#selected_bg_color="Light Blue" # Represents the colour of the lines and text of the graph. #graph_color="Gray" diff --git a/src/data_conversion.rs b/src/data_conversion.rs index 16014608..259a4e74 100644 --- a/src/data_conversion.rs +++ b/src/data_conversion.rs @@ -29,8 +29,8 @@ pub struct ConvertedNetworkData { pub tx: Vec, pub rx_display: String, pub tx_display: String, - pub total_rx_display: String, - pub total_tx_display: String, + pub total_rx_display: Option, + pub total_tx_display: Option, } #[derive(Clone, Default, Debug)] @@ -160,15 +160,8 @@ pub fn convert_cpu_data_points( } if let Some(cpu_data) = cpu_data_vector.get_mut(itx) { - cpu_data.legend_value = format!("{:.0}%", cpu.0.round()); - - //Insert joiner points - for &(joiner_offset, joiner_val) in &cpu.1 { - let offset_time = time_from_start + joiner_offset as f64; - cpu_data.cpu_data.push((-offset_time, joiner_val)); - } - - cpu_data.cpu_data.push((-time_from_start, cpu.0)); + cpu_data.legend_value = format!("{:.0}%", cpu.round()); + cpu_data.cpu_data.push((-time_from_start, *cpu)); } } @@ -197,13 +190,7 @@ pub fn convert_mem_data_points( for (time, data) in ¤t_data.timed_data_vec { let time_from_start: f64 = (current_time.duration_since(*time).as_millis() as f64).floor(); - //Insert joiner points - for &(joiner_offset, joiner_val) in &data.mem_data.1 { - let offset_time = time_from_start + joiner_offset as f64; - result.push((-offset_time, joiner_val)); - } - - result.push((-time_from_start, data.mem_data.0)); + result.push((-time_from_start, data.mem_data)); if *time == current_time { break; @@ -229,14 +216,7 @@ pub fn convert_swap_data_points( for (time, data) in ¤t_data.timed_data_vec { let time_from_start: f64 = (current_time.duration_since(*time).as_millis() as f64).floor(); - - //Insert joiner points - for &(joiner_offset, joiner_val) in &data.swap_data.1 { - let offset_time = time_from_start + joiner_offset as f64; - result.push((-offset_time, joiner_val)); - } - - result.push((-time_from_start, data.swap_data.0)); + result.push((-time_from_start, data.swap_data)); if *time == current_time { break; @@ -300,20 +280,8 @@ pub fn get_rx_tx_data_points( for (time, data) in ¤t_data.timed_data_vec { let time_from_start: f64 = (current_time.duration_since(*time).as_millis() as f64).floor(); - - //Insert joiner points - for &(joiner_offset, joiner_val) in &data.rx_data.1 { - let offset_time = time_from_start + joiner_offset as f64; - rx.push((-offset_time, joiner_val)); - } - - for &(joiner_offset, joiner_val) in &data.tx_data.1 { - let offset_time = time_from_start + joiner_offset as f64; - tx.push((-offset_time, joiner_val)); - } - - rx.push((-time_from_start, data.rx_data.0)); - tx.push((-time_from_start, data.tx_data.0)); + rx.push((-time_from_start, data.rx_data)); + tx.push((-time_from_start, data.tx_data)); if *time == current_time { break; @@ -324,7 +292,7 @@ pub fn get_rx_tx_data_points( } pub fn convert_network_data_points( - current_data: &data_farmer::DataCollection, is_frozen: bool, + current_data: &data_farmer::DataCollection, is_frozen: bool, need_four_points: bool, ) -> ConvertedNetworkData { let (rx, tx) = get_rx_tx_data_points(current_data, is_frozen); @@ -335,27 +303,55 @@ pub fn convert_network_data_points( rx_converted_result = get_exact_byte_values(current_data.network_harvest.rx, false); total_rx_converted_result = get_exact_byte_values(current_data.network_harvest.total_rx, false); - let rx_display = format!("{:.*}{}", 1, rx_converted_result.0, rx_converted_result.1); - let total_rx_display = format!( - "{:.*}{}", - 1, total_rx_converted_result.0, total_rx_converted_result.1 - ); tx_converted_result = get_exact_byte_values(current_data.network_harvest.tx, false); total_tx_converted_result = get_exact_byte_values(current_data.network_harvest.total_tx, false); - let tx_display = format!("{:.*}{}", 1, tx_converted_result.0, tx_converted_result.1); - let total_tx_display = format!( - "{:.*}{}", - 1, total_tx_converted_result.0, total_tx_converted_result.1 - ); - ConvertedNetworkData { - rx, - tx, - rx_display, - tx_display, - total_rx_display, - total_tx_display, + if need_four_points { + let rx_display = format!("{:.*}{}", 1, rx_converted_result.0, rx_converted_result.1); + let total_rx_display = Some(format!( + "{:.*}{}", + 1, total_rx_converted_result.0, total_rx_converted_result.1 + )); + let tx_display = format!("{:.*}{}", 1, tx_converted_result.0, tx_converted_result.1); + let total_tx_display = Some(format!( + "{:.*}{}", + 1, total_tx_converted_result.0, total_tx_converted_result.1 + )); + ConvertedNetworkData { + rx, + tx, + rx_display, + tx_display, + total_rx_display, + total_tx_display, + } + } else { + let rx_display = format!( + "RX: {:<9} All: {:<9}", + format!("{:.1}{:3}", rx_converted_result.0, rx_converted_result.1), + format!( + "{:.1}{:3}", + total_rx_converted_result.0, total_rx_converted_result.1 + ) + ); + let tx_display = format!( + "TX: {:<9} All: {:<9}", + format!("{:.1}{:3}", tx_converted_result.0, tx_converted_result.1), + format!( + "{:.1}{:3}", + total_tx_converted_result.0, total_tx_converted_result.1 + ) + ); + + ConvertedNetworkData { + rx, + tx, + rx_display, + tx_display, + total_rx_display: None, + total_tx_display: None, + } } } diff --git a/src/main.rs b/src/main.rs index db2ca467..42df73ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,6 +89,8 @@ fn get_matches() -> clap::ArgMatches<'static> { (@arg AUTOHIDE_TIME: --autohide_time "Automatically hide the time scaling in graphs after being shown for a brief moment when zoomed in/out. If time is disabled via --hide_time then this will have no effect.") (@arg DEFAULT_WIDGET_TYPE: --default_widget_type +takes_value "The default widget type to select by default.") (@arg DEFAULT_WIDGET_COUNT: --default_widget_count +takes_value "Which number of the selected widget type to select, from left to right, top to bottom. Defaults to 1.") + (@arg USE_OLD_NETWORK_LEGEND: --use_old_network_legend "Use the older (pre-0.4) network widget legend.") + (@arg HIDE_TABLE_GAP: --hide_table_gap "Hides the spacing between the table headers and entries.") //(@arg TURNED_OFF_CPUS: -t ... +takes_value "Hides CPU data points by default") // TODO: [FEATURE] Enable disabling cores in config/flags ) .get_matches() @@ -143,7 +145,7 @@ fn main() -> error::Result<()> { app.used_widgets.clone(), ); - let mut painter = canvas::Painter::init(widget_layout); + let mut painter = canvas::Painter::init(widget_layout, app.app_config_fields.table_gap); if let Err(config_check) = generate_config_colours(&config, &mut painter) { cleanup_terminal(&mut terminal)?; return Err(config_check); @@ -173,14 +175,22 @@ fn main() -> error::Result<()> { // Network if app.used_widgets.use_net { - let network_data = - convert_network_data_points(&app.data_collection, false); + let network_data = convert_network_data_points( + &app.data_collection, + false, + app.app_config_fields.use_basic_mode + || app.app_config_fields.use_old_network_legend, + ); app.canvas_data.network_data_rx = network_data.rx; app.canvas_data.network_data_tx = network_data.tx; app.canvas_data.rx_display = network_data.rx_display; app.canvas_data.tx_display = network_data.tx_display; - app.canvas_data.total_rx_display = network_data.total_rx_display; - app.canvas_data.total_tx_display = network_data.total_tx_display; + if let Some(total_rx_display) = network_data.total_rx_display { + app.canvas_data.total_rx_display = total_rx_display; + } + if let Some(total_tx_display) = network_data.total_tx_display { + app.canvas_data.total_tx_display = total_tx_display; + } } // Disk @@ -462,13 +472,13 @@ fn generate_config_colours(config: &Config, painter: &mut canvas::Painter) -> er painter.colours.set_tx_colour(tx_color)?; } - if let Some(rx_total_color) = &colours.rx_total_color { - painter.colours.set_rx_total_colour(rx_total_color)?; - } + // if let Some(rx_total_color) = &colours.rx_total_color { + // painter.colours.set_rx_total_colour(rx_total_color)?; + // } - if let Some(tx_total_color) = &colours.tx_total_color { - painter.colours.set_tx_total_colour(tx_total_color)?; - } + // if let Some(tx_total_color) = &colours.tx_total_color { + // painter.colours.set_tx_total_colour(tx_total_color)?; + // } if let Some(table_header_color) = &colours.table_header_color { painter diff --git a/src/options.rs b/src/options.rs index 987d6f0e..f2fa00e3 100644 --- a/src/options.rs +++ b/src/options.rs @@ -40,6 +40,8 @@ pub struct ConfigFlags { pub hide_time: Option, pub default_widget_type: Option, pub default_widget_count: Option, + pub use_old_network_legend: Option, + pub hide_table_gap : Option, //disabled_cpu_cores: Option>, // TODO: [FEATURE] Enable disabling cores in config/flags } @@ -216,6 +218,8 @@ pub fn build_app( time_interval: get_time_interval(matches, config)?, hide_time: get_hide_time(matches, config), autohide_time, + use_old_network_legend: get_use_old_network_legend(matches, config), + table_gap: if get_hide_table_gap(matches, config){0}else{1}, }; let used_widgets = UsedWidgets { @@ -603,3 +607,30 @@ fn get_default_widget_and_count( Ok((None, 1)) } } + +pub fn get_use_old_network_legend(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { + if matches.is_present("USE_OLD_NETWORK_LEGEND") { + return true; + } else if let Some(flags) = &config.flags { + if let Some(use_old_network_legend) = flags.use_old_network_legend { + if use_old_network_legend { + return true; + } + } + } + false +} + +pub fn get_hide_table_gap(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { + if matches.is_present("HIDE_TABLE_GAP") { + return true; + } else if let Some(flags) = &config.flags { + if let Some(hide_table_gap) = flags.hide_table_gap { + if hide_table_gap { + return true; + } + } + } + false +} +