-
Notifications
You must be signed in to change notification settings - Fork 240
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: show hostname in title #999
base: main
Are you sure you want to change the base?
Conversation
For bottom to know that there are no batteries on the system, I added the battery::Manager to the options.rs file because here is the first moment bottom verifies battery configuration by reading the config file, which may or may not contain the battery field, but for a better UX, it doesn't matter what bottom finds in the config file now, if it doesn't retrieve battery data, it just ignores the battery widget all together. If needed, it can be adjusted so that if the config file contains the battery field, it will still show the widget.
I guarded the options.rs in two places for battery module that can be missing in the feature list.
Dynamic battery widget
Revert "Dynamic battery widget"
I added a new option in terminal and in the config file to be able to change the terminal title with any custom one. The user can now add `--title` and the custom title after it or add the `title_to_hostname` field in the config file to set the terminal's name to hostname. If there is no option found, then the name of the terminal will be set to "Bottom".
Hmmm... My first impression is that I'm not a fan of changing the default behaviour. I would personally rather it do nothing if nothing is set. Also while it does make sense to have a command-line flag for setting the title to a custom string, if we do keep that, I'm surprised there isn't a config file equivalent. What if I want to permanently set it? (EDIT: That said, I'm not even sure if I want this part, as it seems a bit unnecessary IMO.) As for setting to grab the hostname - does it make sense to just set it as the hostname? Or should we still label what the application is (e.g. Would also be nice to clean up that merge history a bit (why does it have commits from the dynamic battery PR?), but that's a nitpick and I'll likely just squash. |
I will add a config file option for setting the title and also remove the "Bottom" standard name if nothing is set. The idea about including the name of Bottom along the hostname is a good one, didn't think of it. After that, if everything is ok, I can squash the commits. |
Just to save you the effort, I added an edit to my earlier comment, but you can hold off on adding the option for setting the title in the config if you want - I'm not sure if I want to add that feature in general at the moment. |
I will not add that then, but I will rework the feature a bit to match your ideas. In case the title is set and there is an error because of EDIT: I will just use a tuple to return the name and a boolean if there were no errors. |
the name of the terminal, it will be set as before to its path. This behaviour will happen when an error happens inside the `get_use_terminal_name` function as well.
Codecov ReportBase: 20.71% // Head: 20.74% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #999 +/- ##
==========================================
+ Coverage 20.71% 20.74% +0.03%
==========================================
Files 75 75
Lines 14680 14706 +26
==========================================
+ Hits 3041 3051 +10
- Misses 11639 11655 +16
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Just a heads up, your CI is probably failing because your |
I've added the Also, CI runs with |
If you just build normally on your machine, I use |
I've rebuilt the project, thank you for explaining that to me! I resolved some conflict with master manually before (mistakes were made, hehe). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for taking so long, have some suggestions/fixes required.
src/clap.rs
Outdated
let title = Arg::new("title") | ||
.long("title") | ||
.takes_value(true) | ||
.value_name("Title") | ||
.help("Sets the title of the current terminal."); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we were just doing the hostname idea and putting the custom title part aside for now. If so, change this to match the config option, and not take a value.
src/options.rs
Outdated
pub fn get_use_terminal_name(matches: &ArgMatches, config: &Config) -> (bool, String) { | ||
if matches.is_present("title") { | ||
return if let Some(custom_name) = matches.value_of("title") { | ||
(true, String::from(custom_name)) | ||
} else { | ||
(false, String::from("")) | ||
}; | ||
} else if let Some(flags) = &config.flags { | ||
if let Some(title_to_hostname) = flags.title_to_hostname { | ||
if title_to_hostname { | ||
return match gethostname().into_string() { | ||
Ok(hostname) => (title_to_hostname, format!("btm ({})", hostname)), | ||
Err(_) => (false, String::from("")), | ||
}; | ||
} | ||
} | ||
} | ||
(false, String::from("")) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions:
- As mentioned above, remove the custom name part, as we're not doing that for now. Just use the hostname.
- Why not just return an
Option
? e.g. if there is no change, returnNone
.
I removed the custom title option for terminal and made it use the hostname when `--title` is used. The title always contains `btm` now. If `--title` or `title_has_hostname = true` (in config file) is not present, then the terminal has the previous behaviour.
Sorry for this late commit, I will resolve the deprecated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more nitpicks. As mentioned in one of them, it would be nice if you rebase to the latest master branch since most of the clap-related changes you made shouldn't be necessary.
let title = Arg::new("title") | ||
.long("title") | ||
.help("Sets the title of the current terminal to \"btm ($hostname)\"."); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rename to match the option.
@@ -92,6 +93,7 @@ pub struct ConfigFlags { | |||
pub network_use_log: Option<bool>, | |||
pub network_use_binary_prefix: Option<bool>, | |||
pub enable_gpu_memory: Option<bool>, | |||
pub title_has_hostname: Option<bool>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Sorry for suggesting something else, but maybe title_shows_hostname
? Change the config file and clap option as well.
@@ -498,7 +500,7 @@ pub fn get_widget_layout( | |||
} | |||
|
|||
fn get_update_rate_in_milliseconds(matches: &ArgMatches, config: &Config) -> error::Result<u64> { | |||
let update_rate_in_milliseconds = if let Some(update_rate) = matches.value_of("rate") { | |||
let update_rate_in_milliseconds = if let Some(update_rate) = matches.get_one::<String>("rate") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, wonder why it's showing that you had to make a change here (and the rest of this file for any clap issues). If you want, it might be nice to rebase and clean up the commit history (e.g. those weird battery commits).
@@ -732,8 +735,26 @@ pub fn get_app_use_regex(matches: &ArgMatches, config: &Config) -> bool { | |||
false | |||
} | |||
|
|||
pub fn get_use_terminal_name(matches: &ArgMatches, config: &Config) -> Option<String> { | |||
match gethostname().into_string() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: IMO invert this - that is, check if the match
or config
have the corresponding flag first before running gethostname
.
So maybe for example:
if matches.contains_id("title") || &config.flags.and_then(|f| f.title_has_hostname).unwrap_or(false) {
match gethostname().into_string() {
Ok(hostname) => Some(format!("btm ({hostname})")),
Err(_) => None,
}
} else {
None
}
@@ -732,8 +735,26 @@ pub fn get_app_use_regex(matches: &ArgMatches, config: &Config) -> bool { | |||
false | |||
} | |||
|
|||
pub fn get_use_terminal_name(matches: &ArgMatches, config: &Config) -> Option<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to add - might want to rename this to something like get_show_hostname
.
Description
A description of the change, what it does, and why it was made. If relevant (such as any change that modifies the UI), please provide screenshots of the changes:
Added an option to change the terminal name. The user can use
--title
, followed by the desired name for the terminal, or usetitle_to_hostname
field (true/false) in the config file to force the name of the terminal to be the name of the host machine. Otherwise, if no option is used, the default name of the terminal will be now "Bottom". It also works while using SSH.This PR was also discussed at:
UPB-CS-OpenSourceUpstream#4
Issue
If applicable, what issue does this address?
#277
Testing
If relevant, please state how this was tested. All changes must be tested to work:
Tested it on multiple platforms. I also used SSH on all of them.
If this is a code change, please also indicate which platforms were tested:
Checklist
If relevant, ensure the following have been met:
cargo fmt
)README.md
, help menu, doc pages, etc.)