feat: configurable date format

This commit is contained in:
Pihkaal
2024-01-18 23:54:04 +01:00
parent 0716720b77
commit 431de781f7
3 changed files with 13 additions and 1 deletions

7
config
View File

@@ -10,6 +10,13 @@ polite=true
# Value: int # Value: int
fps=30 fps=30
[format]
# Date format
# Value: TODO
date=%Y-%m-%d
[styling] [styling]
# Which color mode to use # Which color mode to use

View File

@@ -7,6 +7,7 @@ pub struct Config {
pub be_polite: bool, pub be_polite: bool,
pub fps: u64, pub fps: u64,
pub color: Color, pub color: Color,
pub date_format: String,
} }
pub fn load_from_file(path: &str) -> Config { pub fn load_from_file(path: &str) -> Config {
@@ -17,6 +18,7 @@ pub fn load_from_file(path: &str) -> Config {
be_polite: ini.getbool("general", "polite").unwrap().unwrap(), be_polite: ini.getbool("general", "polite").unwrap().unwrap(),
fps: ini.getuint("general", "fps").unwrap().unwrap(), fps: ini.getuint("general", "fps").unwrap().unwrap(),
color: load_color(&ini), color: load_color(&ini),
date_format: ini.get("format", "date").unwrap(),
}; };
return config; return config;

View File

@@ -103,7 +103,10 @@ fn render_frame(config: &Config) -> io::Result<()> {
draw_symbol(minute.chars().last().unwrap(), x - 2 + 4 * 7, y, color)?; draw_symbol(minute.chars().last().unwrap(), x - 2 + 4 * 7, y, color)?;
// Display date // Display date
let date = time.date_naive().format("%Y-%m-%d").to_string(); let date = time
.date_naive()
.format(&config.date_format.to_owned())
.to_string();
let mut stdout = io::stdout(); let mut stdout = io::stdout();
let x = width / 2 - (date.len() as u16) / 2; let x = width / 2 - (date.len() as u16) / 2;