This commit is contained in:
benjamyn committed 2024-08-06 13:44:04 +10:00
commit 76f3b6592d
7 files changed
+143

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
use crate::structs::*;
use glob::glob;
use std::{fs, path::PathBuf};
use untildify::untildify;
pub fn load_motds() -> Vec<MOTD> {
let mut path: String = untildify("~/.local/motd");
path.push_str("/*.motd");
let mut motds = Vec::<MOTD>::new();
for entry in glob(&path).unwrap() {
match entry {
Ok(path) => motds.push(read_motd(path)),
Err(e) => {
println!("{}", e);
}
}
}
motds
}
pub fn read_motd(path: PathBuf) -> MOTD {
let motd_contents: String = fs::read_to_string(path).unwrap();
let motd = MOTD::new(motd_contents);
motd
}
+14
View File
@@ -0,0 +1,14 @@
mod files;
use files::*;
mod structs;
fn main() {
let motds = load_motds();
println!("** Important Notes **");
for motd in motds {
motd.print();
}
println!();
println!();
}
+15
View File
@@ -0,0 +1,15 @@
pub struct MOTD {
title: Option<String>,
}
impl MOTD {
pub fn new(motd_title: String) -> MOTD {
return MOTD {
title: Some(String::from(motd_title)),
};
}
pub fn print(&self) {
println!("[*] {}", &self.title.as_ref().unwrap().trim())
}
}