pub(crate) fn write_lines<TWrite: fmt::Write>(
    f: &mut TWrite,
    left: &str,
    right: &str,
) -> fmt::Result {
    let diff = ::diff::lines(left, right);

    let mut changes = diff.into_iter().peekable();
    let mut previous_deletion = LatentDeletion::default();

    while let Some(change) = changes.next() {
        match (change, changes.peek()) {
            // If the text is unchanged, just print it plain
            (::diff::Result::Both(value, _), _) => {
                previous_deletion.flush(f)?;
                writeln!(f, " {}", value)?;
            }
            // Defer any deletions to next loop
            (::diff::Result::Left(deleted), _) => {
                previous_deletion.flush(f)?;
                previous_deletion.set(deleted);
            }
            // Underlying diff library should never return this sequence
            (::diff::Result::Right(_), Some(::diff::Result::Left(_))) => {
                panic!("insertion followed by deletion");
            }
            // If we're being followed by more insertions, don't inline diff
            (::diff::Result::Right(inserted), Some(::diff::Result::Right(_))) => {
                previous_deletion.flush(f)?;
                paint!(f, Green, "{}{}", SIGN_RIGHT, inserted)?;
                writeln!(f)?;
            }
            // Otherwise, check if we need to inline diff with the previous line (if it was a deletion)
            (::diff::Result::Right(inserted), _) => {
                if let Some(deleted) = previous_deletion.take() {
                    write_inline_diff(f, deleted, inserted)?;
                } else {
                    previous_deletion.flush(f)?;
                    paint!(f, Green, "{}{}", SIGN_RIGHT, inserted)?;
                    writeln!(f)?;
                }
            }
        };
    }

    previous_deletion.flush(f)?;
    Ok(())
}
/// Present the diff output for two mutliline strings in a pretty, colorised manner.
Present the diff output for two mutliline strings in a pretty, colorised manner.
Present the diff output for two mutliline strings in a pretty colorised manner .
pub(crate) fn write_lines<TWrite: fmt::Write>(
    f: &mut TWrite,
    left: &str,
    right: &str,
) -> fmt::Result {
    let diff = ::diff::lines(left, right);
    let mut changes = diff.into_iter().peekable();
    let mut previous_deletion = LatentDeletion::default();
    while let Some(change) = changes.next() {
        match (change, changes.peek()) {
            // If the text is unchanged, just print it plain
            (::diff::Result::Both(value, _), _) => {
                previous_deletion.flush(f)?;
                writeln!(f, " {}", value)?;
            }
            // Defer any deletions to next loop
            (::diff::Result::Left(deleted), _) => {
                previous_deletion.flush(f)?;
                previous_deletion.set(deleted);
            }
            // Underlying diff library should never return this sequence
            (::diff::Result::Right(_), Some(::diff::Result::Left(_))) => {
                panic!("insertion followed by deletion");
            }
            // If we're being followed by more insertions, don't inline diff
            (::diff::Result::Right(inserted), Some(::diff::Result::Right(_))) => {
                previous_deletion.flush(f)?;
                paint!(f, Green, "{}{}", SIGN_RIGHT, inserted)?;
                writeln!(f)?;
            }
            // Otherwise, check if we need to inline diff with the previous line (if it was a deletion)
            (::diff::Result::Right(inserted), _) => {
                if let Some(deleted) = previous_deletion.take() {
                    write_inline_diff(f, deleted, inserted)?;
                } else {
                    previous_deletion.flush(f)?;
                    paint!(f, Green, "{}{}", SIGN_RIGHT, inserted)?;
                    writeln!(f)?;
                }
            }
        };
    }
    previous_deletion.flush(f)?;
    Ok(())
}
pub ( crate ) fn write_lines < TWrite : fmt :: Write > ( f : & mut TWrite , left : & str , right : & str , ) -> fmt :: Result { let diff = :: diff :: lines ( left , right ) ; let mut changes = diff . into_iter ( ) . peekable ( ) ; let mut previous_deletion = LatentDeletion :: default ( ) ; while let Some ( change ) = changes . next ( ) { match ( change , changes . peek ( ) ) { // If the text is unchanged, just print it plain ( :: diff :: Result :: Both ( value , _ ) , _ ) => { previous_deletion . flush ( f ) ? ; writeln ! ( f " " value ) ? ; } // Defer any deletions to next loop ( :: diff :: Result :: Left ( deleted ) , _ ) => { previous_deletion . flush ( f ) ? ; previous_deletion . set ( deleted ) ; } // Underlying diff library should never return this sequence ( :: diff :: Result :: Right ( _ ) , Some ( :: diff :: Result :: Left ( _ ) ) ) => { panic ! ( " " ) ; } // If we're being followed by more insertions, don't inline diff ( :: diff :: Result :: Right ( inserted ) , Some ( :: diff :: Result :: Right ( _ ) ) ) => { previous_deletion . flush ( f ) ? ; paint ! ( f Green " " SIGN_RIGHT inserted ) ? ; writeln ! ( f ) ? ; } // Otherwise, check if we need to inline diff with the previous line (if it was a deletion) ( :: diff :: Result :: Right ( inserted ) , _ ) => { if let Some ( deleted ) = previous_deletion . take ( ) { write_inline_diff ( f , deleted , inserted ) ? ; } else { previous_deletion . flush ( f ) ? ; paint ! ( f Green " " SIGN_RIGHT inserted ) ? ; writeln ! ( f ) ? ; } } } ; } previous_deletion . flush ( f ) ? ; Ok ( ( ) ) }
Present the diff output for two mutliline strings in a pretty, colorised manner.
Present the diff output for two mutliline strings in a pretty colorised manner .
f
&mut TWrite
left
&str
right
&str
f
&mut TWrite
left
&str
right
&str