From 7f55b52acf678da31254d1739ab7d747e9477fd0 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 20 Apr 2020 06:06:21 +0000 Subject: [PATCH 1/8] build(deps): bump regex from 1.3.6 to 1.3.7 Bumps [regex](https://github.com/rust-lang/regex) from 1.3.6 to 1.3.7. - [Release notes](https://github.com/rust-lang/regex/releases) - [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/regex/compare/1.3.6...regex-1.3.7) Signed-off-by: dependabot-preview[bot] --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 49d40bacc..e266d989b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -310,7 +310,7 @@ dependencies = [ "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -851,7 +851,7 @@ dependencies = [ [[package]] name = "regex" -version = "1.3.6" +version = "1.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1024,7 +1024,7 @@ dependencies = [ "pest_derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_env_logger 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.51 (registry+https://github.com/rust-lang/crates.io-index)", "starship_module_config_derive 0.1.1", @@ -1389,7 +1389,7 @@ dependencies = [ "checksum rayon-core 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "08a89b46efaf957e52b18062fb2f4660f8b8a4dde1807ca002690868ef2c85a9" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum redox_users 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "09b23093265f8d200fa7b4c2c76297f47e681c655f6f1285a8780d6a022f7431" -"checksum regex 1.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7f6946991529684867e47d86474e3a6d0c0ab9b82d5821e314b1ede31fa3a4b3" +"checksum regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692" "checksum regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)" = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae" "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" "checksum rust-argon2 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2bc8af4bda8e1ff4932523b94d3dd20ee30a87232323eda55903ffd71d2fb017" diff --git a/Cargo.toml b/Cargo.toml index fea189e8e..055c3ac84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,7 +52,7 @@ yaml-rust = "0.4" pest = "^2.1" pest_derive = "^2.1" nom = "5.1.1" -regex = "1.3.6" +regex = "1.3.7" os_info = "2.0.2" urlencoding = "1.0.0" open = "1.4.0" From c9cd91e8e7223cf77318b4d8889451b15d631dc6 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 20 Apr 2020 06:06:36 +0000 Subject: [PATCH 2/8] build(deps): bump sysinfo from 0.13.3 to 0.14.1 Bumps [sysinfo](https://github.com/GuillaumeGomez/sysinfo) from 0.13.3 to 0.14.1. - [Release notes](https://github.com/GuillaumeGomez/sysinfo/releases) - [Commits](https://github.com/GuillaumeGomez/sysinfo/commits) Signed-off-by: dependabot-preview[bot] --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e266d989b..50ad3ccc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1028,7 +1028,7 @@ dependencies = [ "remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.51 (registry+https://github.com/rust-lang/crates.io-index)", "starship_module_config_derive 0.1.1", - "sysinfo 0.13.3 (registry+https://github.com/rust-lang/crates.io-index)", + "sysinfo 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1070,7 +1070,7 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.13.3" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1410,7 +1410,7 @@ dependencies = [ "checksum static_assertions 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7f3eb36b47e512f8f1c9e3d10c2c1965bc992bd9cdb024fa581e2194501c83d3" "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" "checksum syn 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03" -"checksum sysinfo 0.13.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5a0338198966bde7feb14b011a33d404a62a6e03b843352c71512a2a002634b7" +"checksum sysinfo 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d070254b7172eee9eb3990bea8f72aeabfe1226c40bf71a52e4fe75777812e9a" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" "checksum term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9e5b9a66db815dcfd2da92db471106457082577c3c278d4138ab3e3b4e189327" "checksum termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" diff --git a/Cargo.toml b/Cargo.toml index 055c3ac84..707c3cc95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ unicode-segmentation = "1.6.0" gethostname = "0.2.1" once_cell = "1.3.1" chrono = "0.4" -sysinfo = "0.13.3" +sysinfo = "0.14.1" byte-unit = "3.0.3" starship_module_config_derive = { version = "0.1.0", path = "starship_module_config_derive" } yaml-rust = "0.4" From b2f203d0434e9bc4de22e2c6eed1aa5732caddff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Mon, 20 Apr 2020 14:51:36 +0200 Subject: [PATCH 3/8] docs: Remove unused closing tag from config page (#1125) --- docs/config/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/config/README.md b/docs/config/README.md index 56e1273dc..8b7498d66 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -1191,8 +1191,6 @@ symbol = "โš™๏ธ " The `singularity` module shows the current singularity image, if inside a container and `$SINGULARITY_NAME` is set. -::: - ### Options | Variable | Default | Description | From 7aa9c8fab05520fbe3b88a7c0be55c3c909d2d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Jaramillo=20Mart=C3=ADnez?= Date: Mon, 20 Apr 2020 19:43:24 +0200 Subject: [PATCH 4/8] docs: Fix broken installation link anchor on README (#1033) * Fix Installation link anchor on README * Use fake anchor for Installation --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 974626fd7..aa43d1b76 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@

Website ยท - Installation + Installation ยท Configuration

@@ -130,6 +130,8 @@

+ + ## ๐Ÿš€ Installation ### Prerequisites From b0bfed2a215fbfc79539502e280af8e054aba3ae Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 23 Apr 2020 09:33:37 +0200 Subject: [PATCH 5/8] build(deps): bump git2 from 0.13.2 to 0.13.3 (#1132) Bumps [git2](https://github.com/rust-lang/git2-rs) from 0.13.2 to 0.13.3. - [Release notes](https://github.com/rust-lang/git2-rs/releases) - [Commits](https://github.com/rust-lang/git2-rs/compare/0.13.2...0.13.3) Signed-off-by: dependabot-preview[bot] Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> --- Cargo.lock | 12 ++++++------ Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 50ad3ccc1..f35a7613b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -366,12 +366,12 @@ dependencies = [ [[package]] name = "git2" -version = "0.13.2" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", - "libgit2-sys 0.12.3+1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.12.4+1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -472,7 +472,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libgit2-sys" -version = "0.12.3+1.0.0" +version = "0.12.4+1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1012,7 +1012,7 @@ dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "gethostname 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "git2 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", + "git2 0.13.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "native-tls 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "nom 5.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1330,7 +1330,7 @@ dependencies = [ "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" "checksum gethostname 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e692e296bfac1d2533ef168d0b60ff5897b8b70a4009276834014dd8924cc028" "checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" -"checksum git2 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2cfb93ca10f2934069c3aaafb753fbe0663f08ee009a01b6d62e062391447b15" +"checksum git2 0.13.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bdfc6e264105ef4bf1f5c9a0907f285b43ed2ede987b4876556d0478359f0a0f" "checksum hermit-abi 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e" "checksum http 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" "checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" @@ -1343,7 +1343,7 @@ dependencies = [ "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" "checksum lexical-core 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f86d66d380c9c5a685aaac7a11818bdfa1f733198dfd9ec09c70b762cd12ad6f" "checksum libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)" = "dea0c0405123bba743ee3f91f49b1c7cfb684eef0da0a50110f758ccf24cdff0" -"checksum libgit2-sys 0.12.3+1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7637dc15e7f05a16011723e0448655081fc01a374bcd368e2c9b9c7f5c5ab3ea" +"checksum libgit2-sys 0.12.4+1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef2870ecd7b50a76391b108edc2c62283ad2b62e5b1ab4d5263ef1cd04ef1c44" "checksum libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" "checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" diff --git a/Cargo.toml b/Cargo.toml index 707c3cc95..5788d98b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ tls-vendored = ["native-tls/vendored"] clap = "2.33.0" ansi_term = "0.12.1" dirs = "2.0.2" -git2 = { version = "0.13.1", default-features = false, features = [] } +git2 = { version = "0.13.3", default-features = false, features = [] } toml = { version = "0.5.6", features = ["preserve_order"] } serde_json = "1.0.51" rayon = "1.3.0" From 060689fa8847211e6cfc86aeaf5821a49c66b912 Mon Sep 17 00:00:00 2001 From: Thomas O'Donnell Date: Fri, 24 Apr 2020 12:37:13 +0200 Subject: [PATCH 6/8] fix: Fix latest clippy suggestions (#1136) Have removed some imports that Clippy says are not needed anymore. --- src/bug_report.rs | 1 - src/config.rs | 1 - src/modules/crystal.rs | 1 - src/modules/elixir.rs | 1 - src/modules/elm.rs | 1 - src/modules/golang.rs | 1 - src/modules/haskell.rs | 1 - src/modules/julia.rs | 1 - src/modules/kubernetes.rs | 1 - src/modules/nodejs.rs | 1 - src/modules/package.rs | 1 - src/modules/php.rs | 1 - src/modules/ruby.rs | 1 - tests/testsuite/aws.rs | 1 - tests/testsuite/git_branch.rs | 1 - tests/testsuite/git_state.rs | 1 - tests/testsuite/git_status.rs | 1 - tests/testsuite/hg_branch.rs | 1 - tests/testsuite/python.rs | 1 - tests/testsuite/terraform.rs | 1 - 20 files changed, 20 deletions(-) diff --git a/src/bug_report.rs b/src/bug_report.rs index 280c8a4a4..a6f3eb8d8 100644 --- a/src/bug_report.rs +++ b/src/bug_report.rs @@ -204,7 +204,6 @@ fn get_starship_config() -> String { #[cfg(test)] mod tests { use super::*; - use os_info; use std::env; #[test] diff --git a/src/config.rs b/src/config.rs index 50456093f..ab86a6ef0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -423,7 +423,6 @@ fn parse_color_string(color_string: &str) -> Option { mod tests { use super::*; use starship_module_config_derive::ModuleConfig; - use toml; #[test] fn test_load_config() { diff --git a/src/modules/crystal.rs b/src/modules/crystal.rs index 2243514ce..62e4023a1 100644 --- a/src/modules/crystal.rs +++ b/src/modules/crystal.rs @@ -51,7 +51,6 @@ mod tests { use ansi_term::Color; use std::fs::File; use std::io; - use tempfile; #[test] fn folder_without_crystal_files() -> io::Result<()> { diff --git a/src/modules/elixir.rs b/src/modules/elixir.rs index 3ef1c984b..6eb5ed954 100644 --- a/src/modules/elixir.rs +++ b/src/modules/elixir.rs @@ -63,7 +63,6 @@ mod tests { use ansi_term::Color; use std::fs::File; use std::io; - use tempfile; #[test] fn test_parse_elixir_version() { diff --git a/src/modules/elm.rs b/src/modules/elm.rs index b6c1da4f9..48629fa0f 100644 --- a/src/modules/elm.rs +++ b/src/modules/elm.rs @@ -42,7 +42,6 @@ mod tests { use ansi_term::Color; use std::fs::{self, File}; use std::io; - use tempfile; #[test] fn folder_without_elm() -> io::Result<()> { diff --git a/src/modules/golang.rs b/src/modules/golang.rs index 809b9b1c9..915c24eb3 100644 --- a/src/modules/golang.rs +++ b/src/modules/golang.rs @@ -70,7 +70,6 @@ mod tests { use ansi_term::Color; use std::fs::{self, File}; use std::io; - use tempfile; #[test] fn folder_without_go_files() -> io::Result<()> { diff --git a/src/modules/haskell.rs b/src/modules/haskell.rs index 7b28d56ad..40d87d8d0 100644 --- a/src/modules/haskell.rs +++ b/src/modules/haskell.rs @@ -43,7 +43,6 @@ mod tests { use ansi_term::Color; use std::fs::File; use std::io; - use tempfile; #[test] fn folder_without_stack_yaml() -> io::Result<()> { diff --git a/src/modules/julia.rs b/src/modules/julia.rs index 7d395254b..fc5f01b95 100644 --- a/src/modules/julia.rs +++ b/src/modules/julia.rs @@ -55,7 +55,6 @@ mod tests { use ansi_term::Color; use std::fs::File; use std::io; - use tempfile; #[test] fn folder_without_julia_file() -> io::Result<()> { diff --git a/src/modules/kubernetes.rs b/src/modules/kubernetes.rs index e9ffd78e6..509ef5d66 100644 --- a/src/modules/kubernetes.rs +++ b/src/modules/kubernetes.rs @@ -1,4 +1,3 @@ -use dirs; use yaml_rust::YamlLoader; use std::env; diff --git a/src/modules/nodejs.rs b/src/modules/nodejs.rs index bc8c2c36f..309287dc4 100644 --- a/src/modules/nodejs.rs +++ b/src/modules/nodejs.rs @@ -41,7 +41,6 @@ mod tests { use ansi_term::Color; use std::fs::{self, File}; use std::io; - use tempfile; #[test] fn folder_without_node_files() -> io::Result<()> { diff --git a/src/modules/package.rs b/src/modules/package.rs index c309ffeb5..e34f90e66 100644 --- a/src/modules/package.rs +++ b/src/modules/package.rs @@ -5,7 +5,6 @@ use crate::utils; use regex::Regex; use serde_json as json; -use toml; use super::{RootModuleConfig, SegmentConfig}; use crate::configs::package::PackageConfig; diff --git a/src/modules/php.rs b/src/modules/php.rs index 59ee4c26e..170bfe4f8 100644 --- a/src/modules/php.rs +++ b/src/modules/php.rs @@ -58,7 +58,6 @@ mod tests { use ansi_term::Color; use std::fs::File; use std::io; - use tempfile; #[test] fn test_format_php_version() { diff --git a/src/modules/ruby.rs b/src/modules/ruby.rs index 2980cf5a8..3a7d3baf1 100644 --- a/src/modules/ruby.rs +++ b/src/modules/ruby.rs @@ -56,7 +56,6 @@ mod tests { use ansi_term::Color; use std::fs::File; use std::io; - use tempfile; #[test] fn folder_without_ruby_files() -> io::Result<()> { diff --git a/tests/testsuite/aws.rs b/tests/testsuite/aws.rs index 988238b9d..50eca28b5 100644 --- a/tests/testsuite/aws.rs +++ b/tests/testsuite/aws.rs @@ -2,7 +2,6 @@ use std::fs::File; use std::io::{self, Write}; use ansi_term::Color; -use tempfile; use crate::common::{self, TestCommand}; diff --git a/tests/testsuite/git_branch.rs b/tests/testsuite/git_branch.rs index c8504a4df..bea10a85e 100644 --- a/tests/testsuite/git_branch.rs +++ b/tests/testsuite/git_branch.rs @@ -2,7 +2,6 @@ use ansi_term::Color; use remove_dir_all::remove_dir_all; use std::io; use std::process::Command; -use tempfile; use crate::common::{self, TestCommand}; diff --git a/tests/testsuite/git_state.rs b/tests/testsuite/git_state.rs index 13a0eaed3..f3f625d40 100644 --- a/tests/testsuite/git_state.rs +++ b/tests/testsuite/git_state.rs @@ -3,7 +3,6 @@ use std::ffi::OsStr; use std::fs::OpenOptions; use std::io::{self, Error, ErrorKind, Write}; use std::process::{Command, Stdio}; -use tempfile; #[test] fn show_nothing_on_empty_dir() -> io::Result<()> { diff --git a/tests/testsuite/git_status.rs b/tests/testsuite/git_status.rs index eceadb3b7..7b71987b3 100644 --- a/tests/testsuite/git_status.rs +++ b/tests/testsuite/git_status.rs @@ -4,7 +4,6 @@ use std::fs::{self, File}; use std::io; use std::path::PathBuf; use std::process::Command; -use tempfile; use crate::common::{self, TestCommand}; diff --git a/tests/testsuite/hg_branch.rs b/tests/testsuite/hg_branch.rs index 41bec34e6..8e0928f9f 100644 --- a/tests/testsuite/hg_branch.rs +++ b/tests/testsuite/hg_branch.rs @@ -3,7 +3,6 @@ use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; use std::{env, io}; -use tempfile; use crate::common::{self, TestCommand}; diff --git a/tests/testsuite/python.rs b/tests/testsuite/python.rs index ffc66612e..c996282bc 100644 --- a/tests/testsuite/python.rs +++ b/tests/testsuite/python.rs @@ -2,7 +2,6 @@ use std::fs::File; use std::io; use ansi_term::Color; -use tempfile; use crate::common::{self, TestCommand}; diff --git a/tests/testsuite/terraform.rs b/tests/testsuite/terraform.rs index 2d35ab79d..188a8940d 100644 --- a/tests/testsuite/terraform.rs +++ b/tests/testsuite/terraform.rs @@ -1,7 +1,6 @@ use ansi_term::Color; use std::fs::{self, File}; use std::io::{self, Write}; -use tempfile; use crate::common; use crate::common::TestCommand; From 71020b0397a86e850ad5beda926aa9416250025c Mon Sep 17 00:00:00 2001 From: heyrict Date: Fri, 24 Apr 2020 20:51:45 +0800 Subject: [PATCH 7/8] feat(format_string): Add syntax for positional segments --- src/formatter/model.rs | 30 ++++++++ src/formatter/parser.rs | 29 ++++---- src/formatter/spec.pest | 7 +- src/formatter/string_formatter.rs | 112 +++++++++++++++++------------- 4 files changed, 114 insertions(+), 64 deletions(-) diff --git a/src/formatter/model.rs b/src/formatter/model.rs index 8e4bbea39..fc45104ae 100644 --- a/src/formatter/model.rs +++ b/src/formatter/model.rs @@ -1,4 +1,9 @@ use std::borrow::Cow; +use std::collections::BTreeSet; + +pub trait VariableHolder { + fn get_variables(&self) -> BTreeSet; +} pub struct TextGroup<'a> { pub format: Vec>, @@ -9,9 +14,34 @@ pub enum FormatElement<'a> { Text(Cow<'a, str>), Variable(Cow<'a, str>), TextGroup(TextGroup<'a>), + Positional(Vec>), } pub enum StyleElement<'a> { Text(Cow<'a, str>), Variable(Cow<'a, str>), } + +impl<'a> VariableHolder> for FormatElement<'a> { + fn get_variables(&self) -> BTreeSet> { + match self { + FormatElement::Variable(var) => { + let mut variables = BTreeSet::new(); + variables.insert(var.clone()); + variables + } + FormatElement::TextGroup(textgroup) => textgroup.format.get_variables(), + FormatElement::Positional(format) => format.get_variables(), + _ => Default::default(), + } + } +} + +impl<'a> VariableHolder> for Vec> { + fn get_variables(&self) -> BTreeSet> { + self.iter().fold(BTreeSet::new(), |mut acc, el| { + acc.extend(el.get_variables()); + acc + }) + } +} diff --git a/src/formatter/parser.rs b/src/formatter/parser.rs index 3097cbabe..daba5e6d2 100644 --- a/src/formatter/parser.rs +++ b/src/formatter/parser.rs @@ -6,6 +6,18 @@ use super::model::*; #[grammar = "formatter/spec.pest"] struct IdentParser; +fn _parse_value(value: Pair) -> FormatElement { + match value.as_rule() { + Rule::text => FormatElement::Text(_parse_text(value).into()), + Rule::variable => FormatElement::Variable(_parse_variable(value).into()), + Rule::textgroup => FormatElement::TextGroup(_parse_textgroup(value)), + Rule::positional => { + FormatElement::Positional(_parse_format(value.into_inner().next().unwrap())) + } + _ => unreachable!(), + } +} + fn _parse_textgroup(textgroup: Pair) -> TextGroup { let mut inner_rules = textgroup.into_inner(); let format = inner_rules.next().unwrap(); @@ -29,15 +41,7 @@ fn _parse_text(text: Pair) -> String { } fn _parse_format(format: Pair) -> Vec { - format - .into_inner() - .map(|pair| match pair.as_rule() { - Rule::text => FormatElement::Text(_parse_text(pair).into()), - Rule::variable => FormatElement::Variable(_parse_variable(pair).into()), - Rule::textgroup => FormatElement::TextGroup(_parse_textgroup(pair)), - _ => unreachable!(), - }) - .collect() + format.into_inner().map(_parse_value).collect() } fn _parse_style(style: Pair) -> Vec { @@ -55,12 +59,7 @@ pub fn parse(format: &str) -> Result, Error> { IdentParser::parse(Rule::expression, format).map(|pairs| { pairs .take_while(|pair| pair.as_rule() != Rule::EOI) - .map(|pair| match pair.as_rule() { - Rule::text => FormatElement::Text(_parse_text(pair).into()), - Rule::variable => FormatElement::Variable(_parse_variable(pair).into()), - Rule::textgroup => FormatElement::TextGroup(_parse_textgroup(pair)), - _ => unreachable!(), - }) + .map(_parse_value) .collect() }) } diff --git a/src/formatter/spec.pest b/src/formatter/spec.pest index 94d0b110b..5ce59fc85 100644 --- a/src/formatter/spec.pest +++ b/src/formatter/spec.pest @@ -4,7 +4,7 @@ // // Should be started with SOI and ended with EOI, with a format string in it. expression = _{ SOI ~ value* ~ EOI } -value = _{ text | variable | textgroup } +value = _{ text | variable | textgroup | positional } // Variable // @@ -44,3 +44,8 @@ escaped_char = { "[" | "]" | "(" | ")" | "\\" | "$" } textgroup = { "[" ~ format ~ "]" ~ "(" ~ style ~ ")" } format = { value* } style = { (variable | string)* } + +// Positional +// +// A positional format string that won't render if all the containing variables are empty. +positional = { "(" ~ format ~ ")" } diff --git a/src/formatter/string_formatter.rs b/src/formatter/string_formatter.rs index 62843f156..a0e198d25 100644 --- a/src/formatter/string_formatter.rs +++ b/src/formatter/string_formatter.rs @@ -2,6 +2,7 @@ use ansi_term::Style; use pest::error::Error; use rayon::prelude::*; use std::collections::BTreeMap; +use std::iter::FromIterator; use crate::config::parse_style_string; use crate::segment::Segment; @@ -33,16 +34,22 @@ impl<'a> StringFormatter<'a> { pub fn new(format: &'a str) -> Result> { parse(format) .map(|format| { - let variables = _get_variables(&format); + let variables = VariableMapType::from_iter( + format + .get_variables() + .into_iter() + .map(|key| (key.to_string(), None)) + .collect::)>>(), + ); (format, variables) }) .map(|(format, variables)| Self { format, variables }) } /// Maps variable name to its value - pub fn map(mut self, mapper: impl Fn(&str) -> Option + Sync) -> Self { + pub fn map>(mut self, mapper: impl Fn(&str) -> Option + Sync) -> Self { self.variables.par_iter_mut().for_each(|(key, value)| { - *value = mapper(key).map(VariableValue::Plain); + *value = mapper(key).map(|var| var.into()).map(VariableValue::Plain); }); self } @@ -105,9 +112,9 @@ impl<'a> StringFormatter<'a> { } FormatElement::Variable(name) => variables .get(name.as_ref()) - .map(|segments| { - let value = segments.clone().unwrap_or_default(); - match value { + .and_then(|segments| { + let value = segments.clone()?; + Some(match value { VariableValue::Styled(segments) => segments .into_iter() .map(|mut segment| { @@ -122,9 +129,23 @@ impl<'a> StringFormatter<'a> { VariableValue::Plain(text) => { vec![_new_segment(name.to_string(), text, style)] } - } + }) }) .unwrap_or_default(), + FormatElement::Positional(format) => { + let should_show: bool = format.get_variables().iter().any(|var| { + variables + .get(var.as_ref()) + .map(|segments| segments.is_some()) + .unwrap_or(false) + }); + + if should_show { + _parse_format(format, style, variables) + } else { + Vec::new() + } + } }) .collect() } @@ -133,47 +154,6 @@ impl<'a> StringFormatter<'a> { } } -/// Extract variable names from an array of `FormatElement` into a `BTreeMap` -fn _get_variables<'a>(format: &[FormatElement<'a>]) -> VariableMapType { - let mut variables: VariableMapType = Default::default(); - - fn _push_variables_from_textgroup<'a>( - variables: &mut VariableMapType, - textgroup: &'a TextGroup<'a>, - ) { - for el in &textgroup.format { - match el { - FormatElement::Variable(name) => _push_variable(variables, name.as_ref()), - FormatElement::TextGroup(textgroup) => { - _push_variables_from_textgroup(variables, &textgroup) - } - _ => {} - } - } - for el in &textgroup.style { - if let StyleElement::Variable(name) = el { - _push_variable(variables, name.as_ref()) - } - } - } - - fn _push_variable<'a>(variables: &mut VariableMapType, name: &'a str) { - variables.insert(name.to_owned(), None); - } - - for el in format { - match el { - FormatElement::Variable(name) => _push_variable(&mut variables, name.as_ref()), - FormatElement::TextGroup(textgroup) => { - _push_variables_from_textgroup(&mut variables, &textgroup) - } - _ => {} - } - } - - variables -} - /// Helper function to create a new segment fn _new_segment(name: String, value: String, style: Option