aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2022-10-24 11:17:48 +0200
committeromagdy7 <omar.professional8777@gmail.com>2022-10-24 11:17:48 +0200
commit9e2258209a35c228387950c6e809778608da2185 (patch)
tree25e88e970076e2aeb87f02bd6d8442bab5ea4277 /src
parent8235b1b37afab63bfd769a973e5847348d625f0a (diff)
downloadgof-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')
-rw-r--r--src/generation.rs10
-rw-r--r--src/ui.rs32
2 files changed, 17 insertions, 25 deletions
diff --git a/src/generation.rs b/src/generation.rs
index 63aa3e3..f58bba9 100644
--- a/src/generation.rs
+++ b/src/generation.rs
@@ -159,13 +159,13 @@ pub fn next_gen(app: &mut App) -> Gen {
nxt_gen
}
-pub fn gen_from_file(path: &PathBuf) -> Gen {
+pub fn gen_from_file(s : &String) -> Gen {
let mut gen = Gen::new();
- let file = File::open(path).expect("File not found");
- let reader = BufReader::new(file);
+ // let file = File::open(path).expect("File not found");
+ // let reader = BufReader::new(file);
- for line in reader.lines() {
- let line = line.unwrap();
+ for line in s.lines() {
+ let line = line;
let mut row: Vec<Cell> = vec![];
for ch in line.chars() {
if ch == '.' {
diff --git a/src/ui.rs b/src/ui.rs
index 73a345f..692e3e3 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -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)