update ggemtext api to v0.3.0

This commit is contained in:
yggverse 2024-12-02 16:12:30 +02:00
parent 2a59bebea9
commit cdf6e78408
4 changed files with 58 additions and 32 deletions

View File

@ -21,7 +21,7 @@ version = "0.11.0"
[dependencies.gemtext] [dependencies.gemtext]
package = "ggemtext" package = "ggemtext"
version = "0.2.1" version = "0.3.0"
[dependencies.gtk] [dependencies.gtk]
package = "gtk4" package = "gtk4"
@ -35,6 +35,7 @@ version = "0.32.1"
[dependencies.openssl] [dependencies.openssl]
version = "0.10.68" version = "0.10.68"
# development
[patch.crates-io] [patch.crates-io]
#ggemini = { path = "ggemini" } #ggemini = { path = "ggemini" }
#ggemtext = { path = "ggemtext" } ggemtext = { git = "https://github.com/YGGverse/ggemtext.git" }

View File

@ -17,7 +17,7 @@ impl Gemini {
// Construct // Construct
pub fn new(gemtext: &str, base: &Uri, actions: (Rc<WindowAction>, Rc<TabAction>)) -> Self { pub fn new(gemtext: &str, base: &Uri, actions: (Rc<WindowAction>, Rc<TabAction>)) -> Self {
// Init components // Init components
let reader = Rc::new(Reader::new(gemtext, base, actions)); let reader = Rc::new(Reader::new(gemtext, base, actions).unwrap()); // @TODO handle errors
let widget = Rc::new(Widget::new(&reader.widget.text_view)); let widget = Rc::new(Widget::new(&reader.widget.text_view));
// Result // Result

View File

@ -1,6 +1,8 @@
pub mod error;
mod tag; mod tag;
mod widget; mod widget;
pub use error::Error;
use tag::Tag; use tag::Tag;
use widget::Widget; use widget::Widget;
@ -32,7 +34,11 @@ pub struct Reader {
impl Reader { impl Reader {
// Construct // Construct
pub fn new(gemtext: &str, base: &Uri, actions: (Rc<WindowAction>, Rc<TabAction>)) -> Self { pub fn new(
gemtext: &str,
base: &Uri,
actions: (Rc<WindowAction>, Rc<TabAction>),
) -> Result<Self, Error> {
// Init default values // Init default values
let mut title = None; let mut title = None;
@ -77,8 +83,8 @@ impl Reader {
} }
} }
Some(ref mut this) => { Some(ref mut this) => {
Code::multiline_continue_from(this, line); match Code::multiline_continue_from(this, line) {
Ok(()) => {
// Close tag found: // Close tag found:
if this.completed { if this.completed {
// Is alt provided // Is alt provided
@ -108,6 +114,9 @@ impl Reader {
// Skip other actions for this line // Skip other actions for this line
continue; continue;
} }
Err(e) => return Err(Error::Gemtext(e.to_string())),
}
}
}; };
// Is header // Is header
@ -351,6 +360,6 @@ impl Reader {
}); // @TODO may be expensive for CPU, add timeout? }); // @TODO may be expensive for CPU, add timeout?
// Result // Result
Self { title, widget } Ok(Self { title, widget })
} }
} }

View File

@ -0,0 +1,16 @@
use std::fmt::{Display, Formatter, Result};
#[derive(Debug)]
pub enum Error {
Gemtext(String),
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> Result {
match self {
Self::Gemtext(e) => {
write!(f, "Gemtext error: {e}")
}
}
}
}