diff --git a/Cargo.lock b/Cargo.lock index 9490f2603..0cc33c101 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5284,7 +5284,6 @@ dependencies = [ "pest", "pest_derive", "phf", - "semver", "serde", "sha2", "signal-hook", diff --git a/termwiz/Cargo.toml b/termwiz/Cargo.toml index e9f536de0..f11de6176 100644 --- a/termwiz/Cargo.toml +++ b/termwiz/Cargo.toml @@ -33,7 +33,6 @@ ordered-float = "4.1" pest = "2.1" pest_derive = "2.1" phf = "0.11" -semver = "1.0" serde = {version="1.0", features = ["rc", "derive"], optional=true} siphasher = "0.3" sha2 = "0.10" diff --git a/termwiz/src/caps/mod.rs b/termwiz/src/caps/mod.rs index cd7bc5d3b..c9b94e8d9 100644 --- a/termwiz/src/caps/mod.rs +++ b/termwiz/src/caps/mod.rs @@ -55,7 +55,6 @@ //! the terminal capabilities, but also offers a `ProbeHints` //! that can be used by the embedding application to override those choices. use crate::{builder, Result}; -use semver::Version; use std::env::var; use terminfo::{self, capability as cap}; @@ -295,14 +294,13 @@ impl Capabilities { // here because the iTerm2 docs don't say when the // image protocol was first implemented, but do mention // the gif version. - Version::parse( + version_ge( hints .term_program_version .as_ref() .unwrap_or(&"0.0.0".to_owned()), + "2.9.20150512", ) - .unwrap_or(Version::new(0, 0, 0)) - >= Version::new(2, 9, 20150512) } Some("WezTerm") => true, _ => false, @@ -378,10 +376,62 @@ impl Capabilities { } } +/// Returns true if the version string `a` is >= `b` +fn version_ge(a: &str, b: &str) -> bool { + let mut a = a.split('.'); + let mut b = b.split('.'); + + loop { + match (a.next(), b.next()) { + (Some(a), Some(b)) => match (a.parse::(), b.parse::()) { + (Ok(a), Ok(b)) => { + if a > b { + return true; + } + if a < b { + return false; + } + } + _ => { + if a > b { + return true; + } + if a < b { + return false; + } + } + }, + (Some(_), None) => { + // A is greater + return true; + } + (None, Some(_)) => { + // A is smaller + return false; + } + (None, None) => { + // Equal + return true; + } + } + } +} + #[cfg(test)] mod test { use super::*; + #[test] + fn version_cmp() { + assert!(version_ge("1", "0")); + assert!(version_ge("1.0", "0")); + assert!(!version_ge("0", "1")); + assert!(version_ge("3.2", "2.9")); + assert!(version_ge("3.2.0beta5", "2.9")); + assert!(version_ge("3.2.0beta5", "3.2.0")); + assert!(version_ge("3.2.0beta5", "3.2.0beta1")); + } + fn load_terminfo() -> terminfo::Database { // Load our own compiled data so that the tests have an // environment that doesn't vary machine by machine.