merge GUI #1

Merged
Oliver merged 9 commits from gui into master 2025-04-02 06:37:38 +00:00
4 changed files with 101 additions and 19 deletions
Showing only changes of commit 09acb5af50 - Show all commits

View File

@ -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 bible;
mod texts;
fn main() {
pub const BIBLE_DIRECTORY: &str = "./Holy-Bible-XML-Format";
fn main() -> iced::Result {
let arg = env::args().collect::<Vec<String>>();
if let Some(query) = arg.get(1) {
if query.starts_with("H") | query.starts_with("h") {
if let Some(found) = strong::get(query) {
print!("{found}");
return;
return Ok(());
}
}
if let Some(second_query) = arg.get(2) {
bible::get(query,second_query);
}
if let Some(second_query) = arg.get(2) {
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()
}
}

View File

@ -1,10 +1,10 @@
use inline_colorization::*;
use std::{fmt::Display, fs};
use std::{fmt::Display, fs, path::PathBuf};
use quick_xml::de::from_str;
use serde::Deserialize;
const BOOKS_IN_ORDER: [&str; 66] = [
pub const BOOKS_IN_ORDER: [&str; 66] = [
"Genesis",
"Exodus",
"Leviticus",
@ -73,20 +73,14 @@ const BOOKS_IN_ORDER: [&str; 66] = [
"Revelation",
];
// This would eventaully be a list built by the user
const BIBLES: [&str; 2] = [
"/usr/local/bible/EnglishNASBBible.xml",
"/usr/local/bible/EnglishNIVBible.xml",
];
pub fn get(query: &str, loc: &str) {
pub fn get(query: &str, location: &str, files: Vec<PathBuf>) {
// expecting query to be in format:
// Gen 1:2
// Gen 1:2-5
// Gen 1
// 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 verse = splits.next();
@ -114,7 +108,7 @@ pub fn get(query: &str, loc: &str) {
};
// Load Bibles into memory
let bibles = BIBLES
let bibles = files
.iter()
.filter_map(|path| fs::read_to_string(path).ok())
.filter_map(|contents| from_str::<Bible>(&contents).ok())

2
src/texts/mod.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod bible;
pub mod strong;