Skip to content

Commit

Permalink
fix all rust and clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
decathorpe committed Feb 16, 2024
1 parent 53885b0 commit c00ff67
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub enum Color {
pub enum IconSet {
Nerd,
Unicode,
#[allow(clippy::upper_case_acronyms)]
ASCII,
}

Expand Down
12 changes: 5 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ fn main() {
let sys = System::new_all();
let process = sys.process(get_current_pid().unwrap()).unwrap();
let parent = sys.process(process.parent().unwrap()).unwrap();
let shell = std::env::var("SILVER_SHELL")
.map(|s| s)
.unwrap_or_else(|_| {
let shell = parent.name().trim();
let shell = shell.strip_suffix(".exe").unwrap_or(shell);
shell.strip_prefix("-").unwrap_or(shell).to_owned()
});
let shell = std::env::var("SILVER_SHELL").unwrap_or_else(|_| {
let shell = parent.name().trim();
let shell = shell.strip_suffix(".exe").unwrap_or(shell);
shell.strip_prefix('-').unwrap_or(shell).to_owned()
});

let opt = cli::Silver::parse();

Expand Down
2 changes: 1 addition & 1 deletion src/modules/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn segment(segment: &mut Segment, _: &[&str]) {
});
for (dir, alias) in aliases {
wd = match wd.strip_prefix(dir) {
Ok(stripped) => alias.join(stripped.to_path_buf()),
Ok(stripped) => alias.join(stripped),
Err(_) => wd.clone(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/print.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::{config, modules, sh, Segment};
use std::iter::once;

pub fn prompt<T, U>(shell: &str, args: &Vec<config::Segment>, f: T)
pub fn prompt<T, U>(shell: &str, args: &[config::Segment], f: T)
where
T: Fn(usize, (&Segment, &Segment, &Segment)) -> U,
U: IntoIterator<Item = (String, String, String)>,
{
let v: Vec<_> = once(Segment::default())
.chain(
args.into_iter()
args.iter()
.map(|arg| {
let mut segment = Segment {
background: arg.color.background.to_string(),
Expand Down
8 changes: 4 additions & 4 deletions src/sh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ lazy_static! {
}

fn code(color: &str, prefix: &str, light_prefix: &str) -> Option<String> {
let (color, prefix) = if color.starts_with("light") {
(&color[5..], light_prefix)
let (color, prefix) = if let Some(suffix) = color.strip_prefix("light") {
(suffix, light_prefix)
} else {
(color, prefix)
};
Expand All @@ -33,7 +33,7 @@ fn escape(
before_color: &str,
after_color: &str,
) -> String {
match code(&color, &prefix, &light_prefix) {
match code(color, prefix, light_prefix) {
// 16 colors
Some(code) => format!("{}\x1b[{}m{}", before_color, code, after_color),
None => {
Expand All @@ -47,7 +47,7 @@ fn escape(
}
Err(_) => {
// 24-bit color
if HEX.is_match(&color) {
if HEX.is_match(color) {
format!(
"{}\x1b[{}8;2;{}m{}",
before_color,
Expand Down

0 comments on commit c00ff67

Please sign in to comment.