~exitb/retrofit

726b7b60548441b3068808953e43e39b7dd4b605 — exitb 1 year, 10 months ago cdfbaae
Change the cursor save and restore routines to DEC-derived ones, for compatibility with Terminal.app
3 files changed, 40 insertions(+), 9 deletions(-)

M src/adapter.rs
M src/ansi.rs
M src/main.rs
M src/adapter.rs => src/adapter.rs +32 -7
@@ 123,12 123,18 @@ impl Style {
                if truecolor {
                    match *parameters {
                        [0, red, green, blue] => {
                            self.background =
                                Color::True(parse_color(red)?, parse_color(green)?, parse_color(blue)?)
                            self.background = Color::True(
                                parse_color(red)?,
                                parse_color(green)?,
                                parse_color(blue)?,
                            )
                        }
                        [1, red, green, blue] => {
                            self.foreground =
                                Color::True(parse_color(red)?, parse_color(green)?, parse_color(blue)?)
                            self.foreground = Color::True(
                                parse_color(red)?,
                                parse_color(green)?,
                                parse_color(blue)?,
                            )
                        }
                        _ => Err(Error::UnknownPabloDraw24BitColorParameterFormat(
                            parameters.to_vec(),


@@ 458,7 464,10 @@ where
                    }
                    ControlSequenceIntroducer::SelectGraphicRendition
                    | ControlSequenceIntroducer::PabloDraw24BitColor => {
                        let new_brush = self.brush.clone().parse(&parameters, &introducer, self.truecolor)?;
                        let new_brush =
                            self.brush
                                .clone()
                                .parse(&parameters, &introducer, self.truecolor)?;

                        if self.brush != new_brush {
                            let difference_params = new_brush.render_difference(


@@ 527,13 536,17 @@ where
                        self.saved_line = self.line;
                        self.saved_column = self.column;

                        true
                        self.push_code(AnsiCode::DecSaveCursorPosition);

                        false
                    }
                    ControlSequenceIntroducer::RestoreCursorPosition => {
                        self.line = self.saved_line;
                        self.column = self.saved_column;

                        true
                        self.push_code(AnsiCode::DecRestoreCursorPosition);

                        false
                    }
                    ControlSequenceIntroducer::SetScreenMode
                    | ControlSequenceIntroducer::ResetScreenMode => false,


@@ 547,6 560,18 @@ where
                    });
                }
            }
            AnsiCode::DecSaveCursorPosition => {
                self.saved_line = self.line;
                self.saved_column = self.column;

                self.push_code(code);
            }
            AnsiCode::DecRestoreCursorPosition => {
                self.line = self.saved_line;
                self.column = self.saved_column;

                self.push_code(code);
            }
        }

        self.push_boundary();

M src/ansi.rs => src/ansi.rs +6 -0
@@ 37,6 37,8 @@ pub enum AnsiCode {
        introducer: ControlSequenceIntroducer,
        parameters: Vec<u16>,
    },
    DecSaveCursorPosition,
    DecRestoreCursorPosition,
}

pub struct Escaped<I>


@@ 70,6 72,8 @@ where
    fn parse_escape(&mut self) -> Result<AnsiCode> {
        match self.characters.next().ok_or(Error::TruncatedEscapeCode)? {
            '[' => self.parse_csi(),
            '7' => Ok(AnsiCode::DecSaveCursorPosition),
            '8' => Ok(AnsiCode::DecRestoreCursorPosition),
            character => Err(Error::UnknownEscapeCode(character)),
        }
    }


@@ 250,6 254,8 @@ impl fmt::Display for AnsiCode {

                write!(f, "{}", identifier)
            }
            AnsiCode::DecSaveCursorPosition => write!(f, "\x1B7"),
            AnsiCode::DecRestoreCursorPosition => write!(f, "\x1B8"),
        }
    }
}

M src/main.rs => src/main.rs +2 -2
@@ 83,7 83,7 @@ fn retrofit() -> Result<()> {
                .long("output")
                .value_name("FILE")
                .help("Redirects the output to a file instead of the standard output")
                .takes_value(true)
                .takes_value(true),
        )
        .arg(
            Arg::with_name("ice-colors")


@@ 134,7 134,7 @@ fn retrofit() -> Result<()> {
            let file = File::create(filename).map_err(Error::OutputFileCreating)?;
            Box::new(file) as Box<dyn Write>
        }
        None => Box::new(stdout()) as Box<dyn Write>
        None => Box::new(stdout()) as Box<dyn Write>,
    };

    let mut output = BufWriter::new(target);