Merge branch 'master' into conditional-style

This commit is contained in:
Filip Bachul 2023-01-12 20:38:20 +01:00
commit 0d8a603dbd
9 changed files with 222 additions and 152 deletions

View File

@ -1751,6 +1751,13 @@
"type": "string"
}
}
},
"profiles": {
"default": {},
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"additionalProperties": false,

190
Cargo.lock generated
View File

@ -868,9 +868,9 @@ dependencies = [
[[package]]
name = "git-actor"
version = "0.16.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "599cb75eb7c3bf03149b7ab70c66bc0b9a432a092b1154b49d21b49fc7e4bd93"
checksum = "d9e5fd7bc63ad527d64584f8d01f99b89c051f5fbb8144b58ae5f812775065cf"
dependencies = [
"bstr",
"btoi",
@ -882,9 +882,9 @@ dependencies = [
[[package]]
name = "git-attributes"
version = "0.8.0"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8013dfce47c1e29236d732308933e2c77af5355ec5105755d26faf7764d3f7b"
checksum = "b2c9687a890892650e8574e123b4b633d277b99953cb877dc02aba852a0139fa"
dependencies = [
"bstr",
"compact_str",
@ -925,9 +925,9 @@ dependencies = [
[[package]]
name = "git-config"
version = "0.14.0"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1b95089db62159d7d24c13ddfb4bf949c508521d0bb25331744ef500295ceb8"
checksum = "500cc0517781f9f573c4dc26feb3ae0cdc28ae7160a81ef104590943984f6a8e"
dependencies = [
"bstr",
"git-config-value",
@ -975,9 +975,9 @@ dependencies = [
[[package]]
name = "git-date"
version = "0.3.1"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a2874ce2f3a77cb144167901ea830969e5c991eac7bfee85e6e3f53ef9fcdf2"
checksum = "3777ed3a92334193bc5032d468dee2ddb7d1101263e58e0d2edcc308c06948b5"
dependencies = [
"bstr",
"itoa",
@ -987,9 +987,9 @@ dependencies = [
[[package]]
name = "git-diff"
version = "0.25.0"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8ae775956f509fe115b173d79e539f97539d40c1d5c5c63a61d10eaf79c857a"
checksum = "ca87474422d26d606d04cec6bedfabcd92a0a74102cd7936785358ced6a4a25a"
dependencies = [
"git-hash",
"git-object",
@ -999,9 +999,9 @@ dependencies = [
[[package]]
name = "git-discover"
version = "0.11.0"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aab20ca6af631c2bb10d59e63377ca9c9c74908586e6018ab15377967432e68b"
checksum = "a2738a9941f1411cff31e6ea4399a6c7304cc3ea34fb8c1c6f1aef1f667d46cc"
dependencies = [
"bstr",
"git-hash",
@ -1013,9 +1013,9 @@ dependencies = [
[[package]]
name = "git-features"
version = "0.26.0"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ff74064fa007c5beefa89a64bb72834f32b3c497750a56c79c6802bbdb311f9"
checksum = "0019327672cb759f851d1b18fdcc36bb797dc62b925cb93c8c881b54735eb2c2"
dependencies = [
"crc32fast",
"crossbeam-channel",
@ -1036,9 +1036,9 @@ dependencies = [
[[package]]
name = "git-glob"
version = "0.5.1"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3908404c9b76ac7b3f636a104142378d3eaa78623cbc6eb7c7f0651979d48e8a"
checksum = "aa73cf9c9c1a66e28de1cf250fc1ebe323e7c7c59768c1a2331e3b3308e783a3"
dependencies = [
"bitflags",
"bstr",
@ -1066,9 +1066,9 @@ dependencies = [
[[package]]
name = "git-index"
version = "0.11.0"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "430f5d9302a2dd5e50b6b04a3b9d0df6b3423e55908fde18333fe9cd51312027"
checksum = "b82fd3d70ed6fbceb7573f145fbf79371e4d0c8dbdf7ad46f3a03328239ddda7"
dependencies = [
"atoi",
"bitflags",
@ -1099,9 +1099,9 @@ dependencies = [
[[package]]
name = "git-mailmap"
version = "0.8.0"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "396cef08d4ec18ea35fed043f5b003e46957603a01349dd429a4773c146fefca"
checksum = "1957f2f550e345f70cb0615d390fb0446d41eeb5bc87824b7bae31efd8cfc2da"
dependencies = [
"bstr",
"git-actor",
@ -1110,9 +1110,9 @@ dependencies = [
[[package]]
name = "git-object"
version = "0.25.0"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fad6c2ddb376b99172dc8b651e11be4cb49cef423de4fad563ebbda4fee3fcf6"
checksum = "3f8563e2d6f524d7053f3106714f99ecdc3adbba2cb7108c09d71a02579f2e19"
dependencies = [
"bstr",
"btoi",
@ -1129,9 +1129,9 @@ dependencies = [
[[package]]
name = "git-odb"
version = "0.39.0"
version = "0.40.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84ea84e47ae48b95e108664d2991013507694b1b722e4183ed1c9309251b9b10"
checksum = "b43514e1d1062613352a10f96d48e69967f4c420776596e1af9a6f368df2eea2"
dependencies = [
"arc-swap",
"git-features",
@ -1147,9 +1147,9 @@ dependencies = [
[[package]]
name = "git-pack"
version = "0.29.0"
version = "0.30.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "692e9c78c57212aa76c71be9a319f80d42fe8191735b3aff5b97b8f034295774"
checksum = "9e124d13e4e4b53ca7544e9786f30dafe2e76b4a75ba62b2156ee0656b356c71"
dependencies = [
"bytesize",
"clru",
@ -1182,9 +1182,9 @@ dependencies = [
[[package]]
name = "git-prompt"
version = "0.3.0"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3612a486e507dd431ef0f7108eeaafc8fd1ed7bd0f205a88554f6f91fe5dccbf"
checksum = "ad3f84ec28896f6a4b3f3174a1125117ac91788b1c64d96f25eabcd8d01cc7e3"
dependencies = [
"git-command",
"git-config-value",
@ -1206,9 +1206,9 @@ dependencies = [
[[package]]
name = "git-ref"
version = "0.22.0"
version = "0.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b351af399166a5506369e36389d6b9aee744cfa672d0e2ea93d2b01223b1cfbe"
checksum = "2a2c29bab109acaf626d49a54f1f85ab7f0911268fbf62c2b39680ef4ef19069"
dependencies = [
"git-actor",
"git-features",
@ -1225,9 +1225,9 @@ dependencies = [
[[package]]
name = "git-refspec"
version = "0.6.0"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcf699f310ba8530708f599b1ce730eb557ebc0af1a1a57b882ce3d685571092"
checksum = "419fba469ca7dca4746de8b2be6a21990b276f3974acaa94314f39d4c2bbfc0a"
dependencies = [
"bstr",
"git-hash",
@ -1239,9 +1239,9 @@ dependencies = [
[[package]]
name = "git-repository"
version = "0.31.0"
version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9e21852e326233c5f3f034a44b66215c166506e5ccf227de7e28ccdfbcfb47a"
checksum = "1a958d3fa83660d15c6535765477a8895156bdd6a922dbd0fc445afa42f4b534"
dependencies = [
"git-actor",
"git-attributes",
@ -1282,9 +1282,9 @@ dependencies = [
[[package]]
name = "git-revision"
version = "0.9.0"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b64c0d2e37eb24c8897d11a2f77371a817c3d40dc744d4a2f048f33236eef6b"
checksum = "bfc3f7c901777f8318f059dbdf73dbda05acdb36c631fe12465bd955e230a205"
dependencies = [
"bstr",
"git-date",
@ -1296,15 +1296,15 @@ dependencies = [
[[package]]
name = "git-sec"
version = "0.6.0"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e1802e8252fa223b0ad89a393aed461132174ced1e6842a41f56dc92a3fc14f"
checksum = "6696a816445a51f76995d579a3122f98247377cc45cd681764f740f3a2666004"
dependencies = [
"bitflags",
"dirs 4.0.0",
"git-path",
"libc",
"windows 0.40.0",
"windows 0.43.0",
]
[[package]]
@ -1323,9 +1323,9 @@ dependencies = [
[[package]]
name = "git-traverse"
version = "0.21.0"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43b91ed45b561161ba56b85a83865825b7d17a6b1c6f981e831a78b93cf2cc5f"
checksum = "bd356da21ec00f69b9d4f105df4cb85543c746b18f4b7fc81529ce77713cdb29"
dependencies = [
"git-hash",
"git-hashtable",
@ -1335,9 +1335,9 @@ dependencies = [
[[package]]
name = "git-url"
version = "0.13.0"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c85af407ed0dbb8d8da2a7241827d2fd5681186d9dab3570fc8dd8d6152ec48f"
checksum = "cc9a3df0498c511cf34739eab2692352939b54075c2fc96e8f688d402f3f1250"
dependencies = [
"bstr",
"git-features",
@ -1359,9 +1359,9 @@ dependencies = [
[[package]]
name = "git-worktree"
version = "0.11.0"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffc45b5ac445d0f8719def12303f037966f810cf399ebe0daf29217865df9a49"
checksum = "0c28b292694c98bba8225c39d4e86605843882ba7117ca98491841761e710547"
dependencies = [
"bstr",
"git-attributes",
@ -2093,9 +2093,9 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
name = "pest"
version = "2.5.2"
version = "2.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f6e86fb9e7026527a0d46bc308b841d73170ef8f443e1807f6ef88526a816d4"
checksum = "4257b4a04d91f7e9e6290be5d3da4804dd5784fafde3a497d73eb2b4a158c30a"
dependencies = [
"thiserror",
"ucd-trie",
@ -2103,9 +2103,9 @@ dependencies = [
[[package]]
name = "pest_derive"
version = "2.5.2"
version = "2.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96504449aa860c8dcde14f9fba5c58dc6658688ca1fe363589d6327b8662c603"
checksum = "241cda393b0cdd65e62e07e12454f1f25d57017dcc514b1514cd3c4645e3a0a6"
dependencies = [
"pest",
"pest_generator",
@ -2113,9 +2113,9 @@ dependencies = [
[[package]]
name = "pest_generator"
version = "2.5.2"
version = "2.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "798e0220d1111ae63d66cb66a5dcb3fc2d986d520b98e49e1852bfdb11d7c5e7"
checksum = "46b53634d8c8196302953c74d5352f33d0c512a9499bd2ce468fc9f4128fa27c"
dependencies = [
"pest",
"pest_meta",
@ -2126,13 +2126,13 @@ dependencies = [
[[package]]
name = "pest_meta"
version = "2.5.2"
version = "2.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "984298b75898e30a843e278a9f2452c31e349a073a0ce6fd950a12a74464e065"
checksum = "0ef4f1332a8d4678b41966bb4cc1d0676880e84183a1ecc3f4b69f03e99c7a51"
dependencies = [
"once_cell",
"pest",
"sha1",
"sha2 0.10.6",
]
[[package]]
@ -2467,9 +2467,9 @@ dependencies = [
[[package]]
name = "regex"
version = "1.7.0"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a"
checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
dependencies = [
"aho-corasick",
"memchr",
@ -2690,6 +2690,17 @@ dependencies = [
"opaque-debug",
]
[[package]]
name = "sha2"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0"
dependencies = [
"cfg-if 1.0.0",
"cpufeatures",
"digest 0.10.6",
]
[[package]]
name = "shadow-rs"
version = "0.20.0"
@ -3002,7 +3013,7 @@ dependencies = [
"ordered-float",
"regex",
"semver 0.11.0",
"sha2",
"sha2 0.9.9",
"signal-hook 0.1.17",
"terminfo",
"termios",
@ -3423,33 +3434,18 @@ dependencies = [
"windows_x86_64_msvc 0.39.0",
]
[[package]]
name = "windows"
version = "0.40.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e30acc718a52fb130fec72b1cb5f55ffeeec9253e1b785e94db222178a6acaa1"
dependencies = [
"windows_aarch64_gnullvm 0.40.0",
"windows_aarch64_msvc 0.40.0",
"windows_i686_gnu 0.40.0",
"windows_i686_msvc 0.40.0",
"windows_x86_64_gnu 0.40.0",
"windows_x86_64_gnullvm 0.40.0",
"windows_x86_64_msvc 0.40.0",
]
[[package]]
name = "windows"
version = "0.43.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04662ed0e3e5630dfa9b26e4cb823b817f1a9addda855d973a9458c236556244"
dependencies = [
"windows_aarch64_gnullvm 0.42.0",
"windows_aarch64_gnullvm",
"windows_aarch64_msvc 0.42.0",
"windows_i686_gnu 0.42.0",
"windows_i686_msvc 0.42.0",
"windows_x86_64_gnu 0.42.0",
"windows_x86_64_gnullvm 0.42.0",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc 0.42.0",
]
@ -3472,21 +3468,15 @@ version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
dependencies = [
"windows_aarch64_gnullvm 0.42.0",
"windows_aarch64_gnullvm",
"windows_aarch64_msvc 0.42.0",
"windows_i686_gnu 0.42.0",
"windows_i686_msvc 0.42.0",
"windows_x86_64_gnu 0.42.0",
"windows_x86_64_gnullvm 0.42.0",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc 0.42.0",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.40.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3caa4a1a16561b714323ca6b0817403738583033a6a92e04c5d10d4ba37ca10"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.0"
@ -3505,12 +3495,6 @@ version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec7711666096bd4096ffa835238905bb33fb87267910e154b18b44eaabb340f2"
[[package]]
name = "windows_aarch64_msvc"
version = "0.40.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "328973c62dfcc50fb1aaa8e7100676e0b642fe56bac6bafff3327902db843ab4"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.0"
@ -3529,12 +3513,6 @@ version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "763fc57100a5f7042e3057e7e8d9bdd7860d330070251a73d003563a3bb49e1b"
[[package]]
name = "windows_i686_gnu"
version = "0.40.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa5b09fad70f0df85dea2ac2a525537e415e2bf63ee31cf9b8e263645ee9f3c1"
[[package]]
name = "windows_i686_gnu"
version = "0.42.0"
@ -3553,12 +3531,6 @@ version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7bc7cbfe58828921e10a9f446fcaaf649204dcfe6c1ddd712c5eebae6bda1106"
[[package]]
name = "windows_i686_msvc"
version = "0.40.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a1ad4031c1a98491fa195d8d43d7489cb749f135f2e5c4eed58da094bd0d876"
[[package]]
name = "windows_i686_msvc"
version = "0.42.0"
@ -3577,24 +3549,12 @@ version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6868c165637d653ae1e8dc4d82c25d4f97dd6605eaa8d784b5c6e0ab2a252b65"
[[package]]
name = "windows_x86_64_gnu"
version = "0.40.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "520ff37edd72da8064b49d2281182898e17f0688ae9f4070bca27e4b5c162ac7"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.40.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "046e5b82215102c44fd75f488f1b9158973d02aa34d06ed85c23d6f5520a2853"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.0"
@ -3613,12 +3573,6 @@ version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e4d40883ae9cae962787ca76ba76390ffa29214667a111db9e0a1ad8377e809"
[[package]]
name = "windows_x86_64_msvc"
version = "0.40.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a0c9c6df55dd1bfa76e131cef44bdd8ec9c819ef3611f04dfe453fd5bfeda28"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.0"

View File

@ -48,9 +48,9 @@ clap_complete = "4.0.7"
dirs-next = "2.0.0"
dunce = "1.0.3"
gethostname = "0.4.1"
git-features = { version = "0.26.0", optional = true }
git-features = { version = "0.26.1", optional = true }
# default feature restriction addresses https://github.com/starship/starship/issues/4251
git-repository = { version = "0.31.0", default-features = false, features = ["max-performance-safe"] }
git-repository = { version = "0.33.0", default-features = false, features = ["max-performance-safe"] }
indexmap = { version = "1.9.2", features = ["serde"] }
log = { version = "0.4.17", features = ["std"] }
# nofity-rust is optional (on by default) because the crate doesn't currently build for darwin with nix
@ -62,12 +62,12 @@ open = "3.2.0"
# update os module config and tests when upgrading os_info
os_info = "3.5.1"
path-slash = "0.2.1"
pest = "2.5.2"
pest_derive = "2.5.2"
pest = "2.5.3"
pest_derive = "2.5.3"
quick-xml = "0.27.1"
rand = "0.8.5"
rayon = "1.6.1"
regex = "1.7.0"
regex = "1.7.1"
rust-ini = "0.18.0"
semver = "1.0.16"
serde = { version = "1.0.152", features = ["derive"] }

View File

@ -1,3 +1,4 @@
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
@ -20,6 +21,7 @@ pub struct StarshipRootConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub palette: Option<String>,
pub palettes: HashMap<String, Palette>,
pub profiles: IndexMap<String, String>,
}
pub type Palette = HashMap<String, String>;
@ -125,6 +127,7 @@ impl Default for StarshipRootConfig {
format: "$all".to_string(),
right_format: String::new(),
continuation_prompt: "[∙](bright-black) ".to_string(),
profiles: Default::default(),
scan_timeout: 30,
command_timeout: 500,
add_newline: true,

View File

@ -647,11 +647,12 @@ pub enum Shell {
}
/// Which kind of prompt target to print (main prompt, rprompt, ...)
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Target {
Main,
Right,
Continuation,
Profile(String),
}
/// Properties as passed on from the shell as arguments

View File

@ -85,8 +85,11 @@ enum Commands {
/// Print the right prompt (instead of the standard left prompt)
#[clap(long)]
right: bool,
/// Print the continuation prompt (instead of the standard left prompt)
/// Print the prompt with the specified profile name (instead of the standard left prompt)
#[clap(long, conflicts_with = "right")]
profile: Option<String>,
/// Print the continuation prompt (instead of the standard left prompt)
#[clap(long, conflicts_with = "right", conflicts_with = "profile")]
continuation: bool,
#[clap(flatten)]
properties: Properties,
@ -172,12 +175,14 @@ fn main() {
Commands::Prompt {
properties,
right,
profile,
continuation,
} => {
let target = match (right, continuation) {
(true, _) => Target::Right,
(_, true) => Target::Continuation,
(_, _) => Target::Main,
let target = match (right, profile, continuation) {
(true, _, _) => Target::Right,
(_, Some(profile_name), _) => Target::Profile(profile_name),
(_, _, true) => Target::Continuation,
(_, _, _) => Target::Main,
};
print::prompt(properties, target)
}

View File

@ -802,10 +802,14 @@ aws_secret_access_key=dummy
#[test]
fn missing_any_credentials() -> io::Result<()> {
let dir = tempfile::tempdir()?;
let config_path = dir.path().join("config");
let mut file = File::create(&config_path)?;
file.write_all(
let credential_path = dir.path().join("credentials");
File::create(&credential_path)?;
let config_path = dir.path().join("config");
let mut config_file = File::create(&config_path)?;
config_file.write_all(
"[default]
region = us-east-1
output = json
@ -818,6 +822,10 @@ region = us-east-2
let actual = ModuleRenderer::new("aws")
.env("AWS_CONFIG_FILE", config_path.to_string_lossy().as_ref())
.env(
"AWS_CREDENTIALS_FILE",
credential_path.to_string_lossy().as_ref(),
)
.collect();
let expected = None;

View File

@ -45,7 +45,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
"style" => {
let engines_version = get_engines_version(context);
let in_engines_range =
check_engines_version(nodejs_version.deref().as_ref()?, engines_version);
check_engines_version(nodejs_version.as_deref(), engines_version);
if in_engines_range {
Some(Ok(config.style))
} else {
@ -92,11 +92,12 @@ fn get_engines_version(context: &Context) -> Option<String> {
Some(raw_version.to_string())
}
fn check_engines_version(nodejs_version: &str, engines_version: Option<String>) -> bool {
if engines_version.is_none() {
return true;
}
let r = match VersionReq::parse(&engines_version.unwrap()) {
fn check_engines_version(nodejs_version: Option<&str>, engines_version: Option<String>) -> bool {
let (nodejs_version, engines_version) = match (nodejs_version, engines_version) {
(Some(nv), Some(ev)) => (nv, ev),
_ => return true,
};
let r = match VersionReq::parse(&engines_version) {
Ok(r) => r,
Err(_e) => return true,
};
@ -270,4 +271,16 @@ mod tests {
assert_eq!(expected, actual);
dir.close()
}
#[test]
fn no_node_installed() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("index.js"))?.sync_all()?;
let actual = ModuleRenderer::new("nodejs")
.path(dir.path())
.cmd("node --version", None)
.collect();
let expected = Some(format!("via {}", Color::Green.bold().paint("")));
assert_eq!(expected, actual);
dir.close()
}
}

View File

@ -11,6 +11,7 @@ use unicode_width::UnicodeWidthChar;
use crate::configs::PROMPT_ORDER;
use crate::context::{Context, Properties, Shell, Target};
use crate::formatter::string_formatter::StringFormatterError;
use crate::formatter::{StringFormatter, VariableHolder};
use crate::module::Module;
use crate::module::ALL_MODULES;
@ -403,32 +404,42 @@ fn all_modules_uniq(module_list: &BTreeSet<String>) -> Vec<String> {
/// and the list of all modules used in a format string
fn load_formatter_and_modules<'a>(context: &'a Context) -> (StringFormatter<'a>, BTreeSet<String>) {
let config = &context.root_config;
let (formatter, config_param) = match &context.target {
Target::Main => (StringFormatter::new(&config.format), "format".to_string()),
Target::Right => (
StringFormatter::new(&config.right_format),
"right_format".to_string(),
),
Target::Continuation => (
StringFormatter::new(&config.continuation_prompt),
"continuation_prompt".to_string(),
),
Target::Profile(name) => (
match config.profiles.get(name) {
Some(format) => StringFormatter::new(format),
_ => Err(StringFormatterError::Custom("Invalid Profile".to_string())),
},
format!("profile: {}", &name),
),
};
let lformatter = StringFormatter::new(&config.format);
let rformatter = StringFormatter::new(&config.right_format);
let cformatter = StringFormatter::new(&config.continuation_prompt);
if lformatter.is_err() {
log::error!("Error parsing `format`")
if formatter.is_err() {
log::error!("Error parsing `{}`", config_param);
}
if rformatter.is_err() {
log::error!("Error parsing `right_format`")
}
if cformatter.is_err() {
log::error!("Error parsing `continuation_prompt`")
}
match (lformatter, rformatter, cformatter) {
(Ok(lf), Ok(rf), Ok(cf)) => {
match (formatter, rformatter) {
(Ok(lf), Ok(rf)) => {
let mut modules: BTreeSet<String> = BTreeSet::new();
if context.target != Target::Continuation {
modules.extend(lf.get_variables());
modules.extend(rf.get_variables());
}
match context.target {
Target::Main => (lf, modules),
Target::Right => (rf, modules),
Target::Continuation => (cf, modules),
}
(lf, modules)
}
_ => (StringFormatter::raw(">"), BTreeSet::new()),
}
@ -475,6 +486,26 @@ mod test {
use crate::config::StarshipConfig;
use crate::test::default_context;
#[test]
fn main_prompt() {
let mut context = default_context();
context.config = StarshipConfig {
config: Some(toml::toml! {
add_newline=false
format="$character"
[character]
format=">\n>"
}),
};
context.root_config.format = "$character".to_string();
context.target = Target::Main;
context.root_config.add_newline = false;
let expected = String::from(">\n>");
let actual = get_prompt(context);
assert_eq!(expected, actual);
}
#[test]
fn right_prompt() {
let mut context = default_context();
@ -493,6 +524,54 @@ mod test {
assert_eq!(expected, actual);
}
#[test]
fn custom_prompt() {
let mut context = default_context();
context.config = StarshipConfig {
config: Some(toml::toml! {
add_newline = false
[profiles]
test="0_0$character"
[character]
format=">>"
}),
};
context
.root_config
.profiles
.insert("test".to_string(), "0_0$character".to_string());
context.target = Target::Profile("test".to_string());
context.root_config.add_newline = false;
let expected = String::from("0_0>>");
let actual = get_prompt(context);
assert_eq!(expected, actual);
}
#[test]
fn custom_prompt_fallback() {
let mut context = default_context();
context.config = StarshipConfig {
config: Some(toml::toml! {
add_newline=false
[profiles]
test="0_0$character"
[character]
format=">>"
}),
};
context
.root_config
.profiles
.insert("test".to_string(), "0_0$character".to_string());
context.target = Target::Profile("wrong_prompt".to_string());
context.root_config.add_newline = false;
let expected = String::from(">");
let actual = get_prompt(context);
assert_eq!(expected, actual);
}
#[test]
fn continuation_prompt() {
let mut context = default_context();