using another crate for color output, as colored has an issue

https://rustsec.org/advisories/RUSTSEC-2021-0145.html
This commit is contained in:
Данила Горнушко 2024-06-03 15:06:36 +03:00
parent e28bd11aeb
commit 6ead611a52
3 changed files with 84 additions and 8 deletions

75
Cargo.lock generated
View file

@ -234,6 +234,15 @@ dependencies = [
"fnv",
]
[[package]]
name = "enable-ansi-support"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa4ff3ae2a9aa54bf7ee0983e59303224de742818c1822d89f07da9856d9bc60"
dependencies = [
"windows-sys 0.42.0",
]
[[package]]
name = "fern"
version = "0.6.2"
@ -255,12 +264,13 @@ version = "1.0.0"
dependencies = [
"chrono",
"clap",
"colored",
"crc",
"ctrlc",
"enable-ansi-support",
"fern",
"hound",
"log",
"owo-colors",
"serialport",
"textplots",
]
@ -396,6 +406,12 @@ version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "owo-colors"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "caff54706df99d2a78a5a4e3455ff45448d81ef1bb63c22cd14052ca0e993a3f"
[[package]]
name = "proc-macro2"
version = "1.0.83"
@ -629,6 +645,21 @@ dependencies = [
"windows-targets 0.52.5",
]
[[package]]
name = "windows-sys"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
dependencies = [
"windows_aarch64_gnullvm 0.42.2",
"windows_aarch64_msvc 0.42.2",
"windows_i686_gnu 0.42.2",
"windows_i686_msvc 0.42.2",
"windows_x86_64_gnu 0.42.2",
"windows_x86_64_gnullvm 0.42.2",
"windows_x86_64_msvc 0.42.2",
]
[[package]]
name = "windows-sys"
version = "0.48.0"
@ -678,6 +709,12 @@ dependencies = [
"windows_x86_64_msvc 0.52.5",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.5"
@ -690,6 +727,12 @@ version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
@ -702,6 +745,12 @@ version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
[[package]]
name = "windows_i686_gnu"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
@ -720,6 +769,12 @@ version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
[[package]]
name = "windows_i686_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
@ -732,6 +787,12 @@ version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
@ -744,6 +805,12 @@ version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
@ -756,6 +823,12 @@ version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"

View file

@ -7,7 +7,8 @@ edition = "2021"
serialport = {version="4.3", default-features=false}
log = "0.4"
fern = "0.6"
colored = "2.1"
enable-ansi-support = "0.2"
owo-colors = "4.0"
chrono = "0.4"
hound = "3.5"
clap = { version = "4.5", features = ["derive"] }

View file

@ -4,6 +4,7 @@ use crc::{Crc, CRC_16_IBM_3740};
use fern::Dispatch;
use hound::{SampleFormat, WavSpec, WavWriter};
use log::{debug, error, info, trace, warn, Level, LevelFilter};
use owo_colors::OwoColorize;
use serialport::SerialPort;
use std::collections::HashMap;
use std::io::{BufRead, BufReader, Read, Write};
@ -184,15 +185,14 @@ fn init_logger(
let stdout_dispatch = Dispatch::new()
.format(|out, message, record| {
use colored::*;
let now = Local::now();
let message = message.to_string();
let level = match record.level() {
Level::Error => "ERROR".red(),
Level::Warn => "WARN".yellow(),
Level::Info => "INFO".green(),
Level::Debug => "DEBUG".blue(),
Level::Trace => "TRACE".purple(),
Level::Error => "ERROR".red().to_string(),
Level::Warn => "WARN".yellow().to_string(),
Level::Info => "INFO".green().to_string(),
Level::Debug => "DEBUG".blue().to_string(),
Level::Trace => "TRACE".purple().to_string(),
};
out.finish(format_args!(
"{} [{}] - {}",
@ -223,6 +223,8 @@ fn init_logger(
}
fn main() {
// enable colorful logs if running on Windows 10
let _ = enable_ansi_support::enable_ansi_support();
let args = Args::parse();
let app_logs_path = args.app_logs_path.as_deref().map(Path::new);
let stat_logs_path = args.stat_logs_path.as_deref().map(Path::new);