colorize output
This commit is contained in:
parent
5f4b97d54d
commit
88ec0a9de2
|
|
@ -158,6 +158,15 @@ version = "1.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
|
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colored"
|
||||||
|
version = "3.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "faf9468729b8cbcea668e36183cb69d317348c2e08e994829fb56ebfdfbaac34"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation-sys"
|
name = "core-foundation-sys"
|
||||||
version = "0.8.7"
|
version = "0.8.7"
|
||||||
|
|
@ -327,6 +336,7 @@ dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"chrono-tz",
|
"chrono-tz",
|
||||||
"clap",
|
"clap",
|
||||||
|
"colored",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,4 @@ edition = "2024"
|
||||||
chrono = "0.4.43"
|
chrono = "0.4.43"
|
||||||
chrono-tz = "0.10.4"
|
chrono-tz = "0.10.4"
|
||||||
clap = { version = "4.5.57", features = ["derive"] }
|
clap = { version = "4.5.57", features = ["derive"] }
|
||||||
|
colored = "3.1.1"
|
||||||
|
|
|
||||||
22
src/cli.rs
22
src/cli.rs
|
|
@ -5,6 +5,7 @@ use chrono::NaiveTime;
|
||||||
use chrono_tz::Etc::UTC;
|
use chrono_tz::Etc::UTC;
|
||||||
use chrono_tz::Tz;
|
use chrono_tz::Tz;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use colored::Colorize;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
@ -116,10 +117,29 @@ pub fn print_timezones(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_timetable(name: &String, name_padding_len: u32, timetable: &Vec<NaiveTime>) {
|
fn print_timetable(name: &String, name_padding_len: u32, timetable: &Vec<NaiveTime>) {
|
||||||
|
let len = timetable.len();
|
||||||
|
let mid = (len - 1) / 2;
|
||||||
|
let acceptable_time_from = NaiveTime::from_hms_opt(8, 0, 0).unwrap();
|
||||||
|
let acceptable_time_to = NaiveTime::from_hms_opt(20, 0, 0).unwrap();
|
||||||
let formatted: Vec<String> = timetable
|
let formatted: Vec<String> = timetable
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, t)| t.format("%H:%M").to_string())
|
.map(|(i, t)| {
|
||||||
|
let stringified = t.format("%H:%M").to_string();
|
||||||
|
|
||||||
|
let acceptable_hours_formatted = if t < &acceptable_time_from || t > &acceptable_time_to
|
||||||
|
{
|
||||||
|
stringified.color("#fea201")
|
||||||
|
} else {
|
||||||
|
stringified.green()
|
||||||
|
};
|
||||||
|
|
||||||
|
if i == mid {
|
||||||
|
acceptable_hours_formatted.reversed().to_string()
|
||||||
|
} else {
|
||||||
|
acceptable_hours_formatted.to_string()
|
||||||
|
}
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let name_padding = (0..name_padding_len)
|
let name_padding = (0..name_padding_len)
|
||||||
.map(|_| " ".to_string())
|
.map(|_| " ".to_string())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue