init commit
This commit is contained in:
13
Cargo.toml
Normal file
13
Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "qr"
|
||||
version = "0.1.0"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
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 }
|
||||
43
src/main.rs
Normal file
43
src/main.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use qrcode::QrCode;
|
||||
|
||||
const W: &str = "[47m [0m";
|
||||
const B: &str = "[40m [0m";
|
||||
|
||||
fn main() {
|
||||
let code = QrCode::new(b"https://hatter.ink/").unwrap();
|
||||
let string = code.render::<char>()
|
||||
.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);
|
||||
}
|
||||
Reference in New Issue
Block a user