diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2022-10-23 21:29:17 +0200 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2022-10-23 21:29:17 +0200 |
| commit | ed0404753c77c09f78b2c41b55b0cf9a68d95585 (patch) | |
| tree | c57bf7f34dc1271be169cd79d47fe29aac8960bc | |
| parent | c04487126bb50e29b5f25cf4ece5f00522b9160d (diff) | |
| download | gof-rs-ed0404753c77c09f78b2c41b55b0cf9a68d95585.tar.xz gof-rs-ed0404753c77c09f78b2c41b55b0cf9a68d95585.zip | |
removed all the hardcoded paths and replaced them with a for loop
| -rw-r--r-- | src/generation.rs | 4 | ||||
| -rw-r--r-- | src/ui.rs | 2585 |
2 files changed, 18 insertions, 2571 deletions
diff --git a/src/generation.rs b/src/generation.rs index 4031c46..63aa3e3 100644 --- a/src/generation.rs +++ b/src/generation.rs @@ -17,7 +17,7 @@ use std::{ error::Error, fs::File, io::{self, BufRead, BufReader, Write}, - path::Path, + path::PathBuf, thread::sleep, time::Duration, }; @@ -159,7 +159,7 @@ pub fn next_gen(app: &mut App) -> Gen { nxt_gen } -pub fn gen_from_file(path: &Path) -> Gen { +pub fn gen_from_file(path: &PathBuf) -> Gen { let mut gen = Gen::new(); let file = File::open(path).expect("File not found"); let reader = BufReader::new(file); @@ -6,7 +6,7 @@ use crossterm::{ use std::{ error::Error, io, - path::Path, + path::{Path, PathBuf}, thread::sleep, time::{Duration, Instant}, }; @@ -74,2576 +74,23 @@ impl<T> StatefulList<T> { /// /// Check the event handling at the bottom to see how to change the state on incoming events. /// Check the drawing logic for items on how to specify the highlighting style for selected items. -pub struct App<'a> { - pub items: StatefulList<(&'a str, &'a Path)>, +pub struct App { + pub items: StatefulList<(String, PathBuf)>, pub flag_cur: bool, pub layout: Layout, pub cur_gen: Gen, } -impl<'a> App<'a> { - pub fn new() -> App<'a> { +impl App { + pub fn new() -> App { + let mut v = vec![]; + for i in 1..=513 { + let name = format!("pattern{}", i); + let p = format!("./presets/patterns/pattern{}.txt", i); + v.push((name.to_owned(), Path::new(p.as_str()).to_owned())); + } App { - items: StatefulList::with_items(vec