Merge pull request #19 from newbee1905/main

Add option to use glow to read light novel
This commit is contained in:
mrfluffy
2023-02-02 07:26:50 -08:00
committed by GitHub
3 changed files with 107 additions and 47 deletions

View File

@@ -1,4 +1,4 @@
use crate::ln::open_text::*; use crate::ln::open_text::{open_bat, open_glow};
use crate::ln::scraper::*; use crate::ln::scraper::*;
use crate::ln::tracker::*; use crate::ln::tracker::*;
use crossterm::{ use crossterm::{
@@ -113,7 +113,7 @@ impl<'a> App {
} }
} }
pub fn ln_ui(chapter: u32) -> Result<(), Box<dyn Error>> { pub fn ln_ui(chapter: u32, reader: String) -> Result<(), Box<dyn Error>> {
// setup terminal // setup terminal
let _ = get_ln_json(); let _ = get_ln_json();
enable_raw_mode()?; enable_raw_mode()?;
@@ -130,7 +130,7 @@ pub fn ln_ui(chapter: u32) -> Result<(), Box<dyn Error>> {
app.current_page_number = (chapter / 48.0).ceil() as u32; app.current_page_number = (chapter / 48.0).ceil() as u32;
} }
let res = run_app(&mut terminal, app); let res = run_app(&mut terminal, app, &*reader);
// restore terminal // restore terminal
disable_raw_mode()?; disable_raw_mode()?;
@@ -148,7 +148,7 @@ pub fn ln_ui(chapter: u32) -> Result<(), Box<dyn Error>> {
Ok(()) Ok(())
} }
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> { fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App, reader: &str) -> io::Result<()> {
let mut chapter_select = false; let mut chapter_select = false;
loop { loop {
@@ -244,7 +244,11 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
file.sync_all().expect("Unable to sync file"); file.sync_all().expect("Unable to sync file");
}; };
terminal.clear()?; terminal.clear()?;
let _ = open_bat(); let _ = match reader {
"bat" => open_bat(),
"glow" => open_glow(),
&_ => todo!(),
};
write_ln_progress( write_ln_progress(
&app.title, &app.title,
&app.current_page_number, &app.current_page_number,

View File

@@ -3,16 +3,15 @@ use std::process::{Command, ExitStatus, Stdio};
#[allow(unused_assignments)] #[allow(unused_assignments)]
pub fn open_bat() -> Result<ExitStatus> { pub fn open_bat() -> Result<ExitStatus> {
let termsize::Size {rows: _, cols} = termsize::get().unwrap(); let termsize::Size { rows: _, cols } = termsize::get().unwrap();
let mut path = String::new(); let mut path = String::new();
if cfg!(target_os = "windows"){ if cfg!(target_os = "windows") {
use dirs::home_dir; use dirs::home_dir;
let mut home = format!("{:?}",home_dir()).replace("\\\\","/"); let mut home = format!("{:?}", home_dir()).replace("\\\\", "/");
home.drain(0..6); home.drain(0..6);
home.drain(home.len()-2..home.len()); home.drain(home.len() - 2..home.len());
path = format!("{}/AppData/Roaming/log_e",home).to_string(); path = format!("{}/AppData/Roaming/log_e", home).to_string();
} } else {
else{
path = "/tmp/log_e".to_string(); path = "/tmp/log_e".to_string();
} }
@@ -37,3 +36,36 @@ pub fn open_bat() -> Result<ExitStatus> {
.spawn()? .spawn()?
.wait() .wait()
} }
#[allow(unused_assignments)]
pub fn open_glow() -> Result<ExitStatus> {
let termsize::Size { rows: _, cols } = termsize::get().unwrap();
let mut path = String::new();
if cfg!(target_os = "windows") {
use dirs::home_dir;
let mut home = format!("{:?}", home_dir()).replace("\\\\", "/");
home.drain(0..6);
home.drain(home.len() - 2..home.len());
path = format!("{}/AppData/Roaming/log_e", home).to_string();
} else {
path = "/tmp/log_e".to_string();
}
let soft_wrap = match Command::new("fold")
.arg("-s")
.arg("-w")
.arg((cols - 9).to_string())
.arg(path)
.stdout(Stdio::piped())
.spawn()
{
Err(why) => panic!("couldn't spawn wc: {}", why),
Ok(soft_wrap) => soft_wrap,
};
Command::new("glow")
.arg("-p")
.stdin(soft_wrap.stdout.unwrap())
.spawn()?
.wait()
}

View File

@@ -18,47 +18,56 @@ fn main() {
//let search = option string //let search = option string
let mut count = 0; let mut count = 0;
let mut provider: String = "gogo".to_string(); let mut provider: String = "gogo".to_string();
let mut reader: String = "bat".to_string();
let mut cast = (false, "0".to_string()); let mut cast = (false, "0".to_string());
for arg in std::env::args() { for arg in std::env::args() {
if arg == "--help" || arg == "-h" { match &*arg {
help = true; "--help" | "-h" => help = true,
} "--anime" | "-a" => anime = true,
if arg == "--anime" || arg == "-a" { "--provider" | "-r" => {
anime = true; if let Some(arg) = std::env::args().nth(count + 1) {
} //get the next argument and see if it is = to gogo of vrv
if arg == "--provider" || arg == "-r" { match arg.as_str() {
if let Some(arg) = std::env::args().nth(count + 1) { "vrv" | "gogo" => {
//get the next argument and see if it is = to gogo of vrv provider = arg;
if arg == "vrv" { count += 1;
provider = "vrv".to_string(); }
count += 1; &_ => provider = "gogo".to_string(),
} else if arg == "gogo" { }
provider = "gogo".to_string();
count += 1;
} else { } else {
provider = "gogo".to_string(); provider = "vrv".to_string();
} }
} else {
provider = "vrv".to_string();
} }
} "--reader" | "-R" => {
if arg == "--cast" || arg == "-C" { if let Some(arg) = std::env::args().nth(count + 1) {
if let Some(arg) = std::env::args().nth(count + 1) { //get the next argument and see if it is = to gogo of vrv
cast = (true, String::from(arg)) match arg.as_str() {
} else { "bat" | "glow" => {
println!("{}", "please provide a ip address".red()) reader = arg;
count += 1;
}
&_ => reader = "bat".to_string(),
}
} else {
provider = "glow".to_string();
}
} }
} "--cast" | "-C" => {
if let Some(arg) = std::env::args().nth(count + 1) {
if arg == "--ln" || arg == "-l" { cast = (true, String::from(arg))
ln = true; } else {
} println!("{}", "please provide a ip address".red())
if arg == "--chapter" || arg == "-c" { }
if let Some(arg) = std::env::args().nth(count + 1) {
chapter = arg.parse::<u32>().unwrap();
} else {
chapter = 0;
} }
"--ln" | "-l" => ln = true,
"--chapter" | "-c" => {
if let Some(arg) = std::env::args().nth(count + 1) {
chapter = arg.parse::<u32>().unwrap();
} else {
chapter = 0;
}
}
&_ => {}
} }
count += 1; count += 1;
@@ -84,7 +93,7 @@ fn main() {
} }
if ln == true { if ln == true {
//ln_read(&search, chapter); //ln_read(&search, chapter);
_ = ln_ui(chapter); _ = ln_ui(chapter, reader);
} else if anime == true { } else if anime == true {
//anime_stream(search, episode, resume); //anime_stream(search, episode, resume);
@@ -130,6 +139,21 @@ fn print_help() {
); );
println!("the providers are {} or {}", "gogo".green(), "vrv".green()); println!("the providers are {} or {}", "gogo".green(), "vrv".green());
println!(""); println!("");
println!("reader:\t\t{}", format_args!("{}", "-R --reader".red()));
println!(
"{}",
"after this^^^ argument you can enter a reader".green()
);
println!(
"if no reader is entered it will default to {}",
"bat".green()
);
println!(
"if the -R argument is not used it will default to {}",
"bat".green()
);
println!("the readers are {} or {}", "bat".green(), "glow".green());
println!("");
println!("help:\t\t{}", format_args!("{}", "-h --help".red())); println!("help:\t\t{}", format_args!("{}", "-h --help".red()));
//kill the program //kill the program
std::process::exit(0); std::process::exit(0);