Compare commits
16 Commits
6d24b304ce
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| d9941b38b5 | |||
| 7442a14a8f | |||
|
|
165d946e0d | ||
|
|
d9150c302f | ||
|
|
46e4030f46 | ||
|
|
9c756f3550 | ||
|
|
035bd21466 | ||
|
|
ba260b02bc | ||
|
|
141da7c17c | ||
|
|
e487bb9a69 | ||
| 2e6eb194f8 | |||
| 82de9a07cc | |||
|
|
8a7804e780 | ||
|
|
acb49d7a4d | ||
|
|
727b2f0b51 | ||
| 789c593f7e |
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -3,4 +3,4 @@
|
|||||||
url = https://github.com/openscriptures/HebrewLexicon.git
|
url = https://github.com/openscriptures/HebrewLexicon.git
|
||||||
[submodule "Holy-Bible-XML-Format"]
|
[submodule "Holy-Bible-XML-Format"]
|
||||||
path = Holy-Bible-XML-Format
|
path = Holy-Bible-XML-Format
|
||||||
url = https://github.com/Beblia/Holy-Bible-XML-Format.git
|
url = https://github.com/Rushmore75/Holy-Bible-XML-Format.git
|
||||||
|
|||||||
Submodule Holy-Bible-XML-Format updated: 69ac8b94c9...7413606dd5
@@ -1,4 +1,4 @@
|
|||||||
# cli bible
|
# Bible
|
||||||
|
|
||||||
## Important Links
|
## Important Links
|
||||||
|
|
||||||
@@ -11,4 +11,3 @@
|
|||||||
[Tanach.us](https://tanach.us)
|
[Tanach.us](https://tanach.us)
|
||||||
|
|
||||||
[AndBible's formats](https://github.com/AndBible/and-bible/wiki/Supported-3rd-party-module-formats)
|
[AndBible's formats](https://github.com/AndBible/and-bible/wiki/Supported-3rd-party-module-formats)
|
||||||
|
|
||||||
|
|||||||
340
src/main.rs
340
src/main.rs
@@ -1,14 +1,19 @@
|
|||||||
#![feature(iter_map_windows)]
|
#![feature(iter_map_windows)]
|
||||||
use iced::widget::scrollable;
|
use iced::keyboard::key::Named;
|
||||||
|
use iced::keyboard::{Key, Modifiers};
|
||||||
|
use iced::{event, Event, Subscription};
|
||||||
|
use iced::widget::{scrollable, text_editor};
|
||||||
use iced::{
|
use iced::{
|
||||||
Element, Length, Task, Theme, clipboard, color,
|
Element, Length, Task, Theme, clipboard, color,
|
||||||
widget::{
|
widget::{
|
||||||
self, button, column, combo_box, row,
|
button, column, combo_box, row,
|
||||||
scrollable::{Direction, Scrollbar},
|
scrollable::{Direction, Scrollbar},
|
||||||
text, text_input,
|
text, text_input,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use std::fs::OpenOptions;
|
||||||
|
use std::io::{BufWriter, Write};
|
||||||
use std::{env, fs, path::PathBuf};
|
use std::{env, fs, path::PathBuf};
|
||||||
use texts::*;
|
use texts::*;
|
||||||
|
|
||||||
@@ -29,10 +34,10 @@ fn main() -> iced::Result {
|
|||||||
if let Some(second_query) = arg.get(2) {
|
if let Some(second_query) = arg.get(2) {
|
||||||
if let Ok(contents) = fs::read_to_string(&format!("{BIBLE_DIRECTORY}/EnglishNASBBible.xml")) {
|
if let Ok(contents) = fs::read_to_string(&format!("{BIBLE_DIRECTORY}/EnglishNASBBible.xml")) {
|
||||||
if let Ok(bible) = quick_xml::de::from_str::<bible::Bible>(&contents) {
|
if let Ok(bible) = quick_xml::de::from_str::<bible::Bible>(&contents) {
|
||||||
if let Some(f) = bible::get(
|
if let Ok(f) = bible::get(
|
||||||
query,
|
query,
|
||||||
second_query,
|
second_query,
|
||||||
vec![&bible],
|
&bible,
|
||||||
) {
|
) {
|
||||||
println!("{}", f);
|
println!("{}", f);
|
||||||
}
|
}
|
||||||
@@ -43,38 +48,16 @@ fn main() -> iced::Result {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ALL BUILTIN THEMES
|
|
||||||
// Light
|
|
||||||
// Dark
|
|
||||||
// Dracula
|
|
||||||
// Nord
|
|
||||||
// SolarizedLight
|
|
||||||
// SolarizedDark
|
|
||||||
// GruvboxLight
|
|
||||||
// GruvboxDark
|
|
||||||
// CatppuccinLatte
|
|
||||||
// CatppuccinFrappe
|
|
||||||
// CatppuccinMacchiato
|
|
||||||
// CatppuccinMocha
|
|
||||||
// TokyoNight
|
|
||||||
// TokyoNightStorm
|
|
||||||
// TokyoNightLight
|
|
||||||
// KanagawaWave
|
|
||||||
// KanagawaDragon
|
|
||||||
// KanagawaLotus
|
|
||||||
// Moonfly
|
|
||||||
// Nightfly
|
|
||||||
// Oxocarbon
|
|
||||||
// Ferra
|
|
||||||
|
|
||||||
// GUI
|
// GUI
|
||||||
iced::application("Bible Study", State::update, State::view)
|
iced::application("Bible Study", State::update, State::view)
|
||||||
.theme(|_| Theme::Nord)
|
.subscription(State::subscription)
|
||||||
|
.theme(State::theme)
|
||||||
.run()
|
.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum Message {
|
enum Message {
|
||||||
|
CycleTheme,
|
||||||
BibleSearchInput(usize, String),
|
BibleSearchInput(usize, String),
|
||||||
BibleSelected(usize, String),
|
BibleSelected(usize, String),
|
||||||
BibleSearchSubmit(usize),
|
BibleSearchSubmit(usize),
|
||||||
@@ -82,26 +65,56 @@ enum Message {
|
|||||||
Clear(usize),
|
Clear(usize),
|
||||||
WordSearchInput(usize, String),
|
WordSearchInput(usize, String),
|
||||||
SubmitWordSearch(usize),
|
SubmitWordSearch(usize),
|
||||||
QuickSearch(usize, String),
|
QuickSearch(usize, String, usize),
|
||||||
AddColRight,
|
AddColRight,
|
||||||
DeleteColumn(usize),
|
DeleteColumn(usize),
|
||||||
|
SetErrorMessage(usize, String),
|
||||||
|
RecievedEvent(Event),
|
||||||
|
NoteInput(usize, text_editor::Action),
|
||||||
|
Save,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Message {
|
||||||
|
fn get_col_idx(&self) -> Option<usize> {
|
||||||
|
match self {
|
||||||
|
Message::SetErrorMessage(i, _) |
|
||||||
|
Message::BibleSearchInput(i, _) |
|
||||||
|
Message::BibleSelected(i, _) |
|
||||||
|
Message::BibleSearchSubmit(i) |
|
||||||
|
Message::CopyText(i) |
|
||||||
|
Message::Clear(i) |
|
||||||
|
Message::WordSearchInput(i, _) |
|
||||||
|
Message::SubmitWordSearch(i) |
|
||||||
|
Message::QuickSearch(i, _, _) |
|
||||||
|
Message::DeleteColumn(i) |
|
||||||
|
Message::NoteInput(i, _)
|
||||||
|
=> {
|
||||||
|
Some(*i)
|
||||||
|
},
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ColState {
|
struct ColState {
|
||||||
selected_file: Option<String>,
|
file: Option<String>,
|
||||||
bible_selected: Option<bible::Bible>,
|
bible_selected: Option<bible::Bible>,
|
||||||
|
|
||||||
bible_search: String,
|
bible_search: String,
|
||||||
scripture_body: Option<String>,
|
scripture_body: Option<String>,
|
||||||
|
|
||||||
word_search: String,
|
word_search: String,
|
||||||
word_search_results: Option<Vec<String>>,
|
word_search_results: Option<Vec<(String, bool)>>,
|
||||||
|
|
||||||
|
notes: text_editor::Content,
|
||||||
|
|
||||||
|
error: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ColState {
|
impl Default for ColState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
selected_file: None,
|
file: None,
|
||||||
bible_selected: None,
|
bible_selected: None,
|
||||||
|
|
||||||
bible_search: String::new(),
|
bible_search: String::new(),
|
||||||
@@ -109,6 +122,10 @@ impl Default for ColState {
|
|||||||
|
|
||||||
word_search: String::new(),
|
word_search: String::new(),
|
||||||
word_search_results: None,
|
word_search_results: None,
|
||||||
|
|
||||||
|
notes: text_editor::Content::new(),
|
||||||
|
|
||||||
|
error: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,7 +133,12 @@ impl Default for ColState {
|
|||||||
struct State {
|
struct State {
|
||||||
files: combo_box::State<String>,
|
files: combo_box::State<String>,
|
||||||
states: Vec<ColState>,
|
states: Vec<ColState>,
|
||||||
cols: usize,
|
// cols: usize,
|
||||||
|
tab_index: Option<i32>,
|
||||||
|
|
||||||
|
theme_idx: usize,
|
||||||
|
themes: [Theme; 3],
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for State {
|
impl Default for State {
|
||||||
@@ -146,38 +168,159 @@ impl Default for State {
|
|||||||
Self {
|
Self {
|
||||||
files: combo_box::State::new(files),
|
files: combo_box::State::new(files),
|
||||||
states: vec![ColState::default()],
|
states: vec![ColState::default()],
|
||||||
cols: 1,
|
// cols: 1,
|
||||||
|
tab_index: None,
|
||||||
|
// THEMES
|
||||||
|
// Dark - KanagawaDragon
|
||||||
|
// Default - Nord
|
||||||
|
// Light - TokyoNightLight
|
||||||
|
theme_idx: 0,
|
||||||
|
themes: [
|
||||||
|
Theme::KanagawaDragon,
|
||||||
|
Theme::Nord,
|
||||||
|
Theme::TokyoNightLight
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
|
fn theme(&self) -> Theme {
|
||||||
|
self.themes[self.theme_idx].clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn subscription(&self) -> Subscription<Message> {
|
||||||
|
event::listen().map(Message::RecievedEvent)
|
||||||
|
}
|
||||||
|
|
||||||
fn update(&mut self, msg: Message) -> Task<Message> {
|
fn update(&mut self, msg: Message) -> Task<Message> {
|
||||||
|
// clear error messages
|
||||||
|
if let Some(idx) = msg.get_col_idx() {
|
||||||
|
self.states[idx].error = None
|
||||||
|
}
|
||||||
|
// match normal messages
|
||||||
match msg {
|
match msg {
|
||||||
|
Message::Save => {
|
||||||
|
let opt = OpenOptions::new()
|
||||||
|
// create if doesn't already exist
|
||||||
|
.create(true)
|
||||||
|
.append(false)
|
||||||
|
// clear existing file
|
||||||
|
.truncate(true)
|
||||||
|
.write(true)
|
||||||
|
.open("save.md")
|
||||||
|
;
|
||||||
|
match opt {
|
||||||
|
Ok(file) => {
|
||||||
|
let mut buffer = BufWriter::new(file);
|
||||||
|
|
||||||
|
// the toml heading at the top of md files
|
||||||
|
let _ = buffer.write_all("---\n---\n".as_bytes());
|
||||||
|
|
||||||
|
for col in &self.states {
|
||||||
|
// separate each col with hr
|
||||||
|
let _ = buffer.write_all("\n---\n".as_bytes());
|
||||||
|
if let Some(scripture) = &col.scripture_body {
|
||||||
|
// code block for scripture
|
||||||
|
let _ = buffer.write_all("```\n".as_bytes());
|
||||||
|
let _ = buffer.write_all(parse(scripture).as_bytes());
|
||||||
|
let _ = buffer.write_all("```\n".as_bytes());
|
||||||
|
}
|
||||||
|
let _ = buffer.write_all(&col.notes.text().as_bytes());
|
||||||
|
}
|
||||||
|
let _ = buffer.flush();
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("{err}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Message::NoteInput(i, action) => {
|
||||||
|
let notes = &mut self.states[i].notes;
|
||||||
|
notes.perform(action);
|
||||||
|
},
|
||||||
|
Message::CycleTheme => {
|
||||||
|
let len = self.themes.len();
|
||||||
|
let i = &mut self.theme_idx;
|
||||||
|
if *i == len-1 {
|
||||||
|
*i = 0;
|
||||||
|
} else {
|
||||||
|
*i += 1;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Message::RecievedEvent(event) => {
|
||||||
|
if let Event::Keyboard(kbd) = event {
|
||||||
|
if let iced::keyboard::Event::KeyReleased {key, modifiers, ..} = kbd {
|
||||||
|
if let Key::Named(n) = key {
|
||||||
|
if let Named::Tab = n {
|
||||||
|
if let Some(idx) = self.tab_index {
|
||||||
|
let new_idx = if modifiers == Modifiers::SHIFT { idx-1 } else { idx+1 };
|
||||||
|
|
||||||
|
// 2 because two buttons on each col
|
||||||
|
let new_idx = new_idx.clamp(0, (self.states.len()*2) as i32 -1);
|
||||||
|
self.tab_index = Some(new_idx);
|
||||||
|
|
||||||
|
let id = format!("tabId-{}", new_idx);
|
||||||
|
return text_input::focus(id);
|
||||||
|
} else {
|
||||||
|
if self.states.len() > 0 {
|
||||||
|
self.tab_index = Some(0);
|
||||||
|
return text_input::focus("tabId-0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Message::SetErrorMessage(i, m) => {
|
||||||
|
self.states[i].error = Some(m);
|
||||||
|
}
|
||||||
Message::DeleteColumn(idx) => {
|
Message::DeleteColumn(idx) => {
|
||||||
self.cols -= 1;
|
// self.cols -= 1;
|
||||||
self.states.remove(idx);
|
self.states.remove(idx);
|
||||||
}
|
}
|
||||||
Message::AddColRight => {
|
Message::AddColRight => {
|
||||||
self.cols += 1;
|
self.states.push(ColState::default());
|
||||||
// clone this state into the new one
|
|
||||||
// self.states.push(self.states.into_iter().last().unwrap().clone())
|
// Add the rightmost opened Bible to the new column
|
||||||
self.states.push(ColState::default())
|
if let Some(last) = self.states.get(self.states.len()-2) {
|
||||||
|
let file = &last.file;
|
||||||
|
if let Some(file) = file {
|
||||||
|
return self.update(Message::BibleSelected(self.states.len()-1, file.to_string()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
Message::BibleSelected(i, file) => {
|
Message::BibleSelected(i, file) => {
|
||||||
if let Ok(contents) = fs::read_to_string(&file) {
|
match fs::read_to_string(&file) {
|
||||||
if let Ok(bible) = quick_xml::de::from_str::<bible::Bible>(&contents) {
|
Ok(contents) => {
|
||||||
|
match quick_xml::de::from_str::<bible::Bible>(&contents) {
|
||||||
|
Ok(bible) => {
|
||||||
// State is held technically in this variable, although
|
// State is held technically in this variable, although
|
||||||
// the Bible is held in memory in it's own variable.
|
// the Bible is held in memory in it's own variable.
|
||||||
self.states[i].selected_file = Some(format!("{bible}"));
|
|
||||||
self.states[i].bible_selected = Some(bible);
|
self.states[i].bible_selected = Some(bible);
|
||||||
// automatically focus the search bar when done here
|
self.states[i].file = Some(file);
|
||||||
// return text_input::focus("bible-search");
|
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("{}", err);
|
||||||
|
return self.update(Message::SetErrorMessage(i, err.to_string()));
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("{}", err);
|
||||||
|
return self.update(Message::SetErrorMessage(i, err.to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::QuickSearch(i, s) => {
|
Message::QuickSearch(i, s, result_index) => {
|
||||||
self.states[i].bible_search = s;
|
self.states[i].bible_search = s;
|
||||||
|
if let Some(wsr) = &mut self.states[i].word_search_results {
|
||||||
|
// set "visited" for this link
|
||||||
|
wsr[result_index].1 = true;
|
||||||
|
}
|
||||||
return self.update(Message::BibleSearchSubmit(i));
|
return self.update(Message::BibleSearchSubmit(i));
|
||||||
}
|
}
|
||||||
Message::BibleSearchInput(i, query) => self.states[i].bible_search = query,
|
Message::BibleSearchInput(i, query) => self.states[i].bible_search = query,
|
||||||
@@ -190,13 +333,35 @@ impl State {
|
|||||||
if let (Some(book), Some(chap_and_ver), Some(bible)) =
|
if let (Some(book), Some(chap_and_ver), Some(bible)) =
|
||||||
(book, location, &self.states[i].bible_selected)
|
(book, location, &self.states[i].bible_selected)
|
||||||
{
|
{
|
||||||
self.states[i].scripture_body = bible::get(book, chap_and_ver, vec![bible]);
|
self.states[i].scripture_body = match bible::get(book, chap_and_ver, bible) {
|
||||||
|
Ok(s) => {
|
||||||
|
Some(s)
|
||||||
|
},
|
||||||
|
Err(s) => {
|
||||||
|
return self.update(Message::SetErrorMessage(i, s));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
if let None = book {
|
||||||
|
return self.update(Message::SetErrorMessage(i, format!("Error selecting book {:?}", book)));
|
||||||
|
}
|
||||||
|
if let None = location {
|
||||||
|
return self.update(Message::SetErrorMessage(i, format!("Error getting chapter and/or verse {:?}", location)));
|
||||||
|
}
|
||||||
|
if let None = &self.states[i].bible_selected {
|
||||||
|
return self.update(Message::SetErrorMessage(i, format!("Error getting selected bible")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::SubmitWordSearch(i) => {
|
Message::SubmitWordSearch(i) => {
|
||||||
if let Some(bible) = &self.states[i].bible_selected {
|
if let Some(bible) = &self.states[i].bible_selected {
|
||||||
let res = bible::search_for_word(&self.states[i].word_search, bible);
|
let res = bible::search_for_word(&self.states[i].word_search, bible);
|
||||||
self.states[i].word_search_results = Some(res);
|
self.states[i].word_search_results = Some(
|
||||||
|
res
|
||||||
|
.into_iter()
|
||||||
|
.map(|f| (f, false))
|
||||||
|
.collect()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::CopyText(i) => {
|
Message::CopyText(i) => {
|
||||||
@@ -209,37 +374,55 @@ impl State {
|
|||||||
self.states[i].word_search_results = None;
|
self.states[i].word_search_results = None;
|
||||||
self.states[i].bible_search = String::new();
|
self.states[i].bible_search = String::new();
|
||||||
self.states[i].word_search = String::new();
|
self.states[i].word_search = String::new();
|
||||||
// return text_input::focus("bible-search");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Element<Message> {
|
fn view(&self) -> Element<Message> {
|
||||||
|
|
||||||
|
// TODO make this dynamic
|
||||||
|
// max height that the scripture body can be
|
||||||
|
// max height that the search resutls can be
|
||||||
|
let max_height = 600;
|
||||||
|
|
||||||
|
// Header bar, static, doesn't scroll
|
||||||
|
column![
|
||||||
|
row![
|
||||||
|
button("Cycle Themes")
|
||||||
|
.on_press(Message::CycleTheme)
|
||||||
|
.style(button::secondary)
|
||||||
|
,
|
||||||
|
button("Save")
|
||||||
|
.on_press(Message::Save)
|
||||||
|
.style(button::secondary)
|
||||||
|
,
|
||||||
|
],
|
||||||
scrollable(
|
scrollable(
|
||||||
row![
|
row![
|
||||||
row((0..self.cols).map(|col_index| {
|
row((0..self.states.len()).map(|col_index| {
|
||||||
column![
|
column![
|
||||||
// header
|
// Top of Column, text entry boxes
|
||||||
button("Delete Column")
|
|
||||||
.on_press_with(move || Message::DeleteColumn(col_index))
|
|
||||||
.width(Length::Fill)
|
|
||||||
.style(button::danger),
|
|
||||||
combo_box(
|
combo_box(
|
||||||
&self.files,
|
&self.files,
|
||||||
"Select Bible",
|
"Select Bible",
|
||||||
self.states[col_index].selected_file.as_ref(),
|
// Some(&"IDK where this text is".to_string()),
|
||||||
|
match &self.states[col_index].bible_selected {
|
||||||
|
Some(b) => Some(&b.translation_name),
|
||||||
|
None => None,
|
||||||
|
},
|
||||||
move |s| Message::BibleSelected(col_index, s)
|
move |s| Message::BibleSelected(col_index, s)
|
||||||
),
|
),
|
||||||
text_input(
|
text_input("Search query, ie: Gen 1:1", &self.states[col_index].bible_search)
|
||||||
"Search query, ie: Gen 1:1",
|
.id(format!("tabId-{}", (col_index*2)+0))
|
||||||
&self.states[col_index].bible_search
|
|
||||||
)
|
|
||||||
.on_input(move |s| Message::BibleSearchInput(col_index, s))
|
.on_input(move |s| Message::BibleSearchInput(col_index, s))
|
||||||
.on_submit(Message::BibleSearchSubmit(col_index)),
|
.on_submit(Message::BibleSearchSubmit(col_index)),
|
||||||
widget::text_input("Word Search", &self.states[col_index].word_search)
|
text_input("Word Search", &self.states[col_index].word_search)
|
||||||
|
.id(format!("tabId-{}", (col_index*2)+1))
|
||||||
.on_input(move |s| Message::WordSearchInput(col_index, s))
|
.on_input(move |s| Message::WordSearchInput(col_index, s))
|
||||||
.on_submit(Message::SubmitWordSearch(col_index)),
|
.on_submit(Message::SubmitWordSearch(col_index)),
|
||||||
|
|
||||||
|
// Horizontal Row just above scripture
|
||||||
row![
|
row![
|
||||||
button("Clear All")
|
button("Clear All")
|
||||||
.on_press_with(move || Message::Clear(col_index))
|
.on_press_with(move || Message::Clear(col_index))
|
||||||
@@ -247,8 +430,14 @@ impl State {
|
|||||||
button("Copy Scripture")
|
button("Copy Scripture")
|
||||||
.on_press_with(move || Message::CopyText(col_index))
|
.on_press_with(move || Message::CopyText(col_index))
|
||||||
.style(button::primary),
|
.style(button::primary),
|
||||||
|
button("Delete Column")
|
||||||
|
.on_press_with(move || Message::DeleteColumn(col_index))
|
||||||
|
.style(button::danger),
|
||||||
|
text(format!("{}", self.states[col_index].error.clone().unwrap_or(String::new())))
|
||||||
|
.style(text::danger),
|
||||||
]
|
]
|
||||||
.spacing(5),
|
.spacing(5),
|
||||||
|
// Body
|
||||||
row![
|
row![
|
||||||
// Word search results
|
// Word search results
|
||||||
scrollable(
|
scrollable(
|
||||||
@@ -258,20 +447,32 @@ impl State {
|
|||||||
.clone()
|
.clone()
|
||||||
.unwrap_or(Vec::new())
|
.unwrap_or(Vec::new())
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|i| button(text(i.clone()))
|
.enumerate()
|
||||||
|
.map(|(idx,i)| {
|
||||||
|
let style = if i.1 {
|
||||||
|
button::secondary
|
||||||
|
} else {
|
||||||
|
button::primary
|
||||||
|
};
|
||||||
|
button(text(i.0.clone()))
|
||||||
|
.style(style)
|
||||||
.on_press_with(move || Message::QuickSearch(
|
.on_press_with(move || Message::QuickSearch(
|
||||||
col_index,
|
col_index,
|
||||||
i.to_owned()
|
i.0.to_owned(),
|
||||||
|
idx
|
||||||
))
|
))
|
||||||
.into())
|
.into()
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.padding([5, 5])
|
.padding([5, 5])
|
||||||
)
|
)
|
||||||
|
.height(max_height)
|
||||||
.spacing(5),
|
.spacing(5),
|
||||||
// Body
|
// Scripture
|
||||||
scrollable(
|
scrollable(
|
||||||
if let Some(body) = &self.states[col_index].scripture_body {
|
if let Some(body) = &self.states[col_index].scripture_body {
|
||||||
column(body.split("\n").enumerate().map(|(i, msg)| {
|
column(body.split("\n").enumerate().map(|(i, msg)| {
|
||||||
|
// Color every other verse slightly differently
|
||||||
let msg = parse(msg);
|
let msg = parse(msg);
|
||||||
if i & 1 == 0 {
|
if i & 1 == 0 {
|
||||||
text(msg.to_owned()).color(color![0xFFFFFF]).into()
|
text(msg.to_owned()).color(color![0xFFFFFF]).into()
|
||||||
@@ -287,13 +488,21 @@ impl State {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
.height(max_height)
|
||||||
.spacing(5)
|
.spacing(5)
|
||||||
],
|
],
|
||||||
|
// Notes
|
||||||
|
text_editor(&self.states[col_index].notes)
|
||||||
|
.placeholder("Notes...")
|
||||||
|
.on_action(move |a| Message::NoteInput(col_index, a))
|
||||||
|
.height(100)
|
||||||
|
// .id(format!("tabId-{}", (col_index*2)+2))
|
||||||
]
|
]
|
||||||
.spacing(5)
|
.spacing(5)
|
||||||
.width(800.)
|
.width(800.)
|
||||||
.into()
|
.into()
|
||||||
})),
|
})),
|
||||||
|
// Right most vertical buttons
|
||||||
button(text("+").center())
|
button(text("+").center())
|
||||||
.height(Length::Fixed(200.))
|
.height(Length::Fixed(200.))
|
||||||
.style(button::primary)
|
.style(button::primary)
|
||||||
@@ -305,6 +514,7 @@ impl State {
|
|||||||
.spacing(5),
|
.spacing(5),
|
||||||
)
|
)
|
||||||
.direction(Direction::Horizontal(Scrollbar::new()))
|
.direction(Direction::Horizontal(Scrollbar::new()))
|
||||||
|
]
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,19 +102,9 @@ pub fn search_for_word(word: &str, from_files: &Bible) -> Vec<String> {
|
|||||||
found
|
found
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(book: &str, chap_and_ver: &str, bibles: Vec<&Bible>) -> Option<String> {
|
fn parse_book(book: &str) -> Result<(usize, &str), String> {
|
||||||
// expecting query to be in format:
|
// Go thru the list of books and see which
|
||||||
// Gen 1:2
|
// match the passed book str
|
||||||
// Gen 1:2-5
|
|
||||||
// Gen 1
|
|
||||||
// The book name needs to be just long enough to be unique
|
|
||||||
|
|
||||||
let mut splits = chap_and_ver.split(':');
|
|
||||||
let chapter = splits.next();
|
|
||||||
let verse = splits.next();
|
|
||||||
|
|
||||||
// ###########################################
|
|
||||||
// Figure out what book they are talking about
|
|
||||||
let res = BOOKS_IN_ORDER
|
let res = BOOKS_IN_ORDER
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
@@ -129,47 +119,66 @@ pub fn get(book: &str, chap_and_ver: &str, bibles: Vec<&Bible>) -> Option<String
|
|||||||
.collect::<Vec<(usize, &&str)>>();
|
.collect::<Vec<(usize, &&str)>>();
|
||||||
|
|
||||||
let (book_idx, book_name) = match res.len() {
|
let (book_idx, book_name) = match res.len() {
|
||||||
|
// there is one option for what book it is
|
||||||
1 => res[0],
|
1 => res[0],
|
||||||
|
// there are >1 options for what book it is
|
||||||
2.. => {
|
2.. => {
|
||||||
eprintln!("Err: Ambigious input '{book}', could be any of:");
|
eprintln!("Err: Ambigious input '{book}', could be any of:");
|
||||||
for (_, i) in &res {
|
for (_, i) in &res {
|
||||||
eprintln!("\t{i}");
|
eprintln!("\t{i}");
|
||||||
}
|
}
|
||||||
return None;
|
return Err(format!("Ambigious input '{book}'"));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
eprintln!("'{book}' is not a book");
|
eprintln!("'{book}' is not a book");
|
||||||
return None;
|
return Err(format!("'{book}' is not a book"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Ok((book_idx, book_name))
|
||||||
|
}
|
||||||
|
|
||||||
// Select the book in each Bible
|
fn parse_chapter<'a>(chapter_num: &str, book: &'a Book) -> Result<&'a Chapter, String> {
|
||||||
let books = bibles
|
let chapter = if let Ok(idx) = chapter_num.parse::<usize>() {
|
||||||
.iter()
|
if let Some(chapter) = book.get_chapter_by_index(idx) {
|
||||||
// Book are 1 indexed in the xml spec
|
chapter
|
||||||
.map(|bible| (bible, bible.get_book_by_index(book_idx + 1)))
|
|
||||||
.filter(|(_,e)| e.is_some())
|
|
||||||
.map(|(bible,book)| (*bible,book.unwrap()))
|
|
||||||
.collect::<Vec<(&Bible,&Book)>>();
|
|
||||||
|
|
||||||
// Select the chapter in each Bible
|
|
||||||
let chapters = if let Some(chapter) = chapter {
|
|
||||||
if let Ok(ch_num) = chapter.parse::<usize>() {
|
|
||||||
books
|
|
||||||
.iter()
|
|
||||||
.map(|(bible,book)| (bible, book, book.get_chapter_by_index(ch_num)))
|
|
||||||
.filter(|(_,_,book)| book.is_some())
|
|
||||||
.map(|(bible,book,chapter)| (*bible,*book,chapter.unwrap()))
|
|
||||||
.collect::<Vec<(&Bible, &Book, &Chapter)>>()
|
|
||||||
} else {
|
} else {
|
||||||
return None;
|
return Err(format!("Chapter {idx} doesn't exist in book {}", BOOKS_IN_ORDER[book.number-1]));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return None;
|
return Err(format!("Chapter number could not be parsed from {chapter_num}"));
|
||||||
|
};
|
||||||
|
Ok(chapter)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get(book: &str, chap_and_ver: &str, bible: &Bible) -> Result<String, String> {
|
||||||
|
// 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 = chap_and_ver.split(':');
|
||||||
|
let chapter_num = splits.next();
|
||||||
|
let verse_num = splits.next();
|
||||||
|
// ###########################################
|
||||||
|
|
||||||
|
// Figure out what book they are talking about
|
||||||
|
let (book_idx, book_name) = parse_book(book)?;
|
||||||
|
|
||||||
|
let book = match bible.get_book_by_index(book_idx+1) {
|
||||||
|
Some(s) => s,
|
||||||
|
None => return Err(format!("Selected Bible {} doesn't contain book {book_name}", bible.translation_name)),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Figure out what chapter they are talking about
|
||||||
|
let chapter = if let Some(ch) = chapter_num {
|
||||||
|
parse_chapter(ch, book)?
|
||||||
|
} else {
|
||||||
|
return Err("No chapter number was passed".to_string());
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get the verse in each Bible
|
// Get the verse in each Bible
|
||||||
match verse {
|
match verse_num {
|
||||||
Some(verse) => {
|
Some(verse) => {
|
||||||
let mut splits = verse.split("-");
|
let mut splits = verse.split("-");
|
||||||
let start = splits.next();
|
let start = splits.next();
|
||||||
@@ -180,53 +189,50 @@ pub fn get(book: &str, chap_and_ver: &str, bibles: Vec<&Bible>) -> Option<String
|
|||||||
(Some(sn), Some(en)) => {
|
(Some(sn), Some(en)) => {
|
||||||
if let (Ok(start), Ok(end)) = (sn.parse::<usize>(), en.parse::<usize>()) {
|
if let (Ok(start), Ok(end)) = (sn.parse::<usize>(), en.parse::<usize>()) {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
|
||||||
|
let translation = &bible.translation_name;
|
||||||
|
|
||||||
|
buf += &format!("{style_bold}[{translation}] {style_underline}{book_name} {}:{start}-{end}{style_reset}:\n", chapter.number);
|
||||||
for num in start..=end {
|
for num in start..=end {
|
||||||
for (bible, _book, chapter) in &chapters {
|
|
||||||
if let Some(verse) = chapter.get_verse_by_index(num) {
|
if let Some(verse) = chapter.get_verse_by_index(num) {
|
||||||
buf += &format!(
|
buf += &format!(
|
||||||
"{style_bold}[{}] {style_underline}{book_name} {}:{}{style_reset}: {verse}\n",
|
"{}: {verse}\n", verse.number
|
||||||
bible.translation_name, chapter.number, verse.number
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return Ok(buf);
|
||||||
}
|
}
|
||||||
return Some(buf);
|
return Err(format!("Could not parse '{sn}' or '{en}' into numbers"));
|
||||||
}
|
|
||||||
return None;
|
|
||||||
}
|
}
|
||||||
// only one verse
|
// only one verse
|
||||||
(Some(ver_num), None) => {
|
(Some(ver_num), None) => {
|
||||||
if let Ok(num) = ver_num.parse::<usize>() {
|
if let Ok(num) = ver_num.parse::<usize>() {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
for (bible, _book, chapter) in chapters {
|
|
||||||
if let Some(verse) = chapter.get_verse_by_index(num) {
|
if let Some(verse) = chapter.get_verse_by_index(num) {
|
||||||
buf += &format!(
|
buf += &format!(
|
||||||
"{style_bold}[{}] {style_underline}{book_name} {}:{}{style_reset}: {verse}\n",
|
"{style_bold}[{}] {style_underline}{book_name} {}:{}{style_reset}:\n{verse}\n",
|
||||||
bible.translation_name, chapter.number, verse.number
|
bible.translation_name, chapter.number, verse.number
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return Ok(buf);
|
||||||
}
|
}
|
||||||
return Some(buf);
|
return Err(format!("Could not parse '{ver_num}' into a number"));
|
||||||
}
|
|
||||||
return None;
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// couldn't parse verse
|
// couldn't parse verse
|
||||||
return None;
|
return Err(format!("Couldn't parse '{:?}' or '{:?}' into verse numbers", start, end));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// only chapter
|
// only chapter
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
for (bible, _, chapter) in chapters {
|
|
||||||
buf += &format!(
|
buf += &format!(
|
||||||
"{style_bold}[{}] {style_underline}{book_name} {}{style_reset}:\n",
|
"{style_bold}[{}] {style_underline}{book_name} {}{style_reset}:\n",
|
||||||
bible.translation_name, chapter.number
|
bible.translation_name, chapter.number
|
||||||
);
|
);
|
||||||
buf += &format!("{}", chapter);
|
buf += &format!("{}", chapter);
|
||||||
}
|
return Ok(buf);
|
||||||
return Some(buf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -269,15 +275,10 @@ impl Chapter {
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Bible {
|
pub struct Bible {
|
||||||
#[serde(rename = "@translation")]
|
#[serde(rename = "@translation")]
|
||||||
translation_name: String,
|
pub translation_name: String,
|
||||||
#[serde(rename = "testament")]
|
#[serde(rename = "testament")]
|
||||||
testaments: Vec<Testament>,
|
testaments: Vec<Testament>,
|
||||||
}
|
}
|
||||||
impl Display for Bible {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(f, "{}",self.translation_name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Testament {
|
struct Testament {
|
||||||
@@ -291,6 +292,7 @@ struct Testament {
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Book {
|
struct Book {
|
||||||
#[serde(rename = "@number")]
|
#[serde(rename = "@number")]
|
||||||
|
/// Genesis is book 1
|
||||||
number: usize,
|
number: usize,
|
||||||
#[serde(rename = "chapter")]
|
#[serde(rename = "chapter")]
|
||||||
chapters: Vec<Chapter>,
|
chapters: Vec<Chapter>,
|
||||||
|
|||||||
Reference in New Issue
Block a user