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