summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2021-11-09 23:27:10 +0100
committerPhilipp Gesang <phg@phi-gamma.net>2021-11-10 01:20:11 +0100
commit9e592ee450eeef535b7acf284f157edc9ed4af62 (patch)
tree9b2f25c050c2339c9598560a5a88bc07745ee64c
parent0c84a05d88878dcce09fac859a6c6e8abfad3b95 (diff)
downloadvtcol-9e592ee450eeef535b7acf284f157edc9ed4af62.tar.gz
use lazy_static instead of raw global
This crate would have been handy back in the days.
-rw-r--r--Cargo.toml1
-rw-r--r--src/vtcol.rs19
2 files changed, 12 insertions, 8 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 901e875..4108d5d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -22,3 +22,4 @@ doc = false
[dependencies]
libc = "0.2"
getopts = "0.2"
+lazy_static = "1.4"
diff --git a/src/vtcol.rs b/src/vtcol.rs
index a82e5bb..993653b 100644
--- a/src/vtcol.rs
+++ b/src/vtcol.rs
@@ -1,15 +1,16 @@
-extern crate libc;
-extern crate getopts;
-extern crate core;
+use std::sync::Mutex;
+use lazy_static::lazy_static;
type Fd = libc::c_int;
-static mut VERBOSITY : u8 = 0_u8;
+lazy_static! {
+ static ref VERBOSITY: Mutex<bool> = false;
+}
macro_rules! vrb {
- ( $( $e:expr ),* ) => (
- if unsafe { VERBOSITY } > 0_u8 { println!( $( $e ),* ) }
- )
+ ( $( $e:expr ),* ) => {(
+ if VERBOSITY.lock().unwrap() { println!( $( $e ),* ) }
+ )}
}
const PALETTE_SIZE : usize = 16_usize;
@@ -159,7 +160,9 @@ impl<'a> Job {
unsafe { exit(0) };
};
- if matches.opt_present("v") { unsafe { VERBOSITY = 1_u8; } };
+ if matches.opt_present("v") {
+ VERBOSITY.lock().unwrap() = true;
+ }
if matches.opt_present("l") {
Job::schemes();