Skip to content

Commit 96b5d86

Browse files
committed
Reactive time icon
1 parent 01ac728 commit 96b5d86

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

modules/src/icons.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::fmt;
44
#[derive(Clone, Copy, Hash)]
55
pub enum Icon {
66
Manual(char),
7-
Time,
7+
Time(usize),
88
Calendar,
99
Hyprland,
1010
I3,
@@ -29,7 +29,10 @@ impl fmt::Display for Icon {
2929
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3030
match self {
3131
Self::Manual(s) => write!(f, "{}", s),
32-
Self::Time => write!(f, ""),
32+
Self::Time(hour) => {
33+
let icons = ['󱑖', '󱑋', '󱑌', '󱑍', '󱑎', '󱑏', '󱑐', '󱑑', '󱑒', '󱑓', '󱑔', '󱑕'];
34+
write!(f, "{}", icons[hour % 12])
35+
}
3336
Self::Calendar => write!(f, ""),
3437
Self::Hyprland => write!(f, ""),
3538
Self::I3 => write!(f, ""),

modules/src/modules/datetime.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
colors::{Color, Style},
44
icons::Icon,
55
};
6-
use chrono::Local;
6+
use chrono::{Local, Timelike};
77
use std::{
88
fmt,
99
time::Duration
@@ -40,7 +40,8 @@ impl fmt::Display for DateTime<'_> {
4040

4141
impl ToModule for DateTime<'_> {
4242
fn icon(&self) -> Option<Icon> {
43-
Some(Icon::Time)
43+
let (_, hour) = Local::now().hour12();
44+
Some(Icon::Time(hour as usize))
4445
}
4546
fn style(&self) -> Style {
4647
Style::new_with_fg(Color::Magenta)

modules/src/modules/uptime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl fmt::Display for Uptime {
3232

3333
impl ToModule for Uptime {
3434
fn icon(&self) -> Option<Icon> {
35-
Some(Icon::Time)
35+
Some(Icon::Time(self.uptime.hours as usize))
3636
}
3737
fn style(&self) -> Style {
3838
Style::new_with_fg(Color::Yellow)

0 commit comments

Comments
 (0)