termwiz: trim num dep to num_traits
refs: https://github.com/wez/wezterm/pull/186
This commit is contained in:
1 parent
180ff0d71a
commit
070afa65d6
8 files changed
+24
-24
No files matched your search
Generated
+1
-2
@@ -885,7 +885,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "filedescriptor"
|
||||
version = "0.7.1"
|
||||
version = "0.7.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"libc",
|
||||
@@ -3295,7 +3295,6 @@ dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"memmem",
|
||||
"num",
|
||||
"num-derive",
|
||||
"num-traits 0.2.11",
|
||||
"ordered-float",
|
||||
|
||||
@@ -21,7 +21,6 @@ lazy_static = "1.3"
|
||||
libc = "0.2"
|
||||
log = "0.4"
|
||||
memmem = "0.1"
|
||||
num = "0.2"
|
||||
num-traits = "0.2"
|
||||
ordered-float = "1.0"
|
||||
regex = "1"
|
||||
|
||||
+10
-10
@@ -2,8 +2,8 @@ use super::OneBased;
|
||||
use crate::cell::{Blink, Intensity, Underline};
|
||||
use crate::color::{AnsiColor, ColorSpec, RgbColor};
|
||||
use crate::input::{Modifiers, MouseButtons};
|
||||
use num::{self, ToPrimitive};
|
||||
use num_derive::*;
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
use std::fmt::{Display, Error as FmtError, Formatter};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -145,7 +145,7 @@ impl DeviceAttributeFlags {
|
||||
fn from_params(params: &[i64]) -> Self {
|
||||
let mut attributes = Vec::new();
|
||||
for p in params {
|
||||
match num::FromPrimitive::from_i64(*p) {
|
||||
match FromPrimitive::from_i64(*p) {
|
||||
Some(c) => attributes.push(DeviceAttribute::Code(c)),
|
||||
None => attributes.push(DeviceAttribute::Unspecified(*p as u16)),
|
||||
}
|
||||
@@ -782,7 +782,7 @@ trait EncodeCSIParam {
|
||||
fn write_csi(&self, f: &mut Formatter, control: &str) -> Result<(), FmtError>;
|
||||
}
|
||||
|
||||
impl<T: ParamEnum + PartialEq + num::ToPrimitive> EncodeCSIParam for T {
|
||||
impl<T: ParamEnum + PartialEq + ToPrimitive> EncodeCSIParam for T {
|
||||
fn write_csi(&self, f: &mut Formatter, control: &str) -> Result<(), FmtError> {
|
||||
if *self == ParamEnum::default() {
|
||||
write!(f, "{}", control)
|
||||
@@ -927,7 +927,7 @@ impl ParseParams for (OneBased, OneBased) {
|
||||
/// to denote an enum. It does double duty as a stand-in for Default.
|
||||
/// We need separate traits for this to disambiguate from a regular
|
||||
/// primitive integer.
|
||||
trait ParamEnum: num::FromPrimitive {
|
||||
trait ParamEnum: FromPrimitive {
|
||||
fn default() -> Self;
|
||||
}
|
||||
|
||||
@@ -937,7 +937,7 @@ impl<T: ParamEnum> ParseParams for T {
|
||||
if params.is_empty() {
|
||||
Ok(ParamEnum::default())
|
||||
} else if params.len() == 1 {
|
||||
num::FromPrimitive::from_i64(params[0]).ok_or(())
|
||||
FromPrimitive::from_i64(params[0]).ok_or(())
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
@@ -1039,7 +1039,7 @@ impl Display for Sgr {
|
||||
|
||||
macro_rules! ansi_color {
|
||||
($idx:expr, $eightbit:ident, $( ($Ansi:ident, $code:ident) ),*) => {
|
||||
if let Some(ansi) = num::FromPrimitive::from_u8($idx) {
|
||||
if let Some(ansi) = FromPrimitive::from_u8($idx) {
|
||||
match ansi {
|
||||
$(AnsiColor::$Ansi => code!($code) ,)*
|
||||
}
|
||||
@@ -1370,7 +1370,7 @@ impl<'a> CSIParser<'a> {
|
||||
if params.len() != 1 {
|
||||
Err(())
|
||||
} else {
|
||||
match num::FromPrimitive::from_i64(params[0]) {
|
||||
match FromPrimitive::from_i64(params[0]) {
|
||||
None => Err(()),
|
||||
Some(style) => {
|
||||
Ok(self.advance_by(1, params, CSI::Cursor(Cursor::CursorStyle(style))))
|
||||
@@ -1542,7 +1542,7 @@ impl<'a> CSIParser<'a> {
|
||||
}
|
||||
|
||||
fn dec(&mut self, params: &'a [i64]) -> Result<DecPrivateMode, ()> {
|
||||
match num::FromPrimitive::from_i64(params[0]) {
|
||||
match FromPrimitive::from_i64(params[0]) {
|
||||
None => Ok(self.advance_by(
|
||||
1,
|
||||
params,
|
||||
@@ -1553,7 +1553,7 @@ impl<'a> CSIParser<'a> {
|
||||
}
|
||||
|
||||
fn terminal_mode(&mut self, params: &'a [i64]) -> Result<TerminalMode, ()> {
|
||||
match num::FromPrimitive::from_i64(params[0]) {
|
||||
match FromPrimitive::from_i64(params[0]) {
|
||||
None => Ok(self.advance_by(
|
||||
1,
|
||||
params,
|
||||
@@ -1668,7 +1668,7 @@ impl<'a> CSIParser<'a> {
|
||||
};
|
||||
};
|
||||
|
||||
match num::FromPrimitive::from_i64(params[0]) {
|
||||
match FromPrimitive::from_i64(params[0]) {
|
||||
None => Err(()),
|
||||
Some(sgr) => match sgr {
|
||||
SgrCode::Reset => one!(Sgr::Reset),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use num::{self, ToPrimitive};
|
||||
use num_derive::*;
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
use std::fmt::{Display, Error as FmtError, Formatter, Write as FmtWrite};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -101,7 +101,7 @@ impl Esc {
|
||||
None => u16::from(control),
|
||||
};
|
||||
|
||||
let code = num::FromPrimitive::from_u16(packed).ok_or(())?;
|
||||
let code = FromPrimitive::from_u16(packed).ok_or(())?;
|
||||
|
||||
Ok(Esc::Code(code))
|
||||
}
|
||||
|
||||
@@ -361,7 +361,9 @@ impl OneBased {
|
||||
/// Map a value from an escape sequence parameter
|
||||
pub fn from_esc_param(v: i64) -> Result<Self, ()> {
|
||||
if v == 0 {
|
||||
Ok(Self { value: num::one() })
|
||||
Ok(Self {
|
||||
value: num_traits::one(),
|
||||
})
|
||||
} else if v > 0 && v <= i64::from(u32::max_value()) {
|
||||
Ok(Self { value: v as u32 })
|
||||
} else {
|
||||
|
||||
@@ -3,8 +3,8 @@ pub use crate::hyperlink::Hyperlink;
|
||||
use anyhow::{anyhow, bail, ensure};
|
||||
use base64;
|
||||
use bitflags::bitflags;
|
||||
use num;
|
||||
use num_derive::*;
|
||||
use num_traits::FromPrimitive;
|
||||
use ordered_float::NotNan;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::{Display, Error as FmtError, Formatter};
|
||||
@@ -215,14 +215,14 @@ impl OperatingSystemCommand {
|
||||
}
|
||||
|
||||
fn parse_reset_dynamic_color_number(idx: u8) -> anyhow::Result<Self> {
|
||||
let which_color: DynamicColorNumber = num::FromPrimitive::from_u8(idx)
|
||||
let which_color: DynamicColorNumber = FromPrimitive::from_u8(idx)
|
||||
.ok_or_else(|| anyhow!("osc code is not a valid DynamicColorNumber!?"))?;
|
||||
|
||||
Ok(OperatingSystemCommand::ResetDynamicColor(which_color))
|
||||
}
|
||||
|
||||
fn parse_change_dynamic_color_number(idx: u8, osc: &[&[u8]]) -> anyhow::Result<Self> {
|
||||
let which_color: DynamicColorNumber = num::FromPrimitive::from_u8(idx)
|
||||
let which_color: DynamicColorNumber = FromPrimitive::from_u8(idx)
|
||||
.ok_or_else(|| anyhow!("osc code is not a valid DynamicColorNumber!?"))?;
|
||||
let mut colors = vec![];
|
||||
for spec in osc.iter().skip(1) {
|
||||
@@ -248,7 +248,7 @@ impl OperatingSystemCommand {
|
||||
let p1str = String::from_utf8_lossy(osc[0]);
|
||||
let code: i64 = p1str.parse()?;
|
||||
let osc_code: OperatingSystemCommandCode =
|
||||
num::FromPrimitive::from_i64(code).ok_or_else(|| anyhow!("unknown code"))?;
|
||||
FromPrimitive::from_i64(code).ok_or_else(|| anyhow!("unknown code"))?;
|
||||
|
||||
macro_rules! single_string {
|
||||
($variant:ident) => {{
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::escape::{
|
||||
SixelData, CSI,
|
||||
};
|
||||
use log::error;
|
||||
use num;
|
||||
use num_traits::FromPrimitive;
|
||||
use regex::bytes::Regex;
|
||||
use std::cell::RefCell;
|
||||
use vtparse::{VTActor, VTParser};
|
||||
@@ -135,7 +135,7 @@ impl<'a, F: FnMut(Action)> VTActor for Performer<'a, F> {
|
||||
}
|
||||
|
||||
fn execute_c0_or_c1(&mut self, byte: u8) {
|
||||
match num::FromPrimitive::from_u8(byte) {
|
||||
match FromPrimitive::from_u8(byte) {
|
||||
Some(code) => (self.callback)(Action::Control(code)),
|
||||
None => error!("impossible C0/C1 control code {:?} was dropped", byte),
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::caps::Capabilities;
|
||||
use crate::input::InputEvent;
|
||||
use crate::surface::Change;
|
||||
use anyhow::{anyhow, Error};
|
||||
use num::{self, NumCast};
|
||||
use num_traits::NumCast;
|
||||
use std::fmt::Display;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -117,5 +117,5 @@ pub fn new_terminal(caps: Capabilities) -> Result<impl Terminal, Error> {
|
||||
}
|
||||
|
||||
pub(crate) fn cast<T: NumCast + Display + Copy, U: NumCast>(n: T) -> Result<U, Error> {
|
||||
num::cast(n).ok_or_else(|| anyhow!("{} is out of bounds for this system", n))
|
||||
num_traits::cast(n).ok_or_else(|| anyhow!("{} is out of bounds for this system", n))
|
||||
}
|
||||
Reference in new issue
Block a user