refactor: switch to rust 2024 edition & handle dependency updates (#6609)

This commit is contained in:
David Knaack 2025-03-09 19:24:45 +01:00 committed by GitHub
parent df454d5a64
commit 2a3ca68457
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
48 changed files with 429 additions and 247 deletions

View File

@ -1265,6 +1265,7 @@
"Android": "🤖 ", "Android": "🤖 ",
"Arch": "🎗️ ", "Arch": "🎗️ ",
"Artix": "🎗️ ", "Artix": "🎗️ ",
"Bluefin": "🐟 ",
"CachyOS": "🎗️ ", "CachyOS": "🎗️ ",
"CentOS": "💠 ", "CentOS": "💠 ",
"Debian": "🌀 ", "Debian": "🌀 ",
@ -5008,6 +5009,7 @@
"Android": "🤖 ", "Android": "🤖 ",
"Arch": "🎗️ ", "Arch": "🎗️ ",
"Artix": "🎗️ ", "Artix": "🎗️ ",
"Bluefin": "🐟 ",
"CachyOS": "🎗️ ", "CachyOS": "🎗️ ",
"CentOS": "💠 ", "CentOS": "💠 ",
"Debian": "🌀 ", "Debian": "🌀 ",

167
Cargo.lock generated
View File

@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 4
[[package]] [[package]]
name = "adler2" name = "adler2"
@ -17,7 +17,7 @@ dependencies = [
"cfg-if", "cfg-if",
"once_cell", "once_cell",
"version_check", "version_check",
"zerocopy", "zerocopy 0.7.35",
] ]
[[package]] [[package]]
@ -627,7 +627,7 @@ checksum = "1c7397f8c48906dd9b5afc75001368c979418e5dff5575998a831eb2319b424e"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"pathsearch", "pathsearch",
"rand", "rand 0.8.5",
"shared_library", "shared_library",
"termwiz", "termwiz",
"winapi", "winapi",
@ -1873,9 +1873,9 @@ dependencies = [
[[package]] [[package]]
name = "is_debug" name = "is_debug"
version = "1.0.2" version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8ea828c9d6638a5bd3d8b14e37502b4d56cae910ccf8a5b7f51c7a0eb1d0508" checksum = "1fe266d2e243c931d8190177f20bf7f24eed45e96f39e87dc49a27b32d12d407"
[[package]] [[package]]
name = "is_terminal_polyfill" name = "is_terminal_polyfill"
@ -2469,7 +2469,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d"
dependencies = [ dependencies = [
"phf_shared", "phf_shared",
"rand", "rand 0.8.5",
] ]
[[package]] [[package]]
@ -2565,7 +2565,7 @@ version = "0.2.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
dependencies = [ dependencies = [
"zerocopy", "zerocopy 0.7.35",
] ]
[[package]] [[package]]
@ -2676,8 +2676,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [ dependencies = [
"libc", "libc",
"rand_chacha", "rand_chacha 0.3.1",
"rand_core", "rand_core 0.6.4",
]
[[package]]
name = "rand"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94"
dependencies = [
"rand_chacha 0.9.0",
"rand_core 0.9.3",
"zerocopy 0.8.22",
] ]
[[package]] [[package]]
@ -2687,7 +2698,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [ dependencies = [
"ppv-lite86", "ppv-lite86",
"rand_core", "rand_core 0.6.4",
]
[[package]]
name = "rand_chacha"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
dependencies = [
"ppv-lite86",
"rand_core 0.9.3",
] ]
[[package]] [[package]]
@ -2699,6 +2720,15 @@ dependencies = [
"getrandom 0.2.15", "getrandom 0.2.15",
] ]
[[package]]
name = "rand_core"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
dependencies = [
"getrandom 0.3.1",
]
[[package]] [[package]]
name = "rayon" name = "rayon"
version = "1.10.0" version = "1.10.0"
@ -3009,13 +3039,14 @@ dependencies = [
[[package]] [[package]]
name = "shadow-rs" name = "shadow-rs"
version = "0.38.1" version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ec14cc798c29f4bf74a6c4299c657c04d4e9fba03875c1f0eec569af03aed89" checksum = "3672eb035a31ac62bf171765d04e3f1f01659920847384d08ac979ca6bb56763"
dependencies = [ dependencies = [
"const_format", "const_format",
"is_debug", "is_debug",
"time", "time",
"tzdb",
] ]
[[package]] [[package]]
@ -3126,7 +3157,7 @@ dependencies = [
"pest_derive", "pest_derive",
"process_control", "process_control",
"quick-xml 0.37.2", "quick-xml 0.37.2",
"rand", "rand 0.9.0",
"rayon", "rayon",
"regex", "regex",
"rust-ini", "rust-ini",
@ -3150,7 +3181,7 @@ dependencies = [
"versions", "versions",
"which", "which",
"whoami", "whoami",
"windows 0.59.0", "windows 0.60.0",
"winres", "winres",
"yaml-rust2", "yaml-rust2",
] ]
@ -3521,6 +3552,32 @@ version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "tz-rs"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1450bf2b99397e72070e7935c89facaa80092ac812502200375f1f7d33c71a1"
[[package]]
name = "tzdb"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0be2ea5956f295449f47c0b825c5e109022ff1a6a53bb4f77682a87c2341fbf5"
dependencies = [
"iana-time-zone",
"tz-rs",
"tzdb_data",
]
[[package]]
name = "tzdb_data"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0604b35c1f390a774fdb138cac75a99981078895d24bcab175987440bbff803b"
dependencies = [
"tz-rs",
]
[[package]] [[package]]
name = "ucd-trie" name = "ucd-trie"
version = "0.1.7" version = "0.1.7"
@ -3822,12 +3879,24 @@ dependencies = [
[[package]] [[package]]
name = "windows" name = "windows"
version = "0.59.0" version = "0.60.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f919aee0a93304be7f62e8e5027811bbba96bcb1de84d6618be56e43f8a32a1" checksum = "ddf874e74c7a99773e62b1c671427abf01a425e77c3d3fb9fb1e4883ea934529"
dependencies = [ dependencies = [
"windows-core 0.59.0", "windows-collections",
"windows-targets 0.53.0", "windows-core 0.60.1",
"windows-future",
"windows-link",
"windows-numerics",
]
[[package]]
name = "windows-collections"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5467f79cc1ba3f52ebb2ed41dbb459b8e7db636cc3429458d9a852e15bc24dec"
dependencies = [
"windows-core 0.60.1",
] ]
[[package]] [[package]]
@ -3853,15 +3922,25 @@ dependencies = [
[[package]] [[package]]
name = "windows-core" name = "windows-core"
version = "0.59.0" version = "0.60.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "810ce18ed2112484b0d4e15d022e5f598113e220c53e373fb31e67e21670c1ce" checksum = "ca21a92a9cae9bf4ccae5cf8368dce0837100ddf6e6d57936749e85f152f6247"
dependencies = [ dependencies = [
"windows-implement 0.59.0", "windows-implement 0.59.0",
"windows-interface 0.59.0", "windows-interface 0.59.0",
"windows-result 0.3.0", "windows-link",
"windows-result 0.3.1",
"windows-strings", "windows-strings",
"windows-targets 0.53.0", ]
[[package]]
name = "windows-future"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a787db4595e7eb80239b74ce8babfb1363d8e343ab072f2ffe901400c03349f0"
dependencies = [
"windows-core 0.60.1",
"windows-link",
] ]
[[package]] [[package]]
@ -3914,6 +3993,16 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6dccfd733ce2b1753b03b6d3c65edf020262ea35e20ccdf3e288043e6dd620e3" checksum = "6dccfd733ce2b1753b03b6d3c65edf020262ea35e20ccdf3e288043e6dd620e3"
[[package]]
name = "windows-numerics"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "005dea54e2f6499f2cee279b8f703b3cf3b5734a2d8d21867c8f44003182eeed"
dependencies = [
"windows-core 0.60.1",
"windows-link",
]
[[package]] [[package]]
name = "windows-result" name = "windows-result"
version = "0.1.2" version = "0.1.2"
@ -3925,20 +4014,20 @@ dependencies = [
[[package]] [[package]]
name = "windows-result" name = "windows-result"
version = "0.3.0" version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d08106ce80268c4067c0571ca55a9b4e9516518eaa1a1fe9b37ca403ae1d1a34" checksum = "06374efe858fab7e4f881500e6e86ec8bc28f9462c47e5a9941a0142ad86b189"
dependencies = [ dependencies = [
"windows-targets 0.53.0", "windows-link",
] ]
[[package]] [[package]]
name = "windows-strings" name = "windows-strings"
version = "0.3.0" version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b888f919960b42ea4e11c2f408fadb55f78a9f236d5eef084103c8ce52893491" checksum = "87fa48cc5d406560701792be122a10132491cff9d0aeb23583cc2dcafc847319"
dependencies = [ dependencies = [
"windows-targets 0.53.0", "windows-link",
] ]
[[package]] [[package]]
@ -4265,7 +4354,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"zerocopy-derive", "zerocopy-derive 0.7.35",
]
[[package]]
name = "zerocopy"
version = "0.8.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09612fda0b63f7cb9e0af7e5916fe5a1f8cdcb066829f10f36883207628a4872"
dependencies = [
"zerocopy-derive 0.8.22",
] ]
[[package]] [[package]]
@ -4279,6 +4377,17 @@ dependencies = [
"syn 2.0.98", "syn 2.0.98",
] ]
[[package]]
name = "zerocopy-derive"
version = "0.8.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79f81d38d7a2ed52d8f034e62c568e111df9bf8aba2f7cf19ddc5bf7bd89d520"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.98",
]
[[package]] [[package]]
name = "zerofrom" name = "zerofrom"
version = "0.1.5" version = "0.1.5"

View File

@ -5,7 +5,7 @@ authors = ["Starship Contributors"]
build = "build.rs" build = "build.rs"
categories = ["command-line-utilities"] categories = ["command-line-utilities"]
documentation = "https://starship.rs/guide/" documentation = "https://starship.rs/guide/"
edition = "2021" edition = "2024"
homepage = "https://starship.rs" homepage = "https://starship.rs"
# Keep `/` in front of `README.md` to exclude localized readmes # Keep `/` in front of `README.md` to exclude localized readmes
include = [ include = [
@ -23,7 +23,7 @@ license = "ISC"
readme = "README.md" readme = "README.md"
repository = "https://github.com/starship/starship" repository = "https://github.com/starship/starship"
# Note: MSRV is only intended as a hint, and only the latest version is officially supported in starship. # Note: MSRV is only intended as a hint, and only the latest version is officially supported in starship.
rust-version = "1.80" rust-version = "1.85"
description = """ description = """
The minimal, blazing-fast, and infinitely customizable prompt for any shell! 🌌 The minimal, blazing-fast, and infinitely customizable prompt for any shell! 🌌
""" """
@ -66,7 +66,7 @@ pest = "2.7.15"
pest_derive = "2.7.15" pest_derive = "2.7.15"
process_control = "5.0.0" process_control = "5.0.0"
quick-xml = "0.37.2" quick-xml = "0.37.2"
rand = "0.8.5" rand = "0.9.0"
rayon = "1.10.0" rayon = "1.10.0"
regex = { version = "1.11.1", default-features = false, features = ["perf", "std", "unicode-perl"] } regex = { version = "1.11.1", default-features = false, features = ["perf", "std", "unicode-perl"] }
rust-ini = "0.21.1" rust-ini = "0.21.1"
@ -74,7 +74,7 @@ semver = "1.0.26"
serde = { version = "1.0.218", features = ["derive"] } serde = { version = "1.0.218", features = ["derive"] }
serde_json = "1.0.140" serde_json = "1.0.140"
sha1 = "0.10.6" sha1 = "0.10.6"
shadow-rs = { version = "0.38.1", default-features = false } shadow-rs = { version = "1.0.1", default-features = false, features = ["build"] }
# battery is optional (on by default) because the crate doesn't currently build for Termux # battery is optional (on by default) because the crate doesn't currently build for Termux
# see: https://github.com/svartalf/rust-battery/issues/33 # see: https://github.com/svartalf/rust-battery/issues/33
starship-battery = { version = "0.10.0", optional = true } starship-battery = { version = "0.10.0", optional = true }
@ -106,7 +106,7 @@ features = ["preserve_order", "indexmap2"]
deelevate = "0.2.0" deelevate = "0.2.0"
[target.'cfg(windows)'.dependencies.windows] [target.'cfg(windows)'.dependencies.windows]
version = "0.59.0" version = "0.60.0"
features = [ features = [
"Win32_Foundation", "Win32_Foundation",
"Win32_UI_Shell", "Win32_UI_Shell",
@ -119,7 +119,7 @@ features = [
nix = { version = "0.29.0", default-features = false, features = ["feature", "fs", "user"] } nix = { version = "0.29.0", default-features = false, features = ["feature", "fs", "user"] }
[build-dependencies] [build-dependencies]
shadow-rs = { version = "0.38.1", default-features = false } shadow-rs = { version = "1.0.1", default-features = false, features = ["build"] }
dunce = "1.0.5" dunce = "1.0.5"
[target.'cfg(windows)'.build-dependencies] [target.'cfg(windows)'.build-dependencies]

View File

@ -3378,6 +3378,7 @@ Amazon = "🙂 "
Android = "🤖 " Android = "🤖 "
Arch = "🎗️ " Arch = "🎗️ "
Artix = "🎗️ " Artix = "🎗️ "
Bluefin = "🐟 "
CachyOS = "🎗️ " CachyOS = "🎗️ "
CentOS = "💠 " CentOS = "💠 "
Debian = "🌀 " Debian = "🌀 "

View File

@ -145,6 +145,7 @@ Amazon = "amz "
Android = "andr " Android = "andr "
Arch = "rch " Arch = "rch "
Artix = "atx " Artix = "atx "
Bluefin = "blfn "
CachyOS = "cach " CachyOS = "cach "
CentOS = "cent " CentOS = "cent "
Debian = "deb " Debian = "deb "

View File

@ -25,7 +25,10 @@ pub fn create() {
Style::new().bold().paint("Generated bug report:") Style::new().bold().paint("Generated bug report:")
); );
println!("Forward the pre-filled report above to GitHub in your browser?"); println!("Forward the pre-filled report above to GitHub in your browser?");
println!("{} To avoid any sensitive data from being exposed, please review the included information before proceeding. Data forwarded to GitHub is subject to GitHub's privacy policy.", Style::new().bold().paint("Warning:")); println!(
"{} To avoid any sensitive data from being exposed, please review the included information before proceeding. Data forwarded to GitHub is subject to GitHub's privacy policy.",
Style::new().bold().paint("Warning:")
);
println!( println!(
"Enter `{}` to accept, or anything else to decline, and `{}` to confirm your choice:\n", "Enter `{}` to accept, or anything else to decline, and `{}` to confirm your choice:\n",
Style::new().bold().paint("y"), Style::new().bold().paint("y"),
@ -39,10 +42,14 @@ pub fn create() {
let link = make_github_issue_link(&issue_body); let link = make_github_issue_link(&issue_body);
if let Err(e) = open::that(&link) { if let Err(e) = open::that(&link) {
println!("Failed to open issue report in your browser: {e}"); println!("Failed to open issue report in your browser: {e}");
println!("Please copy the above report and open an issue manually, or try opening the following link:\n{link}"); println!(
"Please copy the above report and open an issue manually, or try opening the following link:\n{link}"
);
} }
} else { } else {
println!("Will not open an issue in your browser! Please copy the above report and open an issue manually."); println!(
"Will not open an issue in your browser! Please copy the above report and open an issue manually."
);
} }
println!("Thanks for using the Starship bug report tool!"); println!("Thanks for using the Starship bug report tool!");
} }

View File

@ -5,7 +5,7 @@ use crate::serde_utils::{ValueDeserializer, ValueRef};
use crate::utils; use crate::utils;
use nu_ansi_term::Color; use nu_ansi_term::Color;
use serde::{ use serde::{
de::value::Error as ValueError, de::Error as SerdeError, Deserialize, Deserializer, Serialize, Deserialize, Deserializer, Serialize, de::Error as SerdeError, de::value::Error as ValueError,
}; };
use std::borrow::Cow; use std::borrow::Cow;
@ -106,8 +106,8 @@ where
Either::<T, Vec<T>>::schema_name() Either::<T, Vec<T>>::schema_name()
} }
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { fn json_schema(generator: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
Either::<T, Vec<T>>::json_schema(gen) Either::<T, Vec<T>>::json_schema(generator)
} }
fn is_referenceable() -> bool { fn is_referenceable() -> bool {

View File

@ -1,4 +1,4 @@
use indexmap::{indexmap, IndexMap}; use indexmap::{IndexMap, indexmap};
use os_info::Type; use os_info::Type;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -36,6 +36,7 @@ impl Default for OSConfig<'_> {
Type::Android => "🤖 ", Type::Android => "🤖 ",
Type::Arch => "🎗️ ", Type::Arch => "🎗️ ",
Type::Artix => "🎗️ ", Type::Artix => "🎗️ ",
Type::Bluefin => "🐟 ",
Type::CachyOS => "🎗️ ", Type::CachyOS => "🎗️ ",
Type::CentOS => "💠 ", Type::CentOS => "💠 ",
Type::Debian => "🌀 ", Type::Debian => "🌀 ",

View File

@ -47,8 +47,7 @@ impl Default for StatusConfig<'_> {
recognize_signal_code: true, recognize_signal_code: true,
pipestatus: false, pipestatus: false,
pipestatus_separator: "|", pipestatus_separator: "|",
pipestatus_format: pipestatus_format: "\\[$pipestatus\\] => [$symbol$common_meaning$signal_name$maybe_int]($style) ",
"\\[$pipestatus\\] => [$symbol$common_meaning$signal_name$maybe_int]($style) ",
pipestatus_segment_format: None, pipestatus_segment_format: None,
disabled: true, disabled: true,
} }

View File

@ -574,9 +574,11 @@ mod tests {
handle_update_configuration(&mut doc, "a.b.c.d.e.f.g.h", "true").unwrap(); handle_update_configuration(&mut doc, "a.b.c.d.e.f.g.h", "true").unwrap();
assert!(doc["a"]["b"]["c"]["d"]["e"]["f"]["g"]["h"] assert!(
doc["a"]["b"]["c"]["d"]["e"]["f"]["g"]["h"]
.as_bool() .as_bool()
.unwrap()) .unwrap()
)
} }
#[test] #[test]

View File

@ -2,15 +2,16 @@ use crate::config::{ModuleConfig, StarshipConfig};
use crate::configs::StarshipRootConfig; use crate::configs::StarshipRootConfig;
use crate::context_env::Env; use crate::context_env::Env;
use crate::module::Module; use crate::module::Module;
use crate::utils::{create_command, exec_timeout, read_file, CommandOutput, PathExt}; use crate::utils::{CommandOutput, PathExt, create_command, exec_timeout, read_file};
use crate::modules; use crate::modules;
use crate::utils; use crate::utils;
use clap::Parser; use clap::Parser;
use gix::{ use gix::{
Repository, ThreadSafeRepository,
repository::Kind, repository::Kind,
sec::{self as git_sec, trust::DefaultForLevel}, sec::{self as git_sec, trust::DefaultForLevel},
state as git_state, Repository, ThreadSafeRepository, state as git_state,
}; };
#[cfg(test)] #[cfg(test)]
use std::collections::HashMap; use std::collections::HashMap;
@ -979,39 +980,47 @@ mod tests {
let dc_following_symlinks = DirContents::from_path(d.path(), true)?; let dc_following_symlinks = DirContents::from_path(d.path(), true)?;
assert!(ScanDir { assert!(
ScanDir {
dir_contents: &dc_following_symlinks, dir_contents: &dc_following_symlinks,
files: &["link_to_file"], files: &["link_to_file"],
extensions: &[], extensions: &[],
folders: &[], folders: &[],
} }
.is_match()); .is_match()
);
assert!(ScanDir { assert!(
ScanDir {
dir_contents: &dc_following_symlinks, dir_contents: &dc_following_symlinks,
files: &[], files: &[],
extensions: &[], extensions: &[],
folders: &["link_to_folder"], folders: &["link_to_folder"],
} }
.is_match()); .is_match()
);
let dc_not_following_symlinks = DirContents::from_path(d.path(), false)?; let dc_not_following_symlinks = DirContents::from_path(d.path(), false)?;
assert!(ScanDir { assert!(
ScanDir {
dir_contents: &dc_not_following_symlinks, dir_contents: &dc_not_following_symlinks,
files: &["link_to_file"], files: &["link_to_file"],
extensions: &[], extensions: &[],
folders: &[], folders: &[],
} }
.is_match()); .is_match()
);
assert!(!ScanDir { assert!(
!ScanDir {
dir_contents: &dc_not_following_symlinks, dir_contents: &dc_not_following_symlinks,
files: &[], files: &[],
extensions: &[], extensions: &[],
folders: &["link_to_folder"], folders: &["link_to_folder"],
} }
.is_match()); .is_match()
);
Ok(()) Ok(())
} }
@ -1022,91 +1031,107 @@ mod tests {
let follow_symlinks = true; let follow_symlinks = true;
let empty_dc = DirContents::from_path(empty.path(), follow_symlinks)?; let empty_dc = DirContents::from_path(empty.path(), follow_symlinks)?;
assert!(!ScanDir { assert!(
!ScanDir {
dir_contents: &empty_dc, dir_contents: &empty_dc,
files: &["package.json"], files: &["package.json"],
extensions: &["js"], extensions: &["js"],
folders: &["node_modules"], folders: &["node_modules"],
} }
.is_match()); .is_match()
);
empty.close()?; empty.close()?;
let rust = testdir(&["README.md", "Cargo.toml", "src/main.rs"])?; let rust = testdir(&["README.md", "Cargo.toml", "src/main.rs"])?;
let rust_dc = DirContents::from_path(rust.path(), follow_symlinks)?; let rust_dc = DirContents::from_path(rust.path(), follow_symlinks)?;
assert!(!ScanDir { assert!(
!ScanDir {
dir_contents: &rust_dc, dir_contents: &rust_dc,
files: &["package.json"], files: &["package.json"],
extensions: &["js"], extensions: &["js"],
folders: &["node_modules"], folders: &["node_modules"],
} }
.is_match()); .is_match()
);
rust.close()?; rust.close()?;
let java = testdir(&["README.md", "src/com/test/Main.java", "pom.xml"])?; let java = testdir(&["README.md", "src/com/test/Main.java", "pom.xml"])?;
let java_dc = DirContents::from_path(java.path(), follow_symlinks)?; let java_dc = DirContents::from_path(java.path(), follow_symlinks)?;
assert!(!ScanDir { assert!(
!ScanDir {
dir_contents: &java_dc, dir_contents: &java_dc,
files: &["package.json"], files: &["package.json"],
extensions: &["js"], extensions: &["js"],
folders: &["node_modules"], folders: &["node_modules"],
} }
.is_match()); .is_match()
);
java.close()?; java.close()?;
let node = testdir(&["README.md", "node_modules/lodash/main.js", "package.json"])?; let node = testdir(&["README.md", "node_modules/lodash/main.js", "package.json"])?;
let node_dc = DirContents::from_path(node.path(), follow_symlinks)?; let node_dc = DirContents::from_path(node.path(), follow_symlinks)?;
assert!(ScanDir { assert!(
ScanDir {
dir_contents: &node_dc, dir_contents: &node_dc,
files: &["package.json"], files: &["package.json"],
extensions: &["js"], extensions: &["js"],
folders: &["node_modules"], folders: &["node_modules"],
} }
.is_match()); .is_match()
);
node.close()?; node.close()?;
let tarballs = testdir(&["foo.tgz", "foo.tar.gz"])?; let tarballs = testdir(&["foo.tgz", "foo.tar.gz"])?;
let tarballs_dc = DirContents::from_path(tarballs.path(), follow_symlinks)?; let tarballs_dc = DirContents::from_path(tarballs.path(), follow_symlinks)?;
assert!(ScanDir { assert!(
ScanDir {
dir_contents: &tarballs_dc, dir_contents: &tarballs_dc,
files: &[], files: &[],
extensions: &["tar.gz"], extensions: &["tar.gz"],
folders: &[], folders: &[],
} }
.is_match()); .is_match()
);
tarballs.close()?; tarballs.close()?;
let dont_match_ext = testdir(&["foo.js", "foo.ts"])?; let dont_match_ext = testdir(&["foo.js", "foo.ts"])?;
let dont_match_ext_dc = DirContents::from_path(dont_match_ext.path(), follow_symlinks)?; let dont_match_ext_dc = DirContents::from_path(dont_match_ext.path(), follow_symlinks)?;
assert!(!ScanDir { assert!(
!ScanDir {
dir_contents: &dont_match_ext_dc, dir_contents: &dont_match_ext_dc,
files: &[], files: &[],
extensions: &["js", "!notfound", "!ts"], extensions: &["js", "!notfound", "!ts"],
folders: &[], folders: &[],
} }
.is_match()); .is_match()
);
dont_match_ext.close()?; dont_match_ext.close()?;
let dont_match_file = testdir(&["goodfile", "evilfile"])?; let dont_match_file = testdir(&["goodfile", "evilfile"])?;
let dont_match_file_dc = DirContents::from_path(dont_match_file.path(), follow_symlinks)?; let dont_match_file_dc = DirContents::from_path(dont_match_file.path(), follow_symlinks)?;
assert!(!ScanDir { assert!(
!ScanDir {
dir_contents: &dont_match_file_dc, dir_contents: &dont_match_file_dc,
files: &["goodfile", "!notfound", "!evilfile"], files: &["goodfile", "!notfound", "!evilfile"],
extensions: &[], extensions: &[],
folders: &[], folders: &[],
} }
.is_match()); .is_match()
);
dont_match_file.close()?; dont_match_file.close()?;
let dont_match_folder = testdir(&["gooddir/somefile", "evildir/somefile"])?; let dont_match_folder = testdir(&["gooddir/somefile", "evildir/somefile"])?;
let dont_match_folder_dc = let dont_match_folder_dc =
DirContents::from_path(dont_match_folder.path(), follow_symlinks)?; DirContents::from_path(dont_match_folder.path(), follow_symlinks)?;
assert!(!ScanDir { assert!(
!ScanDir {
dir_contents: &dont_match_folder_dc, dir_contents: &dont_match_folder_dc,
files: &[], files: &[],
extensions: &[], extensions: &[],
folders: &["gooddir", "!notfound", "!evildir"], folders: &["gooddir", "!notfound", "!evildir"],
} }
.is_match()); .is_match()
);
dont_match_folder.close()?; dont_match_folder.close()?;
Ok(()) Ok(())

View File

@ -1,7 +1,7 @@
// Can't rename internal Pest names // Can't rename internal Pest names
#![allow(clippy::upper_case_acronyms)] #![allow(clippy::upper_case_acronyms)]
use pest::{error::Error, iterators::Pair, Parser}; use pest::{Parser, error::Error, iterators::Pair};
use pest_derive::*; use pest_derive::*;
use super::model::*; use super::model::*;

View File

@ -5,12 +5,12 @@ use std::collections::{BTreeMap, BTreeSet};
use std::error::Error; use std::error::Error;
use std::fmt; use std::fmt;
use crate::config::{parse_style_string, Style}; use crate::config::{Style, parse_style_string};
use crate::context::{Context, Shell}; use crate::context::{Context, Shell};
use crate::segment::Segment; use crate::segment::Segment;
use super::model::*; use super::model::*;
use super::parser::{parse, Rule}; use super::parser::{Rule, parse};
#[derive(Clone)] #[derive(Clone)]
enum VariableValue<'a> { enum VariableValue<'a> {

View File

@ -1,5 +1,5 @@
use super::string_formatter::StringFormatterError;
use super::StringFormatter; use super::StringFormatter;
use super::string_formatter::StringFormatterError;
use crate::segment; use crate::segment;
use std::ops::Deref; use std::ops::Deref;
use std::sync::LazyLock; use std::sync::LazyLock;

View File

@ -8,7 +8,6 @@ use std::time::SystemTime;
use clap::{CommandFactory, Parser, Subcommand, ValueEnum}; use clap::{CommandFactory, Parser, Subcommand, ValueEnum};
use clap_complete::generate; use clap_complete::generate;
use rand::distributions::Alphanumeric;
use rand::Rng; use rand::Rng;
use starship::context::{Context, Properties, Target}; use starship::context::{Context, Properties, Target};
use starship::module::ALL_MODULES; use starship::module::ALL_MODULES;
@ -269,8 +268,8 @@ fn main() {
Commands::Completions { shell } => generate_completions(shell), Commands::Completions { shell } => generate_completions(shell),
Commands::Session => println!( Commands::Session => println!(
"{}", "{}",
rand::thread_rng() rand::rng()
.sample_iter(&Alphanumeric) .sample_iter(rand::distr::Alphanumeric)
.take(16) .take(16)
.map(char::from) .map(char::from)
.collect::<String>() .collect::<String>()

View File

@ -305,7 +305,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
mod tests { mod tests {
use crate::test::ModuleRenderer; use crate::test::ModuleRenderer;
use nu_ansi_term::Color; use nu_ansi_term::Color;
use std::fs::{create_dir, File}; use std::fs::{File, create_dir};
use std::io::{self, Write}; use std::io::{self, Write};
#[test] #[test]
@ -497,13 +497,15 @@ mod tests {
let config_path = dir.path().join("credentials"); let config_path = dir.path().join("credentials");
create_dir(&config_path)?; create_dir(&config_path)?;
assert!(ModuleRenderer::new("aws") assert!(
ModuleRenderer::new("aws")
.env( .env(
"AWS_SHARED_CREDENTIALS_FILE", "AWS_SHARED_CREDENTIALS_FILE",
config_path.to_string_lossy().as_ref(), config_path.to_string_lossy().as_ref(),
) )
.collect() .collect()
.is_none()); .is_none()
);
dir.close() dir.close()
} }
@ -514,10 +516,12 @@ mod tests {
let config_path = dir.path().join("config"); let config_path = dir.path().join("config");
create_dir(&config_path)?; create_dir(&config_path)?;
assert!(ModuleRenderer::new("aws") assert!(
ModuleRenderer::new("aws")
.env("AWS_CONFIG_FILE", config_path.to_string_lossy().as_ref()) .env("AWS_CONFIG_FILE", config_path.to_string_lossy().as_ref())
.collect() .collect()
.is_none()); .is_none()
);
dir.close() dir.close()
} }

View File

@ -69,7 +69,7 @@ fn undistract_me<'a>(
elapsed: u128, elapsed: u128,
) -> Module<'a> { ) -> Module<'a> {
use notify_rust::{Notification, Timeout}; use notify_rust::{Notification, Timeout};
use nu_ansi_term::{unstyle, AnsiStrings}; use nu_ansi_term::{AnsiStrings, unstyle};
if config.show_notifications && config.min_time_to_notify as u128 <= elapsed { if config.show_notifications && config.min_time_to_notify as u128 <= elapsed {
if cfg!(target_os = "linux") { if cfg!(target_os = "linux") {

View File

@ -216,7 +216,9 @@ fn shell_command(cmd: &str, config: &CustomConfig, context: &Context) -> Option<
match output.wait().ok()? { match output.wait().ok()? {
None => { None => {
log::warn!("Executing custom command {cmd:?} timed out."); log::warn!("Executing custom command {cmd:?} timed out.");
log::warn!("You can set command_timeout in your config to a higher value or set ignore_timeout to true for this module to allow longer-running commands to keep executing."); log::warn!(
"You can set command_timeout in your config to a higher value or set ignore_timeout to true for this module to allow longer-running commands to keep executing."
);
None None
} }
Some(status) => Some(status), Some(status) => Some(status),
@ -312,7 +314,7 @@ mod tests {
use super::*; use super::*;
use crate::context::Shell; use crate::context::Shell;
use crate::test::{fixture_repo, FixtureProvider, ModuleRenderer}; use crate::test::{FixtureProvider, ModuleRenderer, fixture_repo};
use nu_ansi_term::Color; use nu_ansi_term::Color;
use std::fs::File; use std::fs::File;
use std::io; use std::io;

View File

@ -1,5 +1,5 @@
use quick_xml::events::Event;
use quick_xml::Reader; use quick_xml::Reader;
use quick_xml::events::Event;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::iter::Iterator; use std::iter::Iterator;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -308,7 +308,7 @@ fn get_latest_sdk_from_cli(context: &Context) -> Option<String> {
.lines() .lines()
.map(str::trim) .map(str::trim)
.filter(|l| !l.is_empty()) .filter(|l| !l.is_empty())
.last() .next_back()
.or_else(parse_failed)?; .or_else(parse_failed)?;
let take_until = latest_sdk.find('[').or_else(parse_failed)? - 1; let take_until = latest_sdk.find('[').or_else(parse_failed)? - 1;
if take_until > 1 { if take_until > 1 {
@ -355,7 +355,7 @@ mod tests {
use std::fs::{self, OpenOptions}; use std::fs::{self, OpenOptions};
use std::io::{self, Write}; use std::io::{self, Write};
use tempfile::{self, TempDir}; use tempfile::{self, TempDir};
use utils::{write_file, CommandOutput}; use utils::{CommandOutput, write_file};
#[test] #[test]
fn shows_nothing_in_directory_with_zero_relevant_files() -> io::Result<()> { fn shows_nothing_in_directory_with_zero_relevant_files() -> io::Result<()> {

View File

@ -1,6 +1,6 @@
use super::{Context, Module}; use super::{Context, Module};
use crate::config::{parse_style_string, ModuleConfig}; use crate::config::{ModuleConfig, parse_style_string};
use crate::configs::fill::FillConfig; use crate::configs::fill::FillConfig;
use crate::segment::Segment; use crate::segment::Segment;

View File

@ -78,7 +78,7 @@ mod tests {
use nu_ansi_term::{Color, Style}; use nu_ansi_term::{Color, Style};
use crate::test::{fixture_repo, FixtureProvider, ModuleRenderer}; use crate::test::{FixtureProvider, ModuleRenderer, fixture_repo};
enum Expect<'a> { enum Expect<'a> {
BranchName(&'a str), BranchName(&'a str),

View File

@ -104,7 +104,7 @@ mod tests {
use nu_ansi_term::{Color, Style}; use nu_ansi_term::{Color, Style};
use crate::test::{fixture_repo, FixtureProvider, ModuleRenderer}; use crate::test::{FixtureProvider, ModuleRenderer, fixture_repo};
use super::FossilDiff; use super::FossilDiff;

View File

@ -151,7 +151,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::fs::{create_dir, File}; use std::fs::{File, create_dir};
use std::io::{self, Write}; use std::io::{self, Write};
use nu_ansi_term::Color; use nu_ansi_term::Color;

View File

@ -123,7 +123,7 @@ mod tests {
use nu_ansi_term::Color; use nu_ansi_term::Color;
use std::io; use std::io;
use crate::test::{fixture_repo, FixtureProvider, ModuleRenderer}; use crate::test::{FixtureProvider, ModuleRenderer, fixture_repo};
use crate::utils::create_command; use crate::utils::create_command;
#[test] #[test]

View File

@ -81,7 +81,7 @@ mod tests {
use nu_ansi_term::Color; use nu_ansi_term::Color;
use std::{io, str}; use std::{io, str};
use crate::test::{fixture_repo, FixtureProvider, ModuleRenderer}; use crate::test::{FixtureProvider, ModuleRenderer, fixture_repo};
use crate::utils::create_command; use crate::utils::create_command;
#[test] #[test]

View File

@ -1,8 +1,8 @@
use regex::Regex; use regex::Regex;
use crate::{ use crate::{
config::ModuleConfig, configs::git_metrics::GitMetricsConfig, config::ModuleConfig, configs::git_metrics::GitMetricsConfig, formatter::StringFormatter,
formatter::string_formatter::StringFormatterError, formatter::StringFormatter, module::Module, formatter::string_formatter::StringFormatterError, module::Module,
}; };
use super::Context; use super::Context;

View File

@ -521,7 +521,7 @@ mod tests {
use std::io::{self, prelude::*}; use std::io::{self, prelude::*};
use std::path::Path; use std::path::Path;
use crate::test::{fixture_repo, FixtureProvider, ModuleRenderer}; use crate::test::{FixtureProvider, ModuleRenderer, fixture_repo};
use crate::utils::create_command; use crate::utils::create_command;
#[allow(clippy::unnecessary_wraps)] #[allow(clippy::unnecessary_wraps)]

View File

@ -94,7 +94,7 @@ mod tests {
use std::io; use std::io;
use std::path::Path; use std::path::Path;
use crate::test::{fixture_repo, FixtureProvider, ModuleRenderer}; use crate::test::{FixtureProvider, ModuleRenderer, fixture_repo};
use crate::utils::create_command; use crate::utils::create_command;
enum Expect<'a> { enum Expect<'a> {

View File

@ -47,7 +47,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module_symbol = ""; let mut module_symbol = "";
let mut module_number = String::new(); let mut module_number = String::new();
if config.threshold != default_threshold { if config.threshold != default_threshold {
log::warn!("`threshold` in [jobs] is deprecated . Please remove it and use `symbol_threshold` and `number_threshold`."); log::warn!(
"`threshold` in [jobs] is deprecated . Please remove it and use `symbol_threshold` and `number_threshold`."
);
// The symbol should be shown if there are *any* background // The symbol should be shown if there are *any* background
// jobs running. // jobs running.

View File

@ -349,12 +349,12 @@ mod deprecated {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::modules::kubernetes::parse_kubeconfigs;
use crate::modules::kubernetes::Document; use crate::modules::kubernetes::Document;
use crate::modules::kubernetes::parse_kubeconfigs;
use crate::test::ModuleRenderer; use crate::test::ModuleRenderer;
use nu_ansi_term::Color; use nu_ansi_term::Color;
use std::env; use std::env;
use std::fs::{create_dir, File}; use std::fs::{File, create_dir};
use std::io::{self, Write}; use std::io::{self, Write};
#[test] #[test]

View File

@ -103,9 +103,11 @@ mod tests {
#[test] #[test]
fn is_ipv4_format() { fn is_ipv4_format() {
let localip = get_localip!(); let localip = get_localip!();
assert!(regex::Regex::new(r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$") assert!(
regex::Regex::new(r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$")
.unwrap() .unwrap()
.is_match(&localip)); .is_match(&localip)
);
} }
#[test] #[test]

View File

@ -1,6 +1,6 @@
use systemstat::{ use systemstat::{
data::{saturating_sub_bytes, ByteSize},
Platform, System, Platform, System,
data::{ByteSize, saturating_sub_bytes},
}; };
use super::{Context, Module, ModuleConfig}; use super::{Context, Module, ModuleConfig};

View File

@ -215,7 +215,9 @@ pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
custom::module(custom.strip_prefix("custom.").unwrap(), context) custom::module(custom.strip_prefix("custom.").unwrap(), context)
} }
_ => { _ => {
eprintln!("Error: Unknown module {module}. Use starship module --list to list out all supported modules."); eprintln!(
"Error: Unknown module {module}. Use starship module --list to list out all supported modules."
);
None None
} }
} }

View File

@ -110,7 +110,7 @@ fn parse_opam_switch(opam_switch: &str) -> Option<OpamSwitch> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{parse_opam_switch, SwitchType}; use super::{SwitchType, parse_opam_switch};
use crate::{test::ModuleRenderer, utils::CommandOutput}; use crate::{test::ModuleRenderer, utils::CommandOutput};
use nu_ansi_term::Color; use nu_ansi_term::Color;
use std::fs::{self, File}; use std::fs::{self, File};

View File

@ -32,7 +32,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
.map(|variable| match variable { .map(|variable| match variable {
"version" => { "version" => {
let odin_version = context.exec_cmd("odin", &["version"])?.stdout; let odin_version = context.exec_cmd("odin", &["version"])?.stdout;
let trimmed_version = odin_version.split(' ').last()?.trim().to_string(); let trimmed_version = odin_version.split(' ').next_back()?.trim().to_string();
if config.show_commit { if config.show_commit {
return Some(Ok(trimmed_version)); return Some(Ok(trimmed_version));

View File

@ -318,7 +318,7 @@ mod tests {
#[test] #[test]
fn warn_on_os_info_update() { fn warn_on_os_info_update() {
#[warn(clippy::wildcard_enum_match_arm)] #[deny(clippy::wildcard_enum_match_arm)]
// This closure is the same as the default config symbols list. // This closure is the same as the default config symbols list.
// When this clippy test fails, a new default symbol should be added to // When this clippy test fails, a new default symbol should be added to
// `config/os.rs` to exhaustively match new possible `os_info::Type` cases. // `config/os.rs` to exhaustively match new possible `os_info::Type` cases.
@ -337,6 +337,7 @@ mod tests {
Type::Amazon => "🙂 ", Type::Amazon => "🙂 ",
Type::Android => "🤖 ", Type::Android => "🤖 ",
Type::Arch | Type::Artix | Type::CachyOS => "🎗️ ", Type::Arch | Type::Artix | Type::CachyOS => "🎗️ ",
Type::Bluefin => "🐟 ",
Type::CentOS | Type::AlmaLinux | Type::RockyLinux => "💠 ", Type::CentOS | Type::AlmaLinux | Type::RockyLinux => "💠 ",
Type::Debian => "🌀 ", Type::Debian => "🌀 ",
Type::DragonFly => "🐉 ", Type::DragonFly => "🐉 ",

View File

@ -3,8 +3,8 @@ use crate::configs::package::PackageConfig;
use crate::formatter::{StringFormatter, VersionFormatter}; use crate::formatter::{StringFormatter, VersionFormatter};
use ini::Ini; use ini::Ini;
use quick_xml::events::Event as QXEvent;
use quick_xml::Reader as QXReader; use quick_xml::Reader as QXReader;
use quick_xml::events::Event as QXEvent;
use regex::Regex; use regex::Regex;
use serde_json as json; use serde_json as json;
use std::fs; use std::fs;
@ -571,8 +571,8 @@ license = "MIT"
} }
#[test] #[test]
fn test_extract_nimble_package_version_for_nimble_directory_when_nimble_is_not_available( fn test_extract_nimble_package_version_for_nimble_directory_when_nimble_is_not_available()
) -> io::Result<()> { -> io::Result<()> {
let config_name = "test_project.nimble"; let config_name = "test_project.nimble";
let config_content = r#" let config_content = r#"

View File

@ -76,7 +76,7 @@ mod tests {
use std::io; use std::io;
use std::path::Path; use std::path::Path;
use crate::test::{fixture_repo, FixtureProvider, ModuleRenderer}; use crate::test::{FixtureProvider, ModuleRenderer, fixture_repo};
enum Expect<'a> { enum Expect<'a> {
ChannelName(&'a str), ChannelName(&'a str),

View File

@ -146,7 +146,7 @@ mod tests {
use super::*; use super::*;
use crate::test::ModuleRenderer; use crate::test::ModuleRenderer;
use nu_ansi_term::Color; use nu_ansi_term::Color;
use std::fs::{create_dir_all, File}; use std::fs::{File, create_dir_all};
use std::io; use std::io;
use std::io::Write; use std::io::Write;

View File

@ -3,7 +3,7 @@ use std::string::ToString;
use super::{Context, Module, ModuleConfig}; use super::{Context, Module, ModuleConfig};
use crate::configs::status::StatusConfig; use crate::configs::status::StatusConfig;
use crate::formatter::{string_formatter::StringFormatterError, StringFormatter}; use crate::formatter::{StringFormatter, string_formatter::StringFormatterError};
use crate::segment::Segment; use crate::segment::Segment;
type ExitCode = i32; type ExitCode = i32;

View File

@ -84,7 +84,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
fn is_login_user(context: &Context, username: &str) -> bool { fn is_login_user(context: &Context, username: &str) -> bool {
context context
.get_env("LOGNAME") .get_env("LOGNAME")
.map_or(true, |logname| logname == username) .is_none_or(|logname| logname == username)
} }
#[cfg(all(target_os = "windows", not(test)))] #[cfg(all(target_os = "windows", not(test)))]

View File

@ -1,14 +1,13 @@
use std::{mem, os::windows::ffi::OsStrExt, path::Path}; use std::{mem, os::windows::ffi::OsStrExt, path::Path};
use windows::{ use windows::{
core::PCWSTR,
Win32::{ Win32::{
Foundation::{CloseHandle, BOOL, ERROR_INSUFFICIENT_BUFFER, HANDLE}, Foundation::{CloseHandle, ERROR_INSUFFICIENT_BUFFER, HANDLE},
Security::{ Security::{
AccessCheck, DuplicateToken, GetFileSecurityW, MapGenericMask, SecurityImpersonation, AccessCheck, DACL_SECURITY_INFORMATION, DuplicateToken, GENERIC_MAPPING,
DACL_SECURITY_INFORMATION, GENERIC_MAPPING, GROUP_SECURITY_INFORMATION, GROUP_SECURITY_INFORMATION, GetFileSecurityW, MapGenericMask,
OWNER_SECURITY_INFORMATION, PRIVILEGE_SET, PSECURITY_DESCRIPTOR, TOKEN_DUPLICATE, OWNER_SECURITY_INFORMATION, PRIVILEGE_SET, PSECURITY_DESCRIPTOR, SecurityImpersonation,
TOKEN_IMPERSONATE, TOKEN_QUERY, TOKEN_READ_CONTROL, TOKEN_DUPLICATE, TOKEN_IMPERSONATE, TOKEN_QUERY, TOKEN_READ_CONTROL,
}, },
Storage::FileSystem::{ Storage::FileSystem::{
FILE_ALL_ACCESS, FILE_GENERIC_EXECUTE, FILE_GENERIC_READ, FILE_GENERIC_WRITE, FILE_ALL_ACCESS, FILE_GENERIC_EXECUTE, FILE_GENERIC_READ, FILE_GENERIC_WRITE,
@ -16,6 +15,7 @@ use windows::{
System::Threading::{GetCurrentProcess, OpenProcessToken}, System::Threading::{GetCurrentProcess, OpenProcessToken},
UI::Shell::PathIsNetworkPathW, UI::Shell::PathIsNetworkPathW,
}, },
core::{BOOL, PCWSTR},
}; };
struct Handle(HANDLE); struct Handle(HANDLE);
@ -60,7 +60,11 @@ pub fn is_write_allowed(folder_path: &Path) -> std::result::Result<bool, String>
// expect ERROR_INSUFFICIENT_BUFFER // expect ERROR_INSUFFICIENT_BUFFER
match rc.ok() { match rc.ok() {
Err(e) if e.code() == ERROR_INSUFFICIENT_BUFFER.into() => (), Err(e) if e.code() == ERROR_INSUFFICIENT_BUFFER.into() => (),
result => return Err(format!("GetFileSecurityW returned unexpected return value when asked for the security descriptor size: {result:?}")), result => {
return Err(format!(
"GetFileSecurityW returned unexpected return value when asked for the security descriptor size: {result:?}"
));
}
} }
let mut buf = vec![0u8; length as usize]; let mut buf = vec![0u8; length as usize];

View File

@ -1,4 +1,4 @@
use clap::{builder::PossibleValue, ValueEnum}; use clap::{ValueEnum, builder::PossibleValue};
use nu_ansi_term::AnsiStrings; use nu_ansi_term::AnsiStrings;
use rayon::prelude::*; use rayon::prelude::*;
use std::collections::BTreeSet; use std::collections::BTreeSet;
@ -13,8 +13,8 @@ use unicode_width::UnicodeWidthChar;
use crate::configs::PROMPT_ORDER; use crate::configs::PROMPT_ORDER;
use crate::context::{Context, Properties, Shell, Target}; use crate::context::{Context, Properties, Shell, Target};
use crate::formatter::{StringFormatter, VariableHolder}; use crate::formatter::{StringFormatter, VariableHolder};
use crate::module::Module;
use crate::module::ALL_MODULES; use crate::module::ALL_MODULES;
use crate::module::Module;
use crate::modules; use crate::modules;
use crate::segment::Segment; use crate::segment::Segment;
use crate::shadow; use crate::shadow;

View File

@ -45,11 +45,7 @@ impl FillSegment {
.cycle() .cycle()
.scan(0usize, |len, g| { .scan(0usize, |len, g| {
*len += Grapheme(g).width(); *len += Grapheme(g).width();
if *len <= w { if *len <= w { Some(g) } else { None }
Some(g)
} else {
None
}
}) })
.collect::<String>(), .collect::<String>(),
None => String::from(&self.value), None => String::from(&self.value),

View File

@ -1,7 +1,7 @@
use crate::module::ALL_MODULES; use crate::module::ALL_MODULES;
use serde::de::{ use serde::de::{
value::{Error as ValueError, MapDeserializer, SeqDeserializer},
Deserializer, Error, IntoDeserializer, Visitor, Deserializer, Error, IntoDeserializer, Visitor,
value::{Error as ValueError, MapDeserializer, SeqDeserializer},
}; };
use std::{cmp::Ordering, fmt}; use std::{cmp::Ordering, fmt};
use toml::Value; use toml::Value;

View File

@ -2,7 +2,7 @@ use crate::context::{Context, Shell, Target};
use crate::logger::StarshipLogger; use crate::logger::StarshipLogger;
use crate::{ use crate::{
config::StarshipConfig, config::StarshipConfig,
utils::{create_command, CommandOutput}, utils::{CommandOutput, create_command},
}; };
use log::{Level, LevelFilter}; use log::{Level, LevelFilter};
use std::fs; use std::fs;

View File

@ -163,7 +163,7 @@ pub fn mock_cmd<T: AsRef<OsStr> + Debug, U: AsRef<OsStr> + Debug>(
) -> Option<Option<CommandOutput>> { ) -> Option<Option<CommandOutput>> {
let command = display_command(&cmd, args); let command = display_command(&cmd, args);
let out = match command.as_str() { let out = match command.as_str() {
"bun --version"=> Some(CommandOutput { "bun --version" => Some(CommandOutput {
stdout: String::from("0.1.4\n"), stdout: String::from("0.1.4\n"),
stderr: String::default(), stderr: String::default(),
}), }),
@ -172,31 +172,38 @@ pub fn mock_cmd<T: AsRef<OsStr> + Debug, U: AsRef<OsStr> + Debug>(
stderr: String::default(), stderr: String::default(),
}), }),
"cc --version" => Some(CommandOutput { "cc --version" => Some(CommandOutput {
stdout: String::from("\ stdout: String::from(
"\
FreeBSD clang version 11.0.1 (git@github.com:llvm/llvm-project.git llvmorg-11.0.1-0-g43ff75f2c3fe) FreeBSD clang version 11.0.1 (git@github.com:llvm/llvm-project.git llvmorg-11.0.1-0-g43ff75f2c3fe)
Target: x86_64-unknown-freebsd13.0 Target: x86_64-unknown-freebsd13.0
Thread model: posix Thread model: posix
InstalledDir: /usr/bin"), InstalledDir: /usr/bin",
),
stderr: String::default(), stderr: String::default(),
}), }),
"gcc --version" => Some(CommandOutput { "gcc --version" => Some(CommandOutput {
stdout: String::from("\ stdout: String::from(
"\
cc (Debian 10.2.1-6) 10.2.1 20210110 cc (Debian 10.2.1-6) 10.2.1 20210110
Copyright (C) 2020 Free Software Foundation, Inc. Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."), warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.",
),
stderr: String::default(), stderr: String::default(),
}), }),
"clang --version" => Some(CommandOutput { "clang --version" => Some(CommandOutput {
stdout: String::from("\ stdout: String::from(
"\
OpenBSD clang version 11.1.0 OpenBSD clang version 11.1.0
Target: amd64-unknown-openbsd7.0 Target: amd64-unknown-openbsd7.0
Thread model: posix Thread model: posix
InstalledDir: /usr/bin"), InstalledDir: /usr/bin",
),
stderr: String::default(), stderr: String::default(),
}), }),
"cobc -version" => Some(CommandOutput { "cobc -version" => Some(CommandOutput {
stdout: String::from("\ stdout: String::from(
"\
cobc (GnuCOBOL) 3.1.2.0 cobc (GnuCOBOL) 3.1.2.0
Copyright (C) 2020 Free Software Foundation, Inc. Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html> License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
@ -205,7 +212,8 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart
Built Dec 24 2020 19:08:58 Built Dec 24 2020 19:08:58
Packaged Dec 23 2020 12:04:58 UTC Packaged Dec 23 2020 12:04:58 UTC
C version \"10.2.0\""), C version \"10.2.0\"",
),
stderr: String::default(), stderr: String::default(),
}), }),
"crystal --version" => Some(CommandOutput { "crystal --version" => Some(CommandOutput {
@ -226,7 +234,7 @@ Default target: x86_64-apple-macosx\n",
}), }),
"deno -V" => Some(CommandOutput { "deno -V" => Some(CommandOutput {
stdout: String::from("deno 1.8.3\n"), stdout: String::from("deno 1.8.3\n"),
stderr: String::default() stderr: String::default(),
}), }),
"dummy_command" => Some(CommandOutput { "dummy_command" => Some(CommandOutput {
stdout: String::from("stdout ok!\n"), stdout: String::from("stdout ok!\n"),
@ -249,21 +257,23 @@ Elixir 1.10 (compiled with Erlang/OTP 22)\n",
stdout: String::from("Fennel 1.2.1 on PUC Lua 5.4\n"), stdout: String::from("Fennel 1.2.1 on PUC Lua 5.4\n"),
stderr: String::default(), stderr: String::default(),
}), }),
"fossil branch current" => Some(CommandOutput{ "fossil branch current" => Some(CommandOutput {
stdout: String::from("topic-branch"), stdout: String::from("topic-branch"),
stderr: String::default(), stderr: String::default(),
}), }),
"fossil branch new topic-branch trunk" => Some(CommandOutput{ "fossil branch new topic-branch trunk" => Some(CommandOutput {
stdout: String::default(), stdout: String::default(),
stderr: String::default(), stderr: String::default(),
}), }),
"fossil diff -i --numstat" => Some(CommandOutput{ "fossil diff -i --numstat" => Some(CommandOutput {
stdout: String::from("\ stdout: String::from(
"\
3 2 README.md 3 2 README.md
3 2 TOTAL over 1 changed files"), 3 2 TOTAL over 1 changed files",
),
stderr: String::default(), stderr: String::default(),
}), }),
"fossil update topic-branch" => Some(CommandOutput{ "fossil update topic-branch" => Some(CommandOutput {
stdout: String::default(), stdout: String::default(),
stderr: String::default(), stderr: String::default(),
}), }),
@ -284,7 +294,9 @@ Elixir 1.10 (compiled with Erlang/OTP 22)\n",
stderr: String::default(), stderr: String::default(),
}), }),
s if s.ends_with("java -Xinternalversion") => Some(CommandOutput { s if s.ends_with("java -Xinternalversion") => Some(CommandOutput {
stdout: String::from("OpenJDK 64-Bit Server VM (13.0.2+8) for bsd-amd64 JRE (13.0.2+8), built on Feb 6 2020 02:07:52 by \"brew\" with clang 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.17)"), stdout: String::from(
"OpenJDK 64-Bit Server VM (13.0.2+8) for bsd-amd64 JRE (13.0.2+8), built on Feb 6 2020 02:07:52 by \"brew\" with clang 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.17)",
),
stderr: String::default(), stderr: String::default(),
}), }),
"scala-cli version --scala" => Some(CommandOutput { "scala-cli version --scala" => Some(CommandOutput {
@ -292,7 +304,9 @@ Elixir 1.10 (compiled with Erlang/OTP 22)\n",
stderr: String::default(), stderr: String::default(),
}), }),
"scalac -version" => Some(CommandOutput { "scalac -version" => Some(CommandOutput {
stdout: String::from("Scala compiler version 2.13.5 -- Copyright 2002-2020, LAMP/EPFL and Lightbend, Inc."), stdout: String::from(
"Scala compiler version 2.13.5 -- Copyright 2002-2020, LAMP/EPFL and Lightbend, Inc.",
),
stderr: String::default(), stderr: String::default(),
}), }),
"julia --version" => Some(CommandOutput { "julia --version" => Some(CommandOutput {
@ -307,19 +321,21 @@ Elixir 1.10 (compiled with Erlang/OTP 22)\n",
stdout: String::from("info: kotlinc-jvm 1.4.21 (JRE 14.0.1+7)\n"), stdout: String::from("info: kotlinc-jvm 1.4.21 (JRE 14.0.1+7)\n"),
stderr: String::default(), stderr: String::default(),
}), }),
"lua -v" => Some(CommandOutput{ "lua -v" => Some(CommandOutput {
stdout: String::from("Lua 5.4.0 Copyright (C) 1994-2020 Lua.org, PUC-Rio\n"), stdout: String::from("Lua 5.4.0 Copyright (C) 1994-2020 Lua.org, PUC-Rio\n"),
stderr: String::default(), stderr: String::default(),
}), }),
"luajit -v" => Some(CommandOutput{ "luajit -v" => Some(CommandOutput {
stdout: String::from("LuaJIT 2.0.5 -- Copyright (C) 2005-2017 Mike Pall. http://luajit.org/\n"), stdout: String::from(
"LuaJIT 2.0.5 -- Copyright (C) 2005-2017 Mike Pall. http://luajit.org/\n",
),
stderr: String::default(), stderr: String::default(),
}), }),
"mojo --version" => Some(CommandOutput { "mojo --version" => Some(CommandOutput {
stdout: String::from("mojo 24.4.0 (2cb57382)\n"), stdout: String::from("mojo 24.4.0 (2cb57382)\n"),
stderr: String::default(), stderr: String::default(),
}), }),
"nats context info --json" => Some(CommandOutput{ "nats context info --json" => Some(CommandOutput {
stdout: String::from("{\"name\":\"localhost\",\"url\":\"nats://localhost:4222\"}"), stdout: String::from("{\"name\":\"localhost\",\"url\":\"nats://localhost:4222\"}"),
stderr: String::default(), stderr: String::default(),
}), }),
@ -347,14 +363,16 @@ active boot switches: -d:release\n",
stderr: String::default(), stderr: String::default(),
}), }),
"opa version" => Some(CommandOutput { "opa version" => Some(CommandOutput {
stdout: String::from("Version: 0.44.0 stdout: String::from(
"Version: 0.44.0
Build Commit: e8d488f Build Commit: e8d488f
Build Timestamp: 2022-09-07T23:50:25Z Build Timestamp: 2022-09-07T23:50:25Z
Build Hostname: 119428673f4c Build Hostname: 119428673f4c
Go Version: go1.19.1 Go Version: go1.19.1
Platform: linux/amd64 Platform: linux/amd64
WebAssembly: unavailable WebAssembly: unavailable
"), ",
),
stderr: String::default(), stderr: String::default(),
}), }),
"opam switch show --safe" => Some(CommandOutput { "opam switch show --safe" => Some(CommandOutput {
@ -379,20 +397,20 @@ WebAssembly: unavailable
stdout: String::from("7.3.8"), stdout: String::from("7.3.8"),
stderr: String::default(), stderr: String::default(),
}) })
}, }
"pijul channel" => Some(CommandOutput{ "pijul channel" => Some(CommandOutput {
stdout: String::from(" main\n* tributary-48198"), stdout: String::from(" main\n* tributary-48198"),
stderr: String::default(), stderr: String::default(),
}), }),
"pijul channel new tributary-48198" => Some(CommandOutput{ "pijul channel new tributary-48198" => Some(CommandOutput {
stdout: String::default(), stdout: String::default(),
stderr: String::default(), stderr: String::default(),
}), }),
"pijul channel switch tributary-48198" => Some(CommandOutput{ "pijul channel switch tributary-48198" => Some(CommandOutput {
stdout: String::from("Outputting repository ↖"), stdout: String::from("Outputting repository ↖"),
stderr: String::default(), stderr: String::default(),
}), }),
"pulumi version" => Some(CommandOutput{ "pulumi version" => Some(CommandOutput {
stdout: String::from("1.2.3-ver.1631311768+e696fb6c"), stdout: String::from("1.2.3-ver.1631311768+e696fb6c"),
stderr: String::default(), stderr: String::default(),
}), }),
@ -428,7 +446,7 @@ R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3. GNU General Public License versions 2 or 3.
For more information about these matters see For more information about these matters see
https://www.gnu.org/licenses/."# https://www.gnu.org/licenses/."#,
), ),
}), }),
"raku --version" => Some(CommandOutput { "raku --version" => Some(CommandOutput {
@ -442,20 +460,23 @@ Built on MoarVM version 2021.12.\n",
}), }),
"red --version" => Some(CommandOutput { "red --version" => Some(CommandOutput {
stdout: String::from("0.6.4\n"), stdout: String::from("0.6.4\n"),
stderr: String::default() stderr: String::default(),
}), }),
"ruby -v" => Some(CommandOutput { "ruby -v" => Some(CommandOutput {
stdout: String::from("ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]\n"), stdout: String::from("ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]\n"),
stderr: String::default(), stderr: String::default(),
}), }),
"solc --version" => Some(CommandOutput { "solc --version" => Some(CommandOutput {
stdout: String::from("solc, the solidity compiler commandline interface stdout: String::from(
Version: 0.8.16+commit.07a7930e.Linux.g++"), "solc, the solidity compiler commandline interface
Version: 0.8.16+commit.07a7930e.Linux.g++",
),
stderr: String::default(), stderr: String::default(),
}), }),
"solcjs --version" => Some(CommandOutput { "solcjs --version" => Some(CommandOutput {
stdout: String::from("0.8.15+commit.e14f2714.Emscripten.clang"), stdout: String::from("0.8.15+commit.e14f2714.Emscripten.clang"),
stderr: String::default() }), stderr: String::default(),
}),
"swift --version" => Some(CommandOutput { "swift --version" => Some(CommandOutput {
stdout: String::from( stdout: String::from(
"\ "\
@ -470,7 +491,7 @@ Target: x86_64-apple-darwin19.4.0\n",
}), }),
"v version" => Some(CommandOutput { "v version" => Some(CommandOutput {
stdout: String::from("V 0.2 30c0659"), stdout: String::from("V 0.2 30c0659"),
stderr: String::default() stderr: String::default(),
}), }),
"zig version" => Some(CommandOutput { "zig version" => Some(CommandOutput {
stdout: String::from("0.6.0\n"), stdout: String::from("0.6.0\n"),
@ -610,7 +631,9 @@ pub fn exec_timeout(cmd: &mut Command, time_limit: Duration) -> Option<CommandOu
} }
Ok(None) => { Ok(None) => {
log::warn!("Executing command {:?} timed out.", cmd.get_program()); log::warn!("Executing command {:?} timed out.", cmd.get_program());
log::warn!("You can set command_timeout in your config to a higher value to allow longer-running commands to keep executing."); log::warn!(
"You can set command_timeout in your config to a higher value to allow longer-running commands to keep executing."
);
None None
} }
Err(error) => { Err(error) => {