fn show_gemini(&mut self, base_url: &Url, content: &str) {
        trace!("show_gemini()");
        let textwrap = SETTINGS.read().unwrap().get_str("textwrap").unwrap();
        let textwrap_int = textwrap.parse::<usize>().unwrap();
        let mut viewport_width = self.get_gemini_viewport_width() - 10;
        viewport_width = std::cmp::min(textwrap_int, viewport_width);
        let mut app = self.app.write().unwrap();
        app.call_on_name("main", |v: &mut ui::layout::Layout| {
            v.set_view("gemini_content");
        });
        info!("Viewport-width = {}", viewport_width);
        app.call_on_name("gemini_content", |v: &mut SelectView<GeminiLine>| {
            v.clear();
            let lines = content.lines();
            for l in lines {
                let line = l.to_string();
                if let Ok(gemini_line) = GeminiLine::parse(line.clone(), &base_url) {
                    match gemini_line.line_type {
                        LineType::Text => {
                            let label = gemini_line.clone().label();
                            if label.len() > viewport_width {
                                let iter = wrap_iter(&label, viewport_width);
                                for str in iter {
                                    let mut formatted = StyledString::new();
                                    let label = format!("       {}", str);
                                    formatted.append(label);
                                    v.add_item(formatted, gemini_line.clone());
                                }
                            } else {
                                v.add_item(format!("       {}", label), gemini_line.clone());
                            }
                        }
                        LineType::UnorderedList => {
                            let label = gemini_line.clone().label();
                            if label.len() > viewport_width {
                                let iter = wrap_iter(&label, viewport_width);
                                let mut first = true;
                                for str in iter {
                                    let mut formatted = StyledString::new();
                                    let label = if first {
                                        format!("       {}", str)
                                    } else {
                                        format!("         {}", str)
                                    };
                                    first = false;
                                    formatted.append(label);
                                    v.add_item(formatted, gemini_line.clone());
                                }
                            } else {
                                v.add_item(format!("       {}", label), gemini_line.clone());
                            }
                        }
                        LineType::Link => {
                            let label = gemini_line.clone().label();
                            v.add_item(label, gemini_line.clone());
                        }
                        LineType::PreformattedToggle => {
                            // Skip for now
                        }
                        _ => {
                            let label = gemini_line.clone().label();
                            v.add_item(label, gemini_line.clone());
                        }
                    }
                }
            }
            v.set_on_submit(|app, entry| {
                app.with_user_data(|userdata: &mut UserData| {
                    if entry.line_type == LineType::Link {
                        let url = entry.url.as_ref().unwrap();
                        info!("Trying to open {}", url.as_str());
                        userdata
                            .ui_tx
                            .write()
                            .unwrap()
                            .send(UiMessage::OpenUrlFromString(
                                String::from(url.as_str()),
                                true,
                                0,
                            ))
                            .unwrap();
                    }
                });
            });
        });
    }
/// Renders a gemini site in a cursive::TextView
Renders a gemini site in a cursive::TextView
Renders a gemini site in a cursive :: TextView
fn show_gemini(&mut self, base_url: &Url, content: &str) {
        trace!("show_gemini()");
        let textwrap = SETTINGS.read().unwrap().get_str("textwrap").unwrap();
        let textwrap_int = textwrap.parse::<usize>().unwrap();
        let mut viewport_width = self.get_gemini_viewport_width() - 10;
        viewport_width = std::cmp::min(textwrap_int, viewport_width);
        let mut app = self.app.write().unwrap();
        app.call_on_name("main", |v: &mut ui::layout::Layout| {
            v.set_view("gemini_content");
        });
        info!("Viewport-width = {}", viewport_width);
        app.call_on_name("gemini_content", |v: &mut SelectView<GeminiLine>| {
            v.clear();
            let lines = content.lines();
            for l in lines {
                let line = l.to_string();
                if let Ok(gemini_line) = GeminiLine::parse(line.clone(), &base_url) {
                    match gemini_line.line_type {
                        LineType::Text => {
                            let label = gemini_line.clone().label();
                            if label.len() > viewport_width {
                                let iter = wrap_iter(&label, viewport_width);
                                for str in iter {
                                    let mut formatted = StyledString::new();
                                    let label = format!("       {}", str);
                                    formatted.append(label);
                                    v.add_item(formatted, gemini_line.clone());
                                }
                            } else {
                                v.add_item(format!("       {}", label), gemini_line.clone());
                            }
                        }
                        LineType::UnorderedList => {
                            let label = gemini_line.clone().label();
                            if label.len() > viewport_width {
                                let iter = wrap_iter(&label, viewport_width);
                                let mut first = true;
                                for str in iter {
                                    let mut formatted = StyledString::new();
                                    let label = if first {
                                        format!("       {}", str)
                                    } else {
                                        format!("         {}", str)
                                    };
                                    first = false;
                                    formatted.append(label);
                                    v.add_item(formatted, gemini_line.clone());
                                }
                            } else {
                                v.add_item(format!("       {}", label), gemini_line.clone());
                            }
                        }
                        LineType::Link => {
                            let label = gemini_line.clone().label();
                            v.add_item(label, gemini_line.clone());
                        }
                        LineType::PreformattedToggle => {
                            // Skip for now
                        }
                        _ => {
                            let label = gemini_line.clone().label();
                            v.add_item(label, gemini_line.clone());
                        }
                    }
                }
            }
            v.set_on_submit(|app, entry| {
                app.with_user_data(|userdata: &mut UserData| {
                    if entry.line_type == LineType::Link {
                        let url = entry.url.as_ref().unwrap();
                        info!("Trying to open {}", url.as_str());
                        userdata
                            .ui_tx
                            .write()
                            .unwrap()
                            .send(UiMessage::OpenUrlFromString(
                                String::from(url.as_str()),
                                true,
                                0,
                            ))
                            .unwrap();
                    }
                });
            });
        });
    }
fn show_gemini ( & mut self , base_url : & Url , content : & str ) { trace ! ( " " ) ; let textwrap = SETTINGS . read ( ) . unwrap ( ) . get_str ( " " ) . unwrap ( ) ; let textwrap_int = textwrap . parse :: < usize > ( ) . unwrap ( ) ; let mut viewport_width = self . get_gemini_viewport_width ( ) - 10 ; viewport_width = std :: cmp :: min ( textwrap_int , viewport_width ) ; let mut app = self . app . write ( ) . unwrap ( ) ; app . call_on_name ( " " , | v : & mut ui :: layout :: Layout | { v . set_view ( " " ) ; } ) ; info ! ( " " viewport_width ) ; app . call_on_name ( " " , | v : & mut SelectView < GeminiLine > | { v . clear ( ) ; let lines = content . lines ( ) ; for l in lines { let line = l . to_string ( ) ; if let Ok ( gemini_line ) = GeminiLine :: parse ( line . clone ( ) , & base_url ) { match gemini_line . line_type { LineType :: Text => { let label = gemini_line . clone ( ) . label ( ) ; if label . len ( ) > viewport_width { let iter = wrap_iter ( & label , viewport_width ) ; for str in iter { let mut formatted = StyledString :: new ( ) ; let label = format ! ( " " str ) ; formatted . append ( label ) ; v . add_item ( formatted , gemini_line . clone ( ) ) ; } } else { v . add_item ( format ! ( " " label ) , gemini_line . clone ( ) ) ; } } LineType :: UnorderedList => { let label = gemini_line . clone ( ) . label ( ) ; if label . len ( ) > viewport_width { let iter = wrap_iter ( & label , viewport_width ) ; let mut first = true ; for str in iter { let mut formatted = StyledString :: new ( ) ; let label = if first { format ! ( " " str ) } else { format ! ( " " str ) } ; first = false ; formatted . append ( label ) ; v . add_item ( formatted , gemini_line . clone ( ) ) ; } } else { v . add_item ( format ! ( " " label ) , gemini_line . clone ( ) ) ; } } LineType :: Link => { let label = gemini_line . clone ( ) . label ( ) ; v . add_item ( label , gemini_line . clone ( ) ) ; } LineType :: PreformattedToggle => { // Skip for now } _ => { let label = gemini_line . clone ( ) . label ( ) ; v . add_item ( label , gemini_line . clone ( ) ) ; } } } } v . set_on_submit ( | app , entry | { app . with_user_data ( | userdata : & mut UserData | { if entry . line_type == LineType :: Link { let url = entry . url . as_ref ( ) . unwrap ( ) ; info ! ( " " url as_str ( ) ) ; userdata . ui_tx . write ( ) . unwrap ( ) . send ( UiMessage :: OpenUrlFromString ( String :: from ( url . as_str ( ) ) , true , 0 , ) ) . unwrap ( ) ; } } ) ; } ) ; } ) ; }
Renders a gemini site in a cursive::TextView
Renders a gemini site in a cursive :: TextView
&mut self
base_url
&Url
content
&str
&mut self
base_url
&Url
content
&str