Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add tree flag #312

Merged
merged 2 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
13 changes: 9 additions & 4 deletions src/app/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/screens/config_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion src/clap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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!())
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,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.
Expand Down
16 changes: 16 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -302,6 +306,7 @@ pub fn build_app(
is_use_regex,
is_grouped,
show_memory_as_values,
is_default_tree,
),
);
}
Expand Down Expand Up @@ -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
}