diff --git a/Cargo.toml b/Cargo.toml index 3df8e9c..f9728a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,5 @@ edition = "2021" crossterm = "0.27.0" itertools = "0.13.0" ratatui = "0.26.3" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" diff --git a/src/app.rs b/src/app.rs index d5c627a..ccdfedf 100644 --- a/src/app.rs +++ b/src/app.rs @@ -4,6 +4,7 @@ use std::{io, error, fs}; use std::io::Error; use std::path::Path; use crate::CronTask; +use serde_json; struct TableColors { buffer_bg: Color, @@ -247,6 +248,10 @@ impl App { let text: &str = "Hello, world!!!"; let crondata = &self.tasks; _ = std::fs::write(path, text); - _ = std::fs::write(path2, crondata); + let json_string = serde_json::to_string_pretty(crondata) + .expect("Failed to serialize crondata to JSON"); // Handles the &Vec to String conversion + + _ = std::fs::write(path2, json_string.as_bytes()) // Writes the String as bytes + .expect("Failed to write crondata to file"); } } diff --git a/src/cron.rs b/src/cron.rs index ea85f00..0b54196 100644 --- a/src/cron.rs +++ b/src/cron.rs @@ -7,7 +7,10 @@ use ratatui::widgets::{Block, Paragraph, Row, Table}; use crate::app::{App, CurrentTab, InputState}; use crate::ui::render_ui; -#[derive(Clone)] +// Add these two lines for serde +use serde::{Serialize, Deserialize}; + +#[derive(Clone, Serialize, Deserialize)] // Add Serialize and Deserialize here pub struct CronTask { pub minute: String, pub hour: String, @@ -29,4 +32,3 @@ impl CronTask { } //todo? find a way to formulate the cron task struct into a list / database vector OF cron tasks. } -