working
This commit is contained in:
		
							
								
								
									
										100
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										100
									
								
								src/main.rs
									
									
									
									
									
								
							@@ -1,19 +1,105 @@
 | 
				
			|||||||
use std::env;
 | 
					use iced::{
 | 
				
			||||||
 | 
					    Alignment::Center,
 | 
				
			||||||
 | 
					    Element,
 | 
				
			||||||
 | 
					    widget::{self, Column, column, combo_box, text},
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					use std::{env, fmt::Display, fs, path::PathBuf};
 | 
				
			||||||
 | 
					use texts::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mod strong;
 | 
					mod texts;
 | 
				
			||||||
mod bible;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn main() {
 | 
					pub const BIBLE_DIRECTORY: &str = "./Holy-Bible-XML-Format";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn main() -> iced::Result {
 | 
				
			||||||
    let arg = env::args().collect::<Vec<String>>();
 | 
					    let arg = env::args().collect::<Vec<String>>();
 | 
				
			||||||
    if let Some(query) = arg.get(1) {
 | 
					    if let Some(query) = arg.get(1) {
 | 
				
			||||||
        if query.starts_with("H") | query.starts_with("h") {
 | 
					        if query.starts_with("H") | query.starts_with("h") {
 | 
				
			||||||
            if let Some(found) = strong::get(query) {
 | 
					            if let Some(found) = strong::get(query) {
 | 
				
			||||||
                print!("{found}");
 | 
					                print!("{found}");
 | 
				
			||||||
                return;
 | 
					                return Ok(());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if let Some(second_query) = arg.get(2)  {
 | 
					        if let Some(second_query) = arg.get(2) {
 | 
				
			||||||
            bible::get(query,second_query);
 | 
					            bible::get(
 | 
				
			||||||
 | 
					                query,
 | 
				
			||||||
 | 
					                second_query,
 | 
				
			||||||
 | 
					                vec![format!("{BIBLE_DIRECTORY}/EnglishNASBBible.xml").into()],
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    iced::run("A cool counter", State::update, State::view)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Debug, Clone)]
 | 
				
			||||||
 | 
					enum Message {
 | 
				
			||||||
 | 
					    BookSelected(&'static str),
 | 
				
			||||||
 | 
					    BibleSelected(String),
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct State {
 | 
				
			||||||
 | 
					    book: combo_box::State<&'static str>,
 | 
				
			||||||
 | 
					    selected: Option<&'static str>,
 | 
				
			||||||
 | 
					    files: combo_box::State<String>,
 | 
				
			||||||
 | 
					    file_selected: Option<String>,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					impl Default for State {
 | 
				
			||||||
 | 
					    fn default() -> Self {
 | 
				
			||||||
 | 
					        let files = if let Ok(contents) = fs::read_dir(BIBLE_DIRECTORY) {
 | 
				
			||||||
 | 
					            let paths = contents
 | 
				
			||||||
 | 
					                .into_iter()
 | 
				
			||||||
 | 
					                .filter_map(|f| f.ok())
 | 
				
			||||||
 | 
					                .map(|f| (f.path(), f.file_type()))
 | 
				
			||||||
 | 
					                .filter(|(_, f)| f.is_ok())
 | 
				
			||||||
 | 
					                .map(|(a, b)| (a, b.unwrap()))
 | 
				
			||||||
 | 
					                .filter(|(_, f)| f.is_file())
 | 
				
			||||||
 | 
					                .map(|(f, _)| f)
 | 
				
			||||||
 | 
					                .filter(|f| f.extension().is_some())
 | 
				
			||||||
 | 
					                .filter(|f| f.extension().unwrap() == "xml")
 | 
				
			||||||
 | 
					                .collect::<Vec<PathBuf>>();
 | 
				
			||||||
 | 
					            paths
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            todo!()
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					        let files = files
 | 
				
			||||||
 | 
					            .iter()
 | 
				
			||||||
 | 
					            .filter_map(|f| f.to_str())
 | 
				
			||||||
 | 
					            .map(|f| f.to_owned())
 | 
				
			||||||
 | 
					            .collect::<Vec<String>>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Self {
 | 
				
			||||||
 | 
					            files: combo_box::State::new(files),
 | 
				
			||||||
 | 
					            book: combo_box::State::new(texts::bible::BOOKS_IN_ORDER.to_vec()),
 | 
				
			||||||
 | 
					            selected: None,
 | 
				
			||||||
 | 
					            file_selected: None,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl State {
 | 
				
			||||||
 | 
					    fn update(&mut self, msg: Message) {
 | 
				
			||||||
 | 
					        match msg {
 | 
				
			||||||
 | 
					            Message::BibleSelected(file) => self.file_selected = Some(file),
 | 
				
			||||||
 | 
					            Message::BookSelected(version) => self.selected = Some(version),
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn view(&self) -> Element<Message> {
 | 
				
			||||||
 | 
					        column![
 | 
				
			||||||
 | 
					            widget::combo_box(
 | 
				
			||||||
 | 
					                &self.files,
 | 
				
			||||||
 | 
					                "Select Bible (type)",
 | 
				
			||||||
 | 
					                self.file_selected.as_ref(),
 | 
				
			||||||
 | 
					                Message::BibleSelected
 | 
				
			||||||
 | 
					            ),
 | 
				
			||||||
 | 
					            widget::combo_box(
 | 
				
			||||||
 | 
					                &self.book,
 | 
				
			||||||
 | 
					                "Select Book",
 | 
				
			||||||
 | 
					                self.selected.as_ref(),
 | 
				
			||||||
 | 
					                Message::BookSelected,
 | 
				
			||||||
 | 
					            ),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					        .into()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,10 +1,10 @@
 | 
				
			|||||||
use inline_colorization::*;
 | 
					use inline_colorization::*;
 | 
				
			||||||
use std::{fmt::Display, fs};
 | 
					use std::{fmt::Display, fs, path::PathBuf};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use quick_xml::de::from_str;
 | 
					use quick_xml::de::from_str;
 | 
				
			||||||
use serde::Deserialize;
 | 
					use serde::Deserialize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const BOOKS_IN_ORDER: [&str; 66] = [
 | 
					pub const BOOKS_IN_ORDER: [&str; 66] = [
 | 
				
			||||||
    "Genesis",
 | 
					    "Genesis",
 | 
				
			||||||
    "Exodus",
 | 
					    "Exodus",
 | 
				
			||||||
    "Leviticus",
 | 
					    "Leviticus",
 | 
				
			||||||
@@ -73,20 +73,14 @@ const BOOKS_IN_ORDER: [&str; 66] = [
 | 
				
			|||||||
    "Revelation",
 | 
					    "Revelation",
 | 
				
			||||||
];
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// This would eventaully be a list built by the user
 | 
					pub fn get(query: &str, location: &str, files: Vec<PathBuf>) {
 | 
				
			||||||
const BIBLES: [&str; 2] = [
 | 
					 | 
				
			||||||
    "/usr/local/bible/EnglishNASBBible.xml",
 | 
					 | 
				
			||||||
    "/usr/local/bible/EnglishNIVBible.xml",
 | 
					 | 
				
			||||||
];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn get(query: &str, loc: &str) {
 | 
					 | 
				
			||||||
    // expecting query to be in format:
 | 
					    // expecting query to be in format:
 | 
				
			||||||
    // Gen 1:2
 | 
					    // Gen 1:2
 | 
				
			||||||
    // Gen 1:2-5
 | 
					    // Gen 1:2-5
 | 
				
			||||||
    // Gen 1
 | 
					    // Gen 1
 | 
				
			||||||
    // The book name needs to be just long enough to be unique
 | 
					    // The book name needs to be just long enough to be unique
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let mut splits = loc.split(':');
 | 
					    let mut splits = location.split(':');
 | 
				
			||||||
    let chapter = splits.next();
 | 
					    let chapter = splits.next();
 | 
				
			||||||
    let verse = splits.next();
 | 
					    let verse = splits.next();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -114,7 +108,7 @@ pub fn get(query: &str, loc: &str) {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Load Bibles into memory
 | 
					    // Load Bibles into memory
 | 
				
			||||||
    let bibles = BIBLES
 | 
					    let bibles = files 
 | 
				
			||||||
        .iter()
 | 
					        .iter()
 | 
				
			||||||
        .filter_map(|path| fs::read_to_string(path).ok())
 | 
					        .filter_map(|path| fs::read_to_string(path).ok())
 | 
				
			||||||
        .filter_map(|contents| from_str::<Bible>(&contents).ok())
 | 
					        .filter_map(|contents| from_str::<Bible>(&contents).ok())
 | 
				
			||||||
							
								
								
									
										2
									
								
								src/texts/mod.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								src/texts/mod.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					pub mod bible;
 | 
				
			||||||
 | 
					pub mod strong;
 | 
				
			||||||
		Reference in New Issue
	
	Block a user