Skip to content

Commit

Permalink
update all dependencies to the latest version + various small fixes (#…
Browse files Browse the repository at this point in the history
…100)

* update dependencies to match Fedora patches

* update all dependencies

* fix all rust and clippy warnings
  • Loading branch information
decathorpe authored Feb 21, 2024
1 parent 91a79d6 commit 68d2f01
Show file tree
Hide file tree
Showing 11 changed files with 598 additions and 597 deletions.
1,073 changes: 537 additions & 536 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,24 @@ edition = "2018"
anyhow = "1.0"
serde = { version = "1.0", features = ["derive"] }
chrono = "0.4"
clap = "=3.0.0-beta.2"
clap_derive = "=3.0.0-beta.2"
confy = { git = "https://github.com/rust-cli/confy", features = [ "yaml_conf" ], default-features = false }
dirs = "2"
git2 = "0.15"
clap = { version = "4", features = ["derive"] }
confy = { version = "0.6", features = [ "yaml_conf" ], default-features = false }
dirs = "5"
git2 = { version = "0.18", default-features = false }
hostname = "0.3"
humantime = "2"
humantime-serde = "1.0"
once_cell = "1.4"
lazy_static = "1.4"
libc = "0.2"
regex = "1"
rust-ini = "0.15"
rust-ini = "0.20"
url = "2"
shellexpand = "2.0"
sysinfo = "0.15"
shellexpand = "3"
sysinfo = "0.30"

[target.'cfg(not(windows))'.dependencies]
users = "0.10"
users = { version = "0.11", package = "uzers" }

[target.'cfg(windows)'.dependencies.winapi]
version = "0.3"
Expand Down
6 changes: 3 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub use clap::Clap;
pub use clap::Parser;

#[derive(Clap, Debug)]
#[derive(Debug, Parser)]
#[clap(
about = "a cross-shell customizable powerline-like prompt with icons",
name = "silver",
Expand All @@ -13,7 +13,7 @@ pub struct Silver {
pub cmd: Command,
}

#[derive(Clap, Debug)]
#[derive(Debug, Parser)]
pub enum Command {
Init,
Lprint,
Expand Down
19 changes: 9 additions & 10 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 All @@ -83,16 +84,14 @@ pub struct Git {
}

fn default_left_prompt() -> Prompt {
vec![
Segment {
name: "dir".into(),
color: Colors {
background: Color::Name("7".into()),
foreground: Color::Name("0".into()),
},
args: vec![],
}
]
vec![Segment {
name: "dir".into(),
color: Colors {
background: Color::Name("7".into()),
foreground: Color::Name("0".into()),
},
args: vec![],
}]
}

// Implement defaults that will render a
Expand Down
18 changes: 8 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod sh;
use cli::*;
use once_cell::sync::{Lazy, OnceCell};
use std::path::{Path, PathBuf};
use sysinfo::{get_current_pid, ProcessExt, System, SystemExt};
use sysinfo::{get_current_pid, System};

static CONFIG_PATH: OnceCell<PathBuf> = OnceCell::new();

Expand Down Expand Up @@ -39,15 +39,13 @@ impl Default for Segment {

fn main() {
let sys = System::new_all();
let process = sys.get_process(get_current_pid().unwrap()).unwrap();
let parent = sys.get_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 process = sys.process(get_current_pid().unwrap()).unwrap();
let parent = sys.process(process.parent().unwrap()).unwrap();
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
10 changes: 6 additions & 4 deletions src/modules/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ pub fn segment(segment: &mut Segment, _: &[&str]) {
.iter()
.flat_map(|(i, j)| {
if let Ok(p) = Path::new(
&shellexpand::full_with_context_no_errors(j, dirs::home_dir, |s| {
env::var(s).map(Some).unwrap_or_default()
})
&shellexpand::full_with_context_no_errors(
j,
|| dirs::home_dir().map(|p| p.to_string_lossy().into_owned()),
|s| env::var(s).map(Some).unwrap_or_default(),
)
.into_owned(),
)
.canonicalize()
Expand All @@ -42,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
8 changes: 5 additions & 3 deletions src/modules/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ pub fn segment(segment: &mut Segment, args: &[&str]) {
for dir in CONFIG.git.ignore_dirs.iter() {
if std::env::current_dir().unwrap()
== Path::new(
&shellexpand::full_with_context_no_errors(dir, dirs::home_dir, |s| {
std::env::var(s).map(Some).unwrap_or_default()
})
&shellexpand::full_with_context_no_errors(
dir,
|| dirs::home_dir().map(|p| p.to_string_lossy().into_owned()),
|s| std::env::var(s).map(Some).unwrap_or_default(),
)
.into_owned(),
)
.canonicalize()
Expand Down
6 changes: 3 additions & 3 deletions src/modules/shell.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::Segment;
use sysinfo::{get_current_pid, ProcessExt, System, SystemExt};
use sysinfo::{get_current_pid, System};

pub fn segment(segment: &mut Segment, _: &[&str]) {
let sys = System::new_all();
segment.value = sys
.get_process(
sys.get_process(get_current_pid().unwrap())
.process(
sys.process(get_current_pid().unwrap())
.unwrap()
.parent()
.unwrap(),
Expand Down
26 changes: 13 additions & 13 deletions src/modules/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ fn is_root() -> bool {

let mut token = INVALID_HANDLE_VALUE;
let mut elevated = false;

if unsafe { OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut token) == TRUE } {
let mut elevation: TOKEN_ELEVATION = unsafe { mem::zeroed() };
let mut size = mem::size_of::<TOKEN_ELEVATION>() as DWORD;
if unsafe { GetTokenInformation(

if unsafe { OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut token) == TRUE } {
let mut elevation: TOKEN_ELEVATION = unsafe { mem::zeroed() };
let mut size = mem::size_of::<TOKEN_ELEVATION>() as DWORD;
if unsafe {
GetTokenInformation(
token,
TokenElevation,
&mut elevation as *mut TOKEN_ELEVATION as *mut c_void,
size,
&mut size,
) == TRUE }
{
elevated = elevation.TokenIsElevated != 0;
}
) == TRUE
} {
elevated = elevation.TokenIsElevated != 0;
}
}

if token != INVALID_HANDLE_VALUE {
unsafe { CloseHandle(token) };
}

if token != INVALID_HANDLE_VALUE {
unsafe { CloseHandle(token) };
}

elevated
}
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 68d2f01

Please sign in to comment.