Initial commit

This commit is contained in:
2022-11-11 20:28:21 +01:00
commit 56f671f615
4 changed files with 132 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

75
Cargo.lock generated Normal file
View File

@ -0,0 +1,75 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "colored"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd"
dependencies = [
"atty",
"lazy_static",
"winapi",
]
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.136"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55edcf6c0bb319052dea84732cf99db461780fd5e8d3eb46ab6ff312ab31f197"
[[package]]
name = "linediff"
version = "0.1.0"
dependencies = [
"colored",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

7
Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "linediff"
version = "0.1.0"
edition = "2021"
[dependencies]
colored = "2.0.0"

49
src/main.rs Normal file
View File

@ -0,0 +1,49 @@
use colored::Colorize;
use std::{
io::{stdin, BufRead},
mem::swap,
};
fn main() {
let mut stdin = stdin().lock();
let mut prev_line = String::new();
let mut next_line = String::new();
while let Ok(n) = stdin.read_line(&mut next_line) {
if n == 0 {
break;
}
if next_line.ends_with('\n') {
next_line.pop();
}
let mut chars1 = prev_line.chars();
let mut chars2 = next_line.chars();
let mut buf = [0u8; 4];
while let Some(c1) = chars1.next() {
if let Some(c2) = chars2.next() {
let s = c2.encode_utf8(&mut buf);
if c1 == c2 {
print!("{}", s);
} else {
print!("{}", s.yellow());
}
} else {
let s = c1.encode_utf8(&mut buf);
print!("{}", s.red().strikethrough());
}
}
while let Some(c2) = chars2.next() {
let s = c2.encode_utf8(&mut buf);
print!("{}", s.green());
}
println!();
prev_line.clear();
swap(&mut next_line, &mut prev_line);
}
}