diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..385e9f6 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "qr" +version = "0.1.0" +authors = ["Hatter Jiang "] +edition = "2018" +readme = "README.md" +description = "QR cli" +license = "MIT" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +qrcode = { version = "0.11.2", default-features = false } diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..8230aaa --- /dev/null +++ b/src/main.rs @@ -0,0 +1,43 @@ +use qrcode::QrCode; + +const W: &str = " "; +const B: &str = " "; + +fn main() { + let code = QrCode::new(b"https://hatter.ink/").unwrap(); + let string = code.render::() + .quiet_zone(false) + .module_dimensions(2, 1) + .build(); + let mut output_stirng = String::with_capacity(1024); + let mut ln_len = 0; + for c in string.chars() { + if c == '█' || c == ' ' { + ln_len += 1; + } else { + break; + } + } + for _ in 0..ln_len+2 { + output_stirng.push_str(W); + } + output_stirng.push('\n'); + output_stirng.push_str(W); + for c in string.chars() { + if c == '█' { + output_stirng.push_str(B); + } else if c == ' ' { + output_stirng.push_str(W); + } else { + output_stirng.push_str(W); + output_stirng.push(c); + output_stirng.push_str(W); + } + } + output_stirng.push_str(W); + output_stirng.push('\n'); + for _ in 0..ln_len+2 { + output_stirng.push_str(W); + } + println!("{}", output_stirng); +} \ No newline at end of file