summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2020-11-20 00:13:46 -0500
committerGitHub <noreply@github.com>2020-11-20 00:13:46 -0500
commit2ff8b418b2da57dbe7f2662b37023fc0c70bc6fd (patch)
treec6168c242b254a7931986596271087869d203a93
parent5fedf8a5db3fcc21656e653674bc5aed8d66fde3 (diff)
feature: add tree flag (#312)
Adds a --tree flag that defaults to tree mode for the process widget.
-rw-r--r--CHANGELOG.md2
-rw-r--r--README.md4
-rw-r--r--src/app/states.rs13
-rw-r--r--src/canvas/screens/config_screen.rs2
-rw-r--r--src/clap.rs13
-rw-r--r--src/constants.rs4
-rw-r--r--src/options.rs16
7 files changed, 46 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 58bf448e..727b85e9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,7 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#220](https://github.com/ClementTsang/bottom/pull/220): Add ability to hide specific temperature and disk entries via config.
-- [#223](https://github.com/ClementTsang/bottom/pull/223): Add tree mode for processes.
+- [#223](https://github.com/ClementTsang/bottom/pull/223): Add tree mode for processes. [#312](https://github.com/ClementTsang/bottom/pull/312) also adds a `tree` flag to default to the tree mode.
- [#269](https://github.com/ClementTsang/bottom/pull/269): Add simple indicator for when data updating is frozen.
diff --git a/README.md b/README.md
index 33a95715..69307022 100644
--- a/README.md
+++ b/README.md
@@ -210,6 +210,8 @@ Run using `btm`.
### Flags
+Use `btm --help` for more information.
+
```
--autohide_time Temporarily shows the time scale in graphs.
-b, --basic Hides graphs and uses a more basic look.
@@ -237,6 +239,7 @@ Run using `btm`.
-r, --rate <MS> Sets a refresh rate in ms.
-R, --regex Enables regex by default.
-d, --time_delta <MS> The amount in ms changed upon zooming.
+ -T, --tree Defaults to showing the process widget in tree mode.
--use_old_network_legend DEPRECATED - uses the older network legend.
-V, --version Prints version information.
-W, --whole_word Enables whole-word matching by default.
@@ -549,6 +552,7 @@ These are the following supported flag config values, which correspond to the fl
| `disable_click` | Boolean |
| `color` | String (one of ["default", "default-light", "gruvbox", "gruvbox-light"]) |
| `mem_as_value` | Boolean |
+| `tree` | Boolean |
#### Theming
diff --git a/src/app/states.rs b/src/app/states.rs
index f087b95a..fadb7bcf 100644
--- a/src/app/states.rs
+++ b/src/app/states.rs
@@ -391,9 +391,10 @@ pub struct ProcWidgetState {
impl ProcWidgetState {
pub fn init(
is_case_sensitive: bool, is_match_whole_word: bool, is_use_regex: bool, is_grouped: bool,
- show_memory_as_values: bool,
+ show_memory_as_values: bool, is_tree_mode: bool,
) -> Self {
let mut process_search_state = ProcessSearchState::default();
+
if is_case_sensitive {
// By default it's off
process_search_state.search_toggle_ignore_case();
@@ -405,7 +406,11 @@ impl ProcWidgetState {
process_search_state.search_toggle_regex();
}
- let process_sorting_type = processes::ProcessSorting::CpuPercent;
+ let (process_sorting_type, is_process_sort_descending) = if is_tree_mode {
+ (processes::ProcessSorting::Pid, false)
+ } else {
+ (processes::ProcessSorting::CpuPercent, true)
+ };
// TODO: If we add customizable columns, this should pull from config
let mut columns = ProcColumn::default();
@@ -426,12 +431,12 @@ impl ProcWidgetState {
is_grouped,
scroll_state: AppScrollWidgetState::default(),
process_sorting_type,
- is_process_sort_descending: true,
+ is_process_sort_descending,
is_using_command: false,
current_column_index: 0,
is_sort_open: false,
columns,
- is_tree_mode: false,
+ is_tree_mode,
table_width_state: CanvasTableWidthState::default(),
requires_redraw: false,
}
diff --git a/src/canvas/screens/config_screen.rs b/src/canvas/screens/config_screen.rs
index 741a9fa6..b51a0b73 100644
--- a/src/canvas/screens/config_screen.rs
+++ b/src/canvas/screens/config_screen.rs
@@ -23,7 +23,7 @@ impl ConfigScreen for Painter {
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect,
) {
let config_block = Block::default()
- .title(" Config ") // FIXME: [Config] missing title styling
+ .title(Span::styled(" Config ", self.colours.widget_title_style))
.style(self.colours.border_style)
.borders(Borders::ALL)
.border_style(self.colours.border_style);
diff --git a/src/clap.rs b/src/clap.rs
index 2e064f37..5a5e9472 100644
--- a/src/clap.rs
+++ b/src/clap.rs
@@ -232,7 +232,8 @@ Defaults to \"default\".
.help("Defaults to showing process memory usage by value.")
.long_help(
"\
-Defaults to showing process memory usage by value. Otherwise, it defaults to showing it by percentage.\n\n",
+Defaults to showing process memory usage by value. Otherwise,
+it defaults to showing it by percentage.\n\n",
);
let default_time_value = Arg::with_name("default_time_value")
.short("t")
@@ -332,6 +333,15 @@ The amount of time in milliseconds changed when zooming in/out.
The minimum is 1s (1000), and defaults to 15s (15000).\n\n\n",
);
+ let tree = Arg::with_name("tree")
+ .short("T")
+ .long("tree")
+ .help("Defaults to showing the process widget in tree mode.")
+ .long_help(
+ "\
+Defaults to showing the process widget in tree mode.\n\n",
+ );
+
App::new(crate_name!())
.setting(AppSettings::UnifiedHelpMessage)
.version(crate_version!())
@@ -367,6 +377,7 @@ The minimum is 1s (1000), and defaults to 15s (15000).\n\n\n",
.arg(rate)
.arg(regex)
.arg(time_delta)
+ .arg(tree)
.arg(current_usage)
.arg(use_old_network_legend)
.arg(whole_word)
diff --git a/src/constants.rs b/src/constants.rs
index a408e7eb..b633aca7 100644
--- a/src/constants.rs
+++ b/src/constants.rs
@@ -399,7 +399,9 @@ pub const OLD_CONFIG_TEXT: &str = r##"# This is a default config file for bottom
# Built-in themes. Valid values are "default", "default-light", "gruvbox", "gruvbox-light"
#color = "default"
# Show memory values in the processes widget as values by default
-# mem_as_value = false
+#mem_as_value = false
+# Show tree mode by default in the processes widget.
+#tree = false
# These are all the components that support custom theming. Note that colour support
# will depend on terminal support.
diff --git a/src/options.rs b/src/options.rs
index 15fe6f1b..21da8427 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -144,6 +144,9 @@ pub struct ConfigFlags {
#[builder(default, setter(strip_option))]
pub mem_as_value: Option<bool>,
+
+ #[builder(default, setter(strip_option))]
+ pub tree: Option<bool>,
}
#[derive(Clone, Default, Debug, Deserialize, Serialize)]
@@ -235,6 +238,7 @@ pub fn build_app(
let mut used_widget_set = HashSet::new();
let show_memory_as_values = get_mem_as_value(matches, config);
+ let is_default_tree = get_is_default_tree(matches, config);
for row in &widget_layout.rows {
for col in &row.children {
@@ -302,6 +306,7 @@ pub fn build_app(
is_use_regex,
is_grouped,
show_memory_as_values,
+ is_default_tree,
),
);
}
@@ -937,3 +942,14 @@ fn get_mem_as_value(matches: &clap::ArgMatches<'static>, config: &Config) -> boo
}
false
}
+
+fn get_is_default_tree(matches: &clap::ArgMatches<'static>, config: &Config) -> bool {
+ if matches.is_present("tree") {
+ return true;
+ } else if let Some(flags) = &config.flags {
+ if let Some(tree) = flags.tree {
+ return tree;
+ }
+ }
+ false
+}