- Refactored code to return text
- This is to make sending data to the TUI easier
This commit is contained in:
parent
305b74abd3
commit
2fe2421e6d
44
.github/workflows/rust.yml
vendored
44
.github/workflows/rust.yml
vendored
@ -1,22 +1,22 @@
|
||||
name: Rust
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Build
|
||||
run: cargo build --verbose
|
||||
- name: Run tests
|
||||
run: cargo test --verbose
|
||||
name: Rust
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Build
|
||||
run: cargo build --verbose
|
||||
- name: Run tests
|
||||
run: cargo test --verbose
|
||||
|
22
.gitignore
vendored
22
.gitignore
vendored
@ -1,11 +1,11 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||
Cargo.lock
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
*.epub
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||
Cargo.lock
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
*.epub
|
||||
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -1,48 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AutoImportSettings">
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="CMakeSettings">
|
||||
<configurations>
|
||||
<configuration PROFILE_NAME="Debug" ENABLED="true" CONFIG_NAME="Debug" />
|
||||
</configurations>
|
||||
</component>
|
||||
<component name="CargoProjects">
|
||||
<cargoProject FILE="$PROJECT_DIR$/Cargo.toml" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="81820af5-b0ad-4ac7-a939-e3db68fc7214" name="Changes" comment="- Can now format HTML - No longer returns to main.rs. Main function in html_module.rs now reads to console locally.">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/main.rs" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="ClangdSettings">
|
||||
<option name="formatViaClangd" value="false" />
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_BRANCH_BY_REPOSITORY">
|
||||
<map>
|
||||
<entry key="$PROJECT_DIR$" value="master" />
|
||||
</map>
|
||||
</option>
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="MacroExpansionManager">
|
||||
<option name="directoryName" value="3emh3loa" />
|
||||
</component>
|
||||
<component name="MarkdownSettingsMigration">
|
||||
<option name="stateVersion" value="1" />
|
||||
</component>
|
||||
<component name="ProjectId" id="2PqGkAwNc4bG190Io9DyS4FEdlC" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AutoImportSettings">
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="CMakeSettings">
|
||||
<configurations>
|
||||
<configuration PROFILE_NAME="Debug" ENABLED="true" CONFIG_NAME="Debug" />
|
||||
</configurations>
|
||||
</component>
|
||||
<component name="CargoProjects">
|
||||
<cargoProject FILE="$PROJECT_DIR$/Cargo.toml" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="81820af5-b0ad-4ac7-a939-e3db68fc7214" name="Changes" comment="- Can now format HTML - No longer returns to main.rs. Main function in html_module.rs now reads to console locally.">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/html_module.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/html_module.rs" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/main.rs" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="ClangdSettings">
|
||||
<option name="formatViaClangd" value="false" />
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_BRANCH_BY_REPOSITORY">
|
||||
<map>
|
||||
<entry key="$PROJECT_DIR$" value="master" />
|
||||
</map>
|
||||
</option>
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="MacroExpansionManager">
|
||||
<option name="directoryName" value="3emh3loa" />
|
||||
</component>
|
||||
<component name="MarkdownSettingsMigration">
|
||||
<option name="stateVersion" value="1" />
|
||||
</component>
|
||||
<component name="ProjectId" id="2PqGkAwNc4bG190Io9DyS4FEdlC" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
@ -59,125 +60,128 @@
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"org.rust.cargo.project.model.PROJECT_DISCOVERY": "true",
|
||||
"org.rust.disableDetachedFileInspectionD:/bibliofile/src/html_module.rs": "true",
|
||||
"org.rust.disableDetachedFileInspectionD:/bibliofile/src/main.rs": "true",
|
||||
"settings.editor.selected.configurable": "org.jetbrains.plugins.github.ui.GithubSettingsConfigurable",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
}
|
||||
}]]></component>
|
||||
<component name="RunManager" selected="Cargo.Check">
|
||||
<configuration name="Check" type="CargoCommandRunConfiguration" factoryName="Cargo Command" nameIsGenerated="true">
|
||||
<option name="command" value="check" />
|
||||
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||
<option name="emulateTerminal" value="false" />
|
||||
<option name="channel" value="DEFAULT" />
|
||||
<option name="requiredFeatures" value="true" />
|
||||
<option name="allFeatures" value="false" />
|
||||
<option name="withSudo" value="false" />
|
||||
<option name="buildTarget" value="REMOTE" />
|
||||
<option name="backtrace" value="SHORT" />
|
||||
<envs />
|
||||
<option name="isRedirectInput" value="false" />
|
||||
<option name="redirectInputPath" value="" />
|
||||
<method v="2">
|
||||
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="Run" type="CargoCommandRunConfiguration" factoryName="Cargo Command" nameIsGenerated="true">
|
||||
<option name="command" value="run pg2680.epub" />
|
||||
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||
<option name="emulateTerminal" value="false" />
|
||||
<option name="channel" value="DEFAULT" />
|
||||
<option name="requiredFeatures" value="true" />
|
||||
<option name="allFeatures" value="false" />
|
||||
<option name="withSudo" value="false" />
|
||||
<option name="buildTarget" value="REMOTE" />
|
||||
<option name="backtrace" value="SHORT" />
|
||||
<envs />
|
||||
<option name="isRedirectInput" value="false" />
|
||||
<option name="redirectInputPath" value="" />
|
||||
<method v="2">
|
||||
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<list>
|
||||
<item itemvalue="Cargo.Run" />
|
||||
<item itemvalue="Cargo.Check" />
|
||||
</list>
|
||||
</component>
|
||||
<component name="RustProjectSettings">
|
||||
<option name="toolchainHomeDirectory" value="//wsl$/Ubuntu-22.04/home/jonesd/.cargo/bin" />
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="81820af5-b0ad-4ac7-a939-e3db68fc7214" name="Changes" comment="" />
|
||||
<created>1684177338227</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1684177338227</updated>
|
||||
<workItem from="1684177339283" duration="296000" />
|
||||
<workItem from="1684180154545" duration="927000" />
|
||||
<workItem from="1684181684374" duration="176000" />
|
||||
<workItem from="1684345543022" duration="781000" />
|
||||
<workItem from="1687970763540" duration="4628000" />
|
||||
<workItem from="1689824866342" duration="40000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Commit to scraper_framework branch - changing framework from Soup to Scraper - removed ncurses library. Will use different library instead.">
|
||||
<created>1687972565061</created>
|
||||
<option name="number" value="00001" />
|
||||
<option name="presentableId" value="LOCAL-00001" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1687972565061</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00002" summary="Commit to scraper_framework branch - changing framework from Soup to Scraper - removed ncurses library. Will use different library instead.">
|
||||
<created>1687972590786</created>
|
||||
<option name="number" value="00002" />
|
||||
<option name="presentableId" value="LOCAL-00002" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1687972590786</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00003" summary="- Can now format HTML - No longer returns to main.rs. Main function in html_module.rs now reads to console locally.">
|
||||
<created>1687974796970</created>
|
||||
<option name="number" value="00003" />
|
||||
<option name="presentableId" value="LOCAL-00003" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1687974796970</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="4" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
<option name="TAB_STATES">
|
||||
<map>
|
||||
<entry key="MAIN">
|
||||
<value>
|
||||
<State>
|
||||
<option name="FILTERS">
|
||||
<map>
|
||||
<entry key="branch">
|
||||
<value>
|
||||
<list>
|
||||
<option value="scraper_framework" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</State>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="Commit to scraper_framework branch - changing framework from Soup to Scraper - removed ncurses library. Will use different library instead." />
|
||||
<MESSAGE value="- Can now format HTML - No longer returns to main.rs. Main function in html_module.rs now reads to console locally." />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="- Can now format HTML - No longer returns to main.rs. Main function in html_module.rs now reads to console locally." />
|
||||
</component>
|
||||
<component name="XSLT-Support.FileAssociations.UIState">
|
||||
<expand />
|
||||
<select />
|
||||
</component>
|
||||
}]]></component>
|
||||
<component name="RunManager" selected="Cargo.Check">
|
||||
<configuration name="Check" type="CargoCommandRunConfiguration" factoryName="Cargo Command" nameIsGenerated="true">
|
||||
<option name="command" value="check" />
|
||||
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||
<option name="emulateTerminal" value="false" />
|
||||
<option name="channel" value="DEFAULT" />
|
||||
<option name="requiredFeatures" value="true" />
|
||||
<option name="allFeatures" value="false" />
|
||||
<option name="withSudo" value="false" />
|
||||
<option name="buildTarget" value="REMOTE" />
|
||||
<option name="backtrace" value="SHORT" />
|
||||
<envs />
|
||||
<option name="isRedirectInput" value="false" />
|
||||
<option name="redirectInputPath" value="" />
|
||||
<method v="2">
|
||||
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="Run" type="CargoCommandRunConfiguration" factoryName="Cargo Command" nameIsGenerated="true">
|
||||
<option name="command" value="run pg2680.epub" />
|
||||
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||
<option name="emulateTerminal" value="false" />
|
||||
<option name="channel" value="DEFAULT" />
|
||||
<option name="requiredFeatures" value="true" />
|
||||
<option name="allFeatures" value="false" />
|
||||
<option name="withSudo" value="false" />
|
||||
<option name="buildTarget" value="REMOTE" />
|
||||
<option name="backtrace" value="SHORT" />
|
||||
<envs />
|
||||
<option name="isRedirectInput" value="false" />
|
||||
<option name="redirectInputPath" value="" />
|
||||
<method v="2">
|
||||
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<list>
|
||||
<item itemvalue="Cargo.Run" />
|
||||
<item itemvalue="Cargo.Check" />
|
||||
</list>
|
||||
</component>
|
||||
<component name="RustProjectSettings">
|
||||
<option name="toolchainHomeDirectory" value="//wsl$/Ubuntu-22.04/home/jonesd/.cargo/bin" />
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="81820af5-b0ad-4ac7-a939-e3db68fc7214" name="Changes" comment="" />
|
||||
<created>1684177338227</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1684177338227</updated>
|
||||
<workItem from="1684177339283" duration="296000" />
|
||||
<workItem from="1684180154545" duration="927000" />
|
||||
<workItem from="1684181684374" duration="176000" />
|
||||
<workItem from="1684345543022" duration="781000" />
|
||||
<workItem from="1687970763540" duration="4628000" />
|
||||
<workItem from="1689824866342" duration="40000" />
|
||||
<workItem from="1689861266305" duration="5017000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Commit to scraper_framework branch - changing framework from Soup to Scraper - removed ncurses library. Will use different library instead.">
|
||||
<created>1687972565061</created>
|
||||
<option name="number" value="00001" />
|
||||
<option name="presentableId" value="LOCAL-00001" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1687972565061</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00002" summary="Commit to scraper_framework branch - changing framework from Soup to Scraper - removed ncurses library. Will use different library instead.">
|
||||
<created>1687972590786</created>
|
||||
<option name="number" value="00002" />
|
||||
<option name="presentableId" value="LOCAL-00002" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1687972590786</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00003" summary="- Can now format HTML - No longer returns to main.rs. Main function in html_module.rs now reads to console locally.">
|
||||
<created>1687974796970</created>
|
||||
<option name="number" value="00003" />
|
||||
<option name="presentableId" value="LOCAL-00003" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1687974796970</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="4" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
<option name="TAB_STATES">
|
||||
<map>
|
||||
<entry key="MAIN">
|
||||
<value>
|
||||
<State>
|
||||
<option name="FILTERS">
|
||||
<map>
|
||||
<entry key="branch">
|
||||
<value>
|
||||
<list>
|
||||
<option value="scraper_framework" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</State>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="Commit to scraper_framework branch - changing framework from Soup to Scraper - removed ncurses library. Will use different library instead." />
|
||||
<MESSAGE value="- Can now format HTML - No longer returns to main.rs. Main function in html_module.rs now reads to console locally." />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="- Can now format HTML - No longer returns to main.rs. Main function in html_module.rs now reads to console locally." />
|
||||
</component>
|
||||
<component name="XSLT-Support.FileAssociations.UIState">
|
||||
<expand />
|
||||
<select />
|
||||
</component>
|
||||
</project>
|
@ -9,4 +9,5 @@ edition = "2021"
|
||||
epub = "2.0.0"
|
||||
ncurses = "5.101.0"
|
||||
scraper = "0.17.1"
|
||||
tuikit = "0.5.0"
|
||||
|
||||
|
16
README.md
16
README.md
@ -1,8 +1,8 @@
|
||||
# Bibliofile
|
||||
### A TUI-based ebook reader that hopefully doesn't suck!
|
||||
|
||||
A long long time ago, I was in college. I frequently bought the ebook versions of my textbooks, but to my dismay...most ebook readers sucked. The user interface was complicated, dark mode was unavailable for most readers until I neared graduation, dark mode usually looked terrible even if it was available, etc. I hope to change that. What better dark mode that running it on the TUI? What better way to make a simple UI than to design one myself that *I* like?
|
||||
|
||||
This is very much a personal project. Rust isn't exactly used for big companies besides Mozilla just yet, and progress is slow-going due to my personal and work commitments. Still, when it is done, I will attempt to release it on several popular repositories such as Flatpack so that others can use it.
|
||||
|
||||
Feel free to check up on progress on my blog, www.whoisthisjoker.com. I post there periodically to talk about what direction I want the project to go.
|
||||
# Bibliofile
|
||||
### A TUI-based ebook reader that hopefully doesn't suck!
|
||||
|
||||
A long long time ago, I was in college. I frequently bought the ebook versions of my textbooks, but to my dismay...most ebook readers sucked. The user interface was complicated, dark mode was unavailable for most readers until I neared graduation, dark mode usually looked terrible even if it was available, etc. I hope to change that. What better dark mode that running it on the TUI? What better way to make a simple UI than to design one myself that *I* like?
|
||||
|
||||
This is very much a personal project. Rust isn't exactly used for big companies besides Mozilla just yet, and progress is slow-going due to my personal and work commitments. Still, when it is done, I will attempt to release it on several popular repositories such as Flatpack so that others can use it.
|
||||
|
||||
Feel free to check up on progress on my blog, www.whoisthisjoker.com. I post there periodically to talk about what direction I want the project to go.
|
||||
|
@ -1,25 +1,36 @@
|
||||
/*
|
||||
Program: Bibliofile
|
||||
Purpose: This class is meant to process and return HTML formatted text as strings.
|
||||
Last edited: 6/28/23
|
||||
*/
|
||||
|
||||
use scraper::{Html, Selector};
|
||||
|
||||
pub fn main(content: String){
|
||||
|
||||
|
||||
let str_content = Html::parse_document(&content);
|
||||
|
||||
//Selector is HTML tag. Can be <br> or <p> or anything else. To parse entire page, set selector to <html>
|
||||
let selector = Selector::parse("html").unwrap();
|
||||
let unwrapped_page = str_content.select(&selector).next().unwrap();
|
||||
let page = unwrapped_page.text().collect::<Vec<_>>();
|
||||
|
||||
//every line in document is an entry into the vector. For loop iterates through every entry and displays it.
|
||||
for i in 0..page.len() {
|
||||
println!("{}", page[i]);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Program: Bibliofile
|
||||
Purpose: This class is meant to process and return HTML formatted text as strings.
|
||||
Last edited: 7/20/23
|
||||
*/
|
||||
|
||||
|
||||
use scraper::{Html, Selector};
|
||||
|
||||
pub fn main(content: String) -> String{
|
||||
|
||||
|
||||
let str_content = Html::parse_document(&content);
|
||||
|
||||
//Selector is HTML tag. Can be <br> or <p> or anything else. To parse entire page, set selector to <html>
|
||||
let selector = Selector::parse("html").unwrap();
|
||||
let unwrapped_page = str_content.select(&selector).next().unwrap();
|
||||
let page = unwrapped_page.text().collect::<Vec<_>>();
|
||||
let mut text = String::new();
|
||||
//every line in document is an entry into the vector. For loop iterates through every entry and displays it.
|
||||
for i in 0..page.len() {
|
||||
|
||||
if i < page.len() {
|
||||
text = text + page[i];
|
||||
|
||||
}
|
||||
|
||||
if i == page.len(){
|
||||
text = text + page[i];
|
||||
return text.to_string();
|
||||
}
|
||||
|
||||
}
|
||||
return text.to_string();
|
||||
|
||||
}
|
186
src/main.rs
186
src/main.rs
@ -1,93 +1,93 @@
|
||||
/*
|
||||
Program: Bibliofile
|
||||
Language: Rustc 1.70.0
|
||||
ide: CLion
|
||||
Operating system: Fedora 38/WSL
|
||||
Purpose: ncurses based ereader and library manager for Linux terminal environments.
|
||||
Last edited: 6/28/23
|
||||
*/
|
||||
//this is a test change to see if gitea is accepting pushes.
|
||||
|
||||
mod html_module;
|
||||
|
||||
|
||||
use epub::doc::EpubDoc; //library for navigating epubs
|
||||
use std::env;
|
||||
use std::process::exit;
|
||||
|
||||
|
||||
//initial function. Reads the ebook passed by argument.
|
||||
//TODO: add visual library to pull up ebooks.
|
||||
fn main() {
|
||||
if env::args().len() == 1 {
|
||||
println!("you need to enter a book. Closing program.");
|
||||
}
|
||||
else {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let filename = &args[1];
|
||||
|
||||
epub_func(filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//parses epub files
|
||||
fn epub_func(epub_file: &str){
|
||||
|
||||
let doc = EpubDoc::new(&epub_file);
|
||||
assert!(doc.is_ok());
|
||||
let mut doc = doc.unwrap();
|
||||
|
||||
let mut page_num = 1;
|
||||
let is_reading = true;
|
||||
while is_reading == true {
|
||||
let mut next_or_last = String::new();
|
||||
doc.set_current_page(page_num);
|
||||
|
||||
let content = doc.get_current_str();
|
||||
let str_content = content.unwrap();
|
||||
html_module::main(str_content.0);
|
||||
|
||||
|
||||
let input_size = std::io::stdin().read_line(&mut next_or_last);
|
||||
let input_size_len = input_size.unwrap() - 1;
|
||||
if input_size_len == 1{
|
||||
|
||||
/*
|
||||
Was not sure how to compare string to input from .read_line
|
||||
Instead, I felt that it would be easier to convert it to bytes and
|
||||
compare the ASCII values.
|
||||
*/
|
||||
let compare = next_or_last.as_bytes();
|
||||
|
||||
//If user presses n(for next) goes forward one page.
|
||||
if compare[0] == 110 {
|
||||
page_num = page_num + 1;
|
||||
}
|
||||
//if user presses b, goes back one page.
|
||||
else if compare[0] == 98 {
|
||||
//if page number equals one then you are at the beginning of the book.
|
||||
if page_num == 1 {
|
||||
println!("at beginning of book.");
|
||||
}
|
||||
else {
|
||||
page_num = page_num - 1;
|
||||
}
|
||||
}
|
||||
//If user presses q(for quit), exits with status code of 0.
|
||||
else if compare[0] == 113 {
|
||||
println!("quitting...");
|
||||
exit(0);
|
||||
}
|
||||
else {
|
||||
println!("did not understand command.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
println!("Do not understand input. Try again.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Program: Bibliofile
|
||||
Language: Rustc 1.70.0
|
||||
ide: CLion
|
||||
Operating system: Fedora 38/WSL
|
||||
Purpose: TUI-based ereader and library manager for Linux terminal environments.
|
||||
Last edited: 7/20/23
|
||||
*/
|
||||
//this is a test change to see if gitea is accepting pushes.
|
||||
|
||||
mod html_module;
|
||||
|
||||
|
||||
use epub::doc::EpubDoc; //library for navigating epubs
|
||||
use std::env;
|
||||
use std::process::exit;
|
||||
|
||||
|
||||
//initial function. Reads the ebook passed by argument.
|
||||
//TODO: add visual library to pull up ebooks.
|
||||
fn main() {
|
||||
if env::args().len() == 1 {
|
||||
println!("you need to enter a book. Closing program.");
|
||||
}
|
||||
else {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let filename = &args[1];
|
||||
|
||||
epub_func(filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//parses epub files
|
||||
fn epub_func(epub_file: &str){
|
||||
|
||||
let doc = EpubDoc::new(&epub_file);
|
||||
assert!(doc.is_ok());
|
||||
let mut doc = doc.unwrap();
|
||||
|
||||
let mut page_num = 1;
|
||||
let is_reading = true;
|
||||
while is_reading == true {
|
||||
let mut next_or_last = String::new();
|
||||
doc.set_current_page(page_num);
|
||||
|
||||
let content = doc.get_current_str();
|
||||
let str_content = content.unwrap();
|
||||
let text = html_module::main(str_content.0);
|
||||
println!("{}", text);
|
||||
|
||||
let input_size = std::io::stdin().read_line(&mut next_or_last);
|
||||
let input_size_len = input_size.unwrap() - 1;
|
||||
if input_size_len == 1{
|
||||
|
||||
/*
|
||||
Was not sure how to compare string to input from .read_line
|
||||
Instead, I felt that it would be easier to convert it to bytes and
|
||||
compare the ASCII values.
|
||||
*/
|
||||
let compare = next_or_last.as_bytes();
|
||||
|
||||
//If user presses n(for next) goes forward one page.
|
||||
if compare[0] == 110 {
|
||||
page_num = page_num + 1;
|
||||
}
|
||||
//if user presses b, goes back one page.
|
||||
else if compare[0] == 98 {
|
||||
//if page number equals one then you are at the beginning of the book.
|
||||
if page_num == 1 {
|
||||
println!("at beginning of book.");
|
||||
}
|
||||
else {
|
||||
page_num = page_num - 1;
|
||||
}
|
||||
}
|
||||
//If user presses q(for quit), exits with status code of 0.
|
||||
else if compare[0] == 113 {
|
||||
println!("quitting...");
|
||||
exit(0);
|
||||
}
|
||||
else {
|
||||
println!("did not understand command.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
println!("Do not understand input. Try again.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user