feature: add tree flag (#312)

Adds a --tree flag that defaults to tree mode for the process widget.
This commit is contained in:
Clement Tsang 2020-11-20 00:13:46 -05:00 committed by GitHub
parent 5fedf8a5db
commit 2ff8b418b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 8 deletions

View File

@ -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.

View File

@ -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

View File

@ -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,
}

View File

@ -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);

View File

@ -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)

View File

@ -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.

View File

@ -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
}