Add a disclaimer to the state file

This commit is contained in:
mo8it 2024-04-21 23:39:44 +02:00
parent e3b9124b85
commit 30040d7778

View file

@ -53,7 +53,8 @@ impl AppState {
} }
// See `Self::write` for more information about the file format. // See `Self::write` for more information about the file format.
let mut lines = self.file_buf.split(|c| *c == b'\n'); let mut lines = self.file_buf.split(|c| *c == b'\n').skip(2);
let Some(current_exercise_name) = lines.next() else { let Some(current_exercise_name) = lines.next() else {
return StateFileStatus::NotRead; return StateFileStatus::NotRead;
}; };
@ -300,13 +301,17 @@ impl AppState {
// Write the state file. // Write the state file.
// The file's format is very simple: // The file's format is very simple:
// - The first line is the name of the current exercise. It must end with `\n` even if there // - The first line is a comment.
// are no done exercises.
// - The second line is an empty line. // - The second line is an empty line.
// - The third line is the name of the current exercise. It must end with `\n` even if there
// are no done exercises.
// - The fourth line is an empty line.
// - All remaining lines are the names of done exercises. // - All remaining lines are the names of done exercises.
fn write(&mut self) -> Result<()> { fn write(&mut self) -> Result<()> {
self.file_buf.clear(); self.file_buf.clear();
self.file_buf
.extend_from_slice(b"DON'T EDIT THIS FILE!\n\n");
self.file_buf self.file_buf
.extend_from_slice(self.current_exercise().name.as_bytes()); .extend_from_slice(self.current_exercise().name.as_bytes());
self.file_buf.push(b'\n'); self.file_buf.push(b'\n');