From 88ec0a9de2dab023f964f0a448f6e696622dfbf4 Mon Sep 17 00:00:00 2001 From: Ondrej Novak Date: Tue, 17 Feb 2026 23:42:43 +0100 Subject: [PATCH] colorize output --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/cli.rs | 22 +++++++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index f476aab..60be806 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -158,6 +158,15 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" 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]] name = "core-foundation-sys" version = "0.8.7" @@ -327,6 +336,7 @@ dependencies = [ "chrono", "chrono-tz", "clap", + "colored", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3484cfa..29faa93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,4 @@ edition = "2024" chrono = "0.4.43" chrono-tz = "0.10.4" clap = { version = "4.5.57", features = ["derive"] } +colored = "3.1.1" diff --git a/src/cli.rs b/src/cli.rs index 87b5935..8266691 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -5,6 +5,7 @@ use chrono::NaiveTime; use chrono_tz::Etc::UTC; use chrono_tz::Tz; use clap::Parser; +use colored::Colorize; use std::error::Error; use std::fmt; use std::iter; @@ -116,10 +117,29 @@ pub fn print_timezones( } fn print_timetable(name: &String, name_padding_len: u32, timetable: &Vec) { + 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 = timetable .iter() .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(); let name_padding = (0..name_padding_len) .map(|_| " ".to_string())