did some formatting

This commit is contained in:
Zastian Pretorius
2022-07-26 13:14:38 +01:00
parent 585159455e
commit dcc57d22a9
3 changed files with 40 additions and 36 deletions

View File

@@ -1,14 +1,13 @@
use crate::{string_input,int_input};
use crate::{anime_names,anime_ep_range,anime_link};
use crate::open_video;
use crate::main;
use crate::open_video;
use crate::{anime_ep_range, anime_link, anime_names};
use crate::{int_input, string_input};
use colored::Colorize;
//use crate
pub fn anime_stream(search: String, episode: u32) {
let query = if search != "" {
search
}
else{
} else {
string_input("Search anime: ")
};
@@ -45,16 +44,14 @@ pub fn anime_stream(search: String, episode: u32) {
let link = anime_link(title, 1);
open_video(link);
main();
}
else {
} else {
let mut ep_num: usize = usize::MAX;
if episode > ep_range.into() {
println!("Invalid episode number");
main();
}
else if episode != 0{
} else if episode != 0 {
ep_num = episode as usize;
}else{
} else {
println!("select episode 1-{}: ", ep_range);
while ep_num == usize::max_value() || ep_num > ep_range as usize {
ep_num = int_input("Enter episode number: ");
@@ -63,13 +60,13 @@ pub fn anime_stream(search: String, episode: u32) {
}
}
}
loop{
loop {
let link = anime_link(title, ep_num as u64);
open_video(link);
println!("{}","n: next episode".green());
println!("{}","p: previous episode".yellow());
println!("{}","s: search another anime".green());
println!("{}","q: quit".red());
println!("{}", "n: next episode".green());
println!("{}", "p: previous episode".yellow());
println!("{}", "s: search another anime".green());
println!("{}", "q: quit".red());
let input = string_input("Enter command: ");
if input == "n" {
if ep_num == ep_range as usize {
@@ -88,8 +85,7 @@ pub fn anime_stream(search: String, episode: u32) {
anime_stream("".to_string(), 0);
} else if input == "q" {
std::process::exit(0);
}
else{
} else {
println!("Invalid command");
}
}

View File

@@ -1,29 +1,30 @@
use crate::{chapter_selector, get_full_text, open_bat, search_ln};
use std::fs::File;
use std::io::Write;
use crate::{search_ln,chapter_selector,get_full_text,open_bat};
pub fn ln_read(search: &str, chapter: u32){
pub fn ln_read(search: &str, chapter: u32) {
//convert search in to Option<&str>
let ln_url = search_ln(&search);
let chapter = chapter as f64;
let mut selected_page = 1;
if chapter != 0.0{
selected_page = (chapter/48.0).ceil() as u32;
if chapter != 0.0 {
selected_page = (chapter / 48.0).ceil() as u32;
}
loop {
//make empty tuple called chapter_url with (String, u32, u32)
let chapter_url = chapter_selector(&ln_url, selected_page);
selected_page = chapter_url.1;
let full_text = get_full_text(&chapter_url.0);
if cfg!(target_os = "windows"){
if cfg!(target_os = "windows") {
use dirs::home_dir;
let mut home = format!("{:?}",home_dir()).replace("\\\\","/");
let mut home = format!("{:?}", home_dir()).replace("\\\\", "/");
home.drain(0..6);
home.drain(home.len()-2..home.len());
let mut file = File::create(format!("{}/AppData/Roaming/log_e",home)).expect("Unable to create file");
home.drain(home.len() - 2..home.len());
let mut file = File::create(format!("{}/AppData/Roaming/log_e", home))
.expect("Unable to create file");
file.write_all(full_text.as_bytes())
.expect("Unable to write to file");
file.sync_all().expect("Unable to sync file");
}else{
} else {
let mut file = File::create("/tmp/log_e").expect("Unable to create file");
file.write_all(full_text.as_bytes())
.expect("Unable to write to file");

View File

@@ -21,16 +21,24 @@ pub fn chapter_selector(ln_url: &str, mut selected_page: u32) -> (String, u32) {
let mut count = 0;
ln_chapters.into_iter().for_each(|chaprer| {
if count % 2 == 0 {
println!("({})\t{}", count.to_string().blue(), format_args!("{}", chaprer.blue()));
println!(
"({})\t{}",
count.to_string().blue(),
format_args!("{}", chaprer.blue())
);
} else {
println!("({})\t{}", count.to_string().yellow(), format_args!("{}", chaprer.yellow()));
println!(
"({})\t{}",
count.to_string().yellow(),
format_args!("{}", chaprer.yellow())
);
}
count += 1;
});
println!("{}\t{}","n:".green(), "Go to next page".green());
println!("{}\t{}","b:".yellow(), "Go to previous page".yellow());
println!("{}\t{}","s:".green(), "Search another title".green());
println!("{}\t{}","q:".red(), "quit".red());
println!("{}\t{}", "n:".green(), "Go to next page".green());
println!("{}\t{}", "b:".yellow(), "Go to previous page".yellow());
println!("{}\t{}", "s:".green(), "Search another title".green());
println!("{}\t{}", "q:".red(), "quit".red());
let chapter_number = string_input("Which chapter do you want to read? ");
if chapter_number == "n" && selected_page < ln_last_page.parse::<u32>().unwrap() {
selected_page += 1;
@@ -43,8 +51,7 @@ pub fn chapter_selector(ln_url: &str, mut selected_page: u32) -> (String, u32) {
std::process::exit(0);
} else if chapter_number == "s" {
main();
}
else {
} else {
let chapter_number = chapter_number.trim().to_string();
let mut _chapter_number_int = 0;
if chapter_number.parse::<u32>().is_ok() {