QoL code and made manager mutable

This commit is contained in:
Maddox Werts 2024-06-23 13:54:12 -04:00
parent 8cf5ea3ec8
commit 4dde4f1596
2 changed files with 18 additions and 17 deletions

View file

@ -3,17 +3,17 @@ use crate::{board, manager};
use std::{io, process::exit}; use std::{io, process::exit};
// Structures // Structures
pub struct Interface { pub struct Interface<'a> {
manager: manager::Manager, manager: &'a mut manager::Manager,
running: bool, pub running: bool,
page: u32, page: u32,
on: u32 on: u32
} }
// Implementations // Implementations
impl Interface { impl<'a> Interface<'a> {
pub fn init(manager: manager::Manager) -> Interface{ pub fn init(manager: &'a mut manager::Manager) -> Interface<'a>{
// Return result // Return result
return Interface {manager: manager, running: true, page: 0, on: 0}; return Interface {manager: manager, running: true, page: 0, on: 0};
} }
@ -98,15 +98,12 @@ impl Interface {
} }
pub fn run(&mut self) { pub fn run(&mut self) {
while self.running { // Based on the page do something
match self.page {
match self.page { 0 => self.p_0(),
0 => self.p_0(), 1 => self.p_1(),
1 => self.p_1(), 2 => self.p_2(),
2 => self.p_2(), _ => Interface::error("Invalid Page")
_ => Interface::error("Invalid Page")
}
} }
} }
} }

View file

@ -14,6 +14,10 @@ fn main() {
managed.parse(String::from("data/user.json")); managed.parse(String::from("data/user.json"));
// Passing this through to the interface // Passing this through to the interface
let mut int: interface::Interface = interface::Interface::init(managed); let mut int: interface::Interface = interface::Interface::init(&mut managed);
int.run();
// Running the interface
while int.running {
int.run();
}
} }