mirror of
https://github.com/wez/wezterm.git
synced 2025-01-08 23:17:36 +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:
parent
1f33b35932
commit
eb6fc75a17
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -5284,7 +5284,6 @@ dependencies = [
|
||||
"pest",
|
||||
"pest_derive",
|
||||
"phf",
|
||||
"semver",
|
||||
"serde",
|
||||
"sha2",
|
||||
"signal-hook",
|
||||
|
@ -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"
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user