1
1
mirror of https://github.com/wez/wezterm.git synced 2024-07-14 17:40:26 +03:00

termwiz: remove semver dep

The newer version is much more strict about its inputs
and we're dealing with all sorts of weirdness as input
from the environment, so let's just roll our own simple
solution.
This commit is contained in:
Wez Furlong 2024-05-13 13:00:14 -07:00
parent 1f33b35932
commit eb6fc75a17
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
3 changed files with 54 additions and 6 deletions

1
Cargo.lock generated
View File

@ -5284,7 +5284,6 @@ dependencies = [
"pest",
"pest_derive",
"phf",
"semver",
"serde",
"sha2",
"signal-hook",

View File

@ -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"

View File

@ -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::<u64>(), b.parse::<u64>()) {
(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.