v0.1.1 -> v0.1.2
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "qr"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
readme = "README.md"
|
||||
|
||||
13
README.md
13
README.md
@@ -1,11 +1,16 @@
|
||||
# qr
|
||||
|
||||
QR cli tool
|
||||
|
||||
Install:
|
||||
```
|
||||
cargo install qr
|
||||
$ cargo install qr
|
||||
```
|
||||
|
||||
Usage:
|
||||
```
|
||||
$ qr 'hello world'
|
||||
```
|
||||
|
||||
|
||||
```
|
||||
qr 'hello world'
|
||||
```
|
||||
|
||||
|
||||
41
src/main.rs
41
src/main.rs
@@ -1,8 +1,11 @@
|
||||
use clap::{Arg, App};
|
||||
use qrcode::QrCode;
|
||||
|
||||
const C_W: char = ' ';
|
||||
const C_B: char = '█';
|
||||
const W: &str = "[47m [0m";
|
||||
const B: &str = "[40m [0m";
|
||||
const NL: &str = "\n";
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let matches = App::new("QR cli")
|
||||
@@ -24,7 +27,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let input_string = match input {
|
||||
Some(i) => i,
|
||||
None => return Ok(()), // TODO
|
||||
None => return Ok(()), // TODO no input
|
||||
};
|
||||
|
||||
let code = QrCode::new(input_string.as_bytes()).unwrap();
|
||||
@@ -35,31 +38,35 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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;
|
||||
match c {
|
||||
C_B | C_W => ln_len += 1,
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
for _ in 0..ln_len+2 {
|
||||
println!("【QR test for: {}】", &input_string);
|
||||
for _ in 0..ln_len+4 {
|
||||
output_stirng.push_str(W);
|
||||
}
|
||||
output_stirng.push('\n');
|
||||
output_stirng.push_str(NL);
|
||||
output_stirng.push_str(W);
|
||||
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);
|
||||
match c {
|
||||
C_B => output_stirng.push_str(B),
|
||||
C_W => output_stirng.push_str(W),
|
||||
_ => { // new line
|
||||
output_stirng.push_str(W);
|
||||
output_stirng.push_str(W);
|
||||
output_stirng.push(c);
|
||||
output_stirng.push_str(W);
|
||||
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);
|
||||
output_stirng.push_str(NL);
|
||||
for _ in 0..ln_len+4 {
|
||||
output_stirng.push_str(W);
|
||||
}
|
||||
println!("{}", output_stirng);
|
||||
|
||||
Reference in New Issue
Block a user