This commit is contained in:
Andrew Pamment 2025-09-06 23:34:25 +00:00
parent 0e9aac214c
commit 4e9ab9d760

View File

@ -1,11 +1,11 @@
use doorlib::{self as door, esc, Conn}; use doorlib::{self as door, Conn, esc};
use std::error::Error;
use rss::Channel;
use std::fmt::Write;
use textwrap::wrap;
use iconv_native::convert; use iconv_native::convert;
use rss::Channel;
use std::error::Error;
use std::fmt::Write;
use std::fs::File; use std::fs::File;
use std::io::BufReader; use std::io::BufReader;
use textwrap::wrap;
fn report(mut err: &(dyn std::error::Error + 'static)) -> String { fn report(mut err: &(dyn std::error::Error + 'static)) -> String {
let mut s = format!("{}", err); let mut s = format!("{}", err);
while let Some(src) = err.source() { while let Some(src) = err.source() {
@ -15,20 +15,17 @@ fn report(mut err: &(dyn std::error::Error + 'static)) -> String {
s s
} }
fn xbit_news_feed() -> Result<Channel, Box<dyn Error>> { fn xbit_news_feed() -> Result<Channel, Box<dyn Error>> {
let resp = reqwest::blocking::get("https://x-bit.org/rss/rss.xml"); let resp = reqwest::blocking::get("https://x-bit.org/rss/rss.xml");
match resp { match resp {
Ok(resp) => { Ok(resp) => {
if resp.status().is_success() { if resp.status().is_success() {
let content = resp.bytes()?; let content = resp.bytes()?;
let channel = Channel::read_from(&content[..])?; let channel = Channel::read_from(&content[..])?;
return Ok(channel); return Ok(channel);
} }
}, }
Err(e) => { Err(e) => {
report(e.source().expect("REASON")); report(e.source().expect("REASON"));
} }
@ -44,8 +41,28 @@ fn door_main(mut u: door::User) -> Result<(), Box<dyn Error>> {
let mut index = 0; let mut index = 0;
let mut start = 0; let mut start = 0;
u.write_str(format!("{}{}{} {}{}{}", esc!("[2J"), esc!("[1;1H"), esc!("[0;30;46m"), channel.title(), esc!("[K"), esc!("[0m")).as_str())?; u.write_str(
u.write_str(format!("{}{} Press Q to quit, Up and Down to Scroll {}{}", esc!("[24;1H"), esc!("[0;30;46m"), esc!("[K"), esc!("[0m")).as_str())?; format!(
"{}{}{} {}{}{}",
esc!("[2J"),
esc!("[1;1H"),
esc!("[0;30;46m"),
channel.title(),
esc!("[K"),
esc!("[0m")
)
.as_str(),
)?;
u.write_str(
format!(
"{}{} Press Q to quit, Up and Down to Scroll {}{}",
esc!("[24;1H"),
esc!("[0;30;46m"),
esc!("[K"),
esc!("[0m")
)
.as_str(),
)?;
loop { loop {
for i in start..start + 22 { for i in start..start + 22 {
@ -53,9 +70,45 @@ fn door_main(mut u: door::User) -> Result<(), Box<dyn Error>> {
if i < channel.items().len() { if i < channel.items().len() {
if i == index { if i == index {
u.write_ln(format!("{}{}{:62.62} {:16.16}{}{}", p, esc!("[1;37;45m"), String::from_utf8(convert(channel.items[i].title().unwrap_or("No Title"), "UTF-8", "ASCII//TRANSLIT").unwrap_or(channel.items[i].title().unwrap_or("No Title").into()))?, channel.items[i].pub_date().unwrap_or("??/??/????"), esc!("[K"), esc!("[0m")).as_str())?; u.write_ln(
format!(
"{}{}{:62.62} {:16.16}{}{}",
p,
esc!("[1;37;45m"),
String::from_utf8(
convert(
channel.items[i].title().unwrap_or("No Title"),
"UTF-8",
"ASCII//TRANSLIT"
)
.unwrap_or(channel.items[i].title().unwrap_or("No Title").into())
)?,
channel.items[i].pub_date().unwrap_or("??/??/????"),
esc!("[K"),
esc!("[0m")
)
.as_str(),
)?;
} else { } else {
u.write_ln(format!("{}{}{:62.62} {:16.16}{}{}", p, esc!("[1;37m"), String::from_utf8(convert(channel.items[i].title().unwrap_or("No Title"), "UTF-8", "ASCII//TRANSLIT").unwrap_or(channel.items[i].title().unwrap_or("No Title").into()))?, channel.items[i].pub_date().unwrap_or("??/??/????"), esc!("[K"), esc!("[0m")).as_str())?; u.write_ln(
format!(
"{}{}{:62.62} {:16.16}{}{}",
p,
esc!("[1;37m"),
String::from_utf8(
convert(
channel.items[i].title().unwrap_or("No Title"),
"UTF-8",
"ASCII//TRANSLIT"
)
.unwrap_or(channel.items[i].title().unwrap_or("No Title").into())
)?,
channel.items[i].pub_date().unwrap_or("??/??/????"),
esc!("[K"),
esc!("[0m")
)
.as_str(),
)?;
} }
} else { } else {
u.write_ln(format!("{}{}", p, esc!("[K")).as_str())?; u.write_ln(format!("{}{}", p, esc!("[K")).as_str())?;
@ -85,15 +138,57 @@ fn door_main(mut u: door::User) -> Result<(), Box<dyn Error>> {
} else if ch == b'q' || ch == b'Q' { } else if ch == b'q' || ch == b'Q' {
break; break;
} else if ch == b'\n' || ch == b'\r' { } else if ch == b'\n' || ch == b'\r' {
let desc = String::from_utf8(convert(channel.items[index].description().unwrap_or("No Content"), "UTF-8", "ASCII//TRANSLIT").unwrap_or(channel.items[index].description().unwrap_or("No Content").into()))?; let desc = String::from_utf8(
convert(
channel.items[index].description().unwrap_or("No Content"),
"UTF-8",
"ASCII//TRANSLIT",
)
.unwrap_or(
channel.items[index]
.description()
.unwrap_or("No Content")
.into(),
),
)?;
let content = wrap(&desc, 79); let content = wrap(&desc, 79);
let mut cstart = 0; let mut cstart = 0;
let mut cindex = 0; let mut cindex = 0;
loop { loop {
u.write_ln(format!("{}{}{}{}{}{}", esc!("[2J"), esc!("[1;1H"), esc!("[0;30;46m"), channel.items[index].title().unwrap_or("No Title"), esc!("[K"), esc!("[0m")).as_str())?; u.write_ln(
u.write_ln(format!("{}{}{}{}{}", esc!("[2;1H"), esc!("[0;30;46m"), channel.items[index].link().unwrap_or("No Link"), esc!("[K"), esc!("[0m")).as_str())?; format!(
u.write_str(format!("{}{} Press ENTER to Return to menu, Up and Down to Scroll {}{}", esc!("[24;1H"), esc!("[0;30;46m"), esc!("[K"), esc!("[0m")).as_str())?; "{}{}{}{}{}{}",
esc!("[2J"),
esc!("[1;1H"),
esc!("[0;30;46m"),
channel.items[index].title().unwrap_or("No Title"),
esc!("[K"),
esc!("[0m")
)
.as_str(),
)?;
u.write_ln(
format!(
"{}{}{}{}{}",
esc!("[2;1H"),
esc!("[0;30;46m"),
channel.items[index].link().unwrap_or("No Link"),
esc!("[K"),
esc!("[0m")
)
.as_str(),
)?;
u.write_str(
format!(
"{}{} Press ENTER to Return to menu, Up and Down to Scroll {}{}",
esc!("[24;1H"),
esc!("[0;30;46m"),
esc!("[K"),
esc!("[0m")
)
.as_str(),
)?;
for i in cstart..cstart + 20 { for i in cstart..cstart + 20 {
let p = format!("\x1b[{};1H", (i - cstart) + 3); let p = format!("\x1b[{};1H", (i - cstart) + 3);
if i < content.len() { if i < content.len() {
@ -129,10 +224,31 @@ fn door_main(mut u: door::User) -> Result<(), Box<dyn Error>> {
} }
} }
u.write_str(
u.write_str(format!("{}{}{} {}{}{}", esc!("[2J"), esc!("[1;1H"), esc!("[0;30;46m"), String::from_utf8(convert(channel.title(), "UTF-8", "ASCII//TRANSLIT").unwrap_or(channel.title().into()))?, esc!("[K"), esc!("[0m")).as_str())?; format!(
u.write_str(format!("{}{} Press Q to quit, Up and Down to Scroll {}{}", esc!("[24;1H"), esc!("[0;30;46m"), esc!("[K"), esc!("[0m")).as_str())?; "{}{}{} {}{}{}",
esc!("[2J"),
esc!("[1;1H"),
esc!("[0;30;46m"),
String::from_utf8(
convert(channel.title(), "UTF-8", "ASCII//TRANSLIT")
.unwrap_or(channel.title().into())
)?,
esc!("[K"),
esc!("[0m")
)
.as_str(),
)?;
u.write_str(
format!(
"{}{} Press Q to quit, Up and Down to Scroll {}{}",
esc!("[24;1H"),
esc!("[0;30;46m"),
esc!("[K"),
esc!("[0m")
)
.as_str(),
)?;
} }
} }
Ok(()) Ok(())