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

Fix displayed name for GNOME Terminal and Black Box #174

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions src/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ pub fn common_shells() -> [&'static str; 10] {
]
}

pub fn terminal_replacements(command: &str) -> &str {
match command {
"gnome-terminal-" => "gnome-terminal",
"blackbox-termin" => "blackbox",
_ => command,
}
}

#[cfg(test)]
#[cfg(not(target_os = "netbsd"))]
mod tests {
Expand Down
7 changes: 5 additions & 2 deletions src/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use self::pci_devices::get_pci_devices;
use crate::extra;
use crate::extra::get_entries;
use crate::extra::path_extension;
use crate::extra::terminal_replacements;
use crate::shared;
use crate::traits::*;
use itertools::Itertools;
Expand Down Expand Up @@ -417,10 +418,11 @@ impl GeneralReadout for LinuxGeneralReadout {
// The below loop will traverse /proc to find the
// terminal inside of which the user is operating
if let Ok(mut terminal_name) = fs::read_to_string(path) {
terminal_name = terminal_name.trim().to_string();
// Any command_name we find that matches
// one of the elements within this table
// is effectively ignored
while extra::common_shells().contains(&terminal_name.replace('\n', "").as_str()) {
while extra::common_shells().contains(&terminal_name.as_str()) {
let ppid = get_parent(terminal_pid);
terminal_pid = ppid;

Expand All @@ -438,14 +440,15 @@ impl GeneralReadout for LinuxGeneralReadout {
}

let terminal = terminal_name();
let terminal = terminal_replacements(&terminal);
Comment on lines 442 to +443
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a one-liner, the function should also be renamed to convey its function more clearly.


if terminal.is_empty() {
return Err(ReadoutError::Other(
"Querying terminal information failed".to_string(),
));
}

Ok(terminal)
Ok(terminal.to_string())
}

fn shell(&self, format: ShellFormat, kind: ShellKind) -> Result<String, ReadoutError> {
Expand Down