~exitb/retrofit

053e5b51e7ff28462541ea2636132caa47f9a3cf — exitb 1 year, 10 months ago 6670c94
Apply Clippy changes. Remove explicit panics.
3 files changed, 56 insertions(+), 51 deletions(-)

M src/adapter.rs
M src/ansi.rs
M src/limit_rate.rs
M src/adapter.rs => src/adapter.rs +53 -48
@@ 10,6 10,10 @@ pub enum Error {
    ParameterToColor(std::num::TryFromIntError),
    ApplyingUnknownParameter(u16),
    ColorValueOutOfBounds(u16),
    UnknownControlCharacter(char),
    ControlSequenceWithUnexpectedMultipleParameters(ControlSequenceIntroducer, Vec<u16>),
    EraseInDisplayUnsupportedParameter(Vec<u16>),
    IntroducerNotSupported(ControlSequenceIntroducer),
}

type Result<T> = std::result::Result<T, Error>;


@@ 122,12 126,12 @@ impl Style {
                    }
                }

                match parameters {
                    &[0, red, green, blue] => {
                match *parameters {
                    [0, red, green, blue] => {
                        self.background =
                            Color::True(parse_color(red)?, parse_color(green)?, parse_color(blue)?)
                    }
                    &[1, red, green, blue] => {
                    [1, red, green, blue] => {
                        self.foreground =
                            Color::True(parse_color(red)?, parse_color(green)?, parse_color(blue)?)
                    }


@@ 181,10 185,8 @@ impl Style {
        if truecolor {
            let (red, green, blue) = self.foreground.to_truecolor_palette(self.intense);
            parameters.extend(&[38, 2, red, green, blue]);
        } else {
            if let Some(color) = self.foreground.to_cube_palette(self.intense) {
                parameters.extend(&[38, 5, color]);
            }
        } else if let Some(color) = self.foreground.to_cube_palette(self.intense) {
            parameters.extend(&[38, 5, color]);
        }

        if truecolor {


@@ 192,13 194,11 @@ impl Style {
                .background
                .to_truecolor_palette(ice_colors && self.blink_or_int_back);
            parameters.extend(&[48, 2, red, green, blue]);
        } else {
            if let Some(color) = self
                .background
                .to_cube_palette(ice_colors && self.blink_or_int_back)
            {
                parameters.extend(&[48, 5, color]);
            }
        } else if let Some(color) = self
            .background
            .to_cube_palette(ice_colors && self.blink_or_int_back)
        {
            parameters.extend(&[48, 5, color]);
        }

        parameters


@@ 219,10 219,8 @@ impl Style {
            if truecolor {
                let (red, green, blue) = self.foreground.to_truecolor_palette(self.intense);
                parameters.extend(&[38, 2, red, green, blue]);
            } else {
                if let Some(color) = self.foreground.to_cube_palette(self.intense) {
                    parameters.extend(&[38, 5, color]);
                }
            } else if let Some(color) = self.foreground.to_cube_palette(self.intense) {
                parameters.extend(&[38, 5, color]);
            }
        }



@@ 234,13 232,11 @@ impl Style {
                    .background
                    .to_truecolor_palette(ice_colors && self.blink_or_int_back);
                parameters.extend(&[48, 2, red, green, blue]);
            } else {
                if let Some(color) = self
                    .background
                    .to_cube_palette(ice_colors && self.blink_or_int_back)
                {
                    parameters.extend(&[48, 5, color]);
                }
            } else if let Some(color) = self
                .background
                .to_cube_palette(ice_colors && self.blink_or_int_back)
            {
                parameters.extend(&[48, 5, color]);
            }
        }



@@ 399,7 395,7 @@ where
                    self.push_code(AnsiCode::Printable(' '));
                    self.column += 1;
                }
                character => panic!("Unknown control character: {:?}", character),
                character => Err(Error::UnknownControlCharacter(character))?,
            },
            AnsiCode::ControlSequence {
                introducer,


@@ 407,10 403,13 @@ where
            } => {
                let retransmit = match introducer {
                    ControlSequenceIntroducer::CursorForward => {
                        let count = match parameters.as_slice() {
                            &[0] => 1,
                            &[count] => count,
                            _ => panic!("Not supported"),
                        let count = match *parameters.as_slice() {
                            [0] => 1,
                            [count] => count,
                            _ => Err(Error::ControlSequenceWithUnexpectedMultipleParameters(
                                introducer.clone(),
                                parameters.clone(),
                            ))?,
                        };

                        self.column += count;


@@ 418,10 417,13 @@ where
                        true
                    }
                    ControlSequenceIntroducer::CursorUp => {
                        let count = match parameters.as_slice() {
                            &[0] => 1,
                            &[count] => count,
                            _ => panic!("Not supported"),
                        let count = match *parameters.as_slice() {
                            [0] => 1,
                            [count] => count,
                            _ => Err(Error::ControlSequenceWithUnexpectedMultipleParameters(
                                introducer.clone(),
                                parameters.clone(),
                            ))?,
                        };

                        self.line = self.line.saturating_sub(count as usize);


@@ 429,10 431,13 @@ where
                        true
                    }
                    ControlSequenceIntroducer::CursorBack => {
                        let count = match parameters.as_slice() {
                            &[0] => 1,
                            &[count] => count,
                            _ => panic!("Not supported"),
                        let count = match *parameters.as_slice() {
                            [0] => 1,
                            [count] => count,
                            _ => Err(Error::ControlSequenceWithUnexpectedMultipleParameters(
                                introducer.clone(),
                                parameters.clone(),
                            ))?,
                        };

                        self.column = self.column.saturating_sub(count);


@@ 440,10 445,13 @@ where
                        true
                    }
                    ControlSequenceIntroducer::CursorDown => {
                        let count = match parameters.as_slice() {
                            &[0] => 1,
                            &[count] => count,
                            _ => panic!("Not supported"),
                        let count = match *parameters.as_slice() {
                            [0] => 1,
                            [count] => count,
                            _ => Err(Error::ControlSequenceWithUnexpectedMultipleParameters(
                                introducer.clone(),
                                parameters.clone(),
                            ))?,
                        };

                        for _ in 0..count {


@@ 476,8 484,8 @@ where
                        false
                    }
                    ControlSequenceIntroducer::EraseInDisplay => {
                        if parameters.as_slice() != &[2] {
                            panic!("Unsupported EraseInDisplay with option != 2");
                        if parameters.as_slice() != [2] {
                            return Err(Error::EraseInDisplayUnsupportedParameter(parameters));
                        }

                        let difference = if self.line > 25 { 25 } else { self.line };


@@ 525,10 533,7 @@ where
                    }
                    ControlSequenceIntroducer::SetScreenMode
                    | ControlSequenceIntroducer::ResetScreenMode => false,
                    introducer => panic!(
                        "Introducer not supported: {:?} {:?}",
                        introducer, parameters
                    ),
                    introducer => return Err(Error::IntroducerNotSupported(introducer)),
                };

                if retransmit {

M src/ansi.rs => src/ansi.rs +2 -2
@@ 213,8 213,8 @@ impl fmt::Display for AnsiCode {
                    _ => (),
                }

                match parameters.as_slice() {
                    &[0] => (),
                match *parameters.as_slice() {
                    [0] => (),
                    _ => {
                        let mut first = true;


M src/limit_rate.rs => src/limit_rate.rs +1 -1
@@ 36,7 36,7 @@ where
            iterator: self,
            duration: baud.map(|baud| {
                let bytes_per_second = baud.0 / 8;
                let micros_per_byte = 1000000 / bytes_per_second;
                let micros_per_byte = 1_000_000 / bytes_per_second;
                Duration::from_micros(micros_per_byte)
            }),
        }