diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2022-10-24 11:17:48 +0200 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2022-10-24 11:17:48 +0200 |
| commit | 9e2258209a35c228387950c6e809778608da2185 (patch) | |
| tree | 25e88e970076e2aeb87f02bd6d8442bab5ea4277 /src/ui.rs | |
| parent | 8235b1b37afab63bfd769a973e5847348d625f0a (diff) | |
| download | gof-rs-9e2258209a35c228387950c6e809778608da2185.tar.xz gof-rs-9e2258209a35c228387950c6e809778608da2185.zip | |
Added all necessary data to the binary for shiping a stand-alone binary
Diffstat (limited to 'src/ui.rs')
| -rw-r--r-- | src/ui.rs | 32 |
1 files changed, 12 insertions, 20 deletions
@@ -18,9 +18,12 @@ use tui::{ widgets::{Block, Borders, List, ListItem, ListState, Paragraph}, Frame, Terminal, }; +use include_dir::{include_dir, Dir}; use crate::generation::*; +static PRESETS_DIR : Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/presets/patterns/"); + pub struct StatefulList<T> { state: ListState, items: Vec<T>, @@ -74,7 +77,7 @@ 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 { - pub items: StatefulList<(String, PathBuf)>, + pub items: StatefulList<(String, String)>, pub flag_cur: bool, pub layout: Layout, pub cur_gen: Gen, @@ -82,29 +85,18 @@ pub struct App { impl App { pub fn new() -> App { - fn read_presets() -> io::Result<Vec<(String, PathBuf)>> { + fn read_presets() -> Vec<(String, String)> { let mut result = Vec::new(); - for path in std::fs::read_dir("./presets/patterns")? { - let path = path?.path(); - if !path.is_file() { - continue; - } - if let Some(file_name) = path.file_name() { - let file_name = file_name.to_string_lossy(); - if file_name.starts_with("pattern") && file_name.ends_with(".txt") { - result.push((file_name.trim_end_matches(".txt").to_owned(), path)); - } - } + for i in 1..=513 { + let file_name = format!("pattern{}.txt", i); + let file = PRESETS_DIR.get_file(file_name.to_owned()).unwrap(); + let body = file.contents_utf8().unwrap().to_owned(); + result.push((file_name, body)); } - result.sort_by_key(|(name, _)| { - name.trim_start_matches("pattern") - .parse::<u32>() - .unwrap_or(0) - }); - Ok(result) + result } App { - items: StatefulList::with_items(read_presets().unwrap_or_else(|_| Vec::new())), + items: StatefulList::with_items(read_presets()), flag_cur: false, layout: Layout::default() .direction(Direction::Horizontal) |
