fn show_gophermap(&mut self, content: String, index: usize) {
        let mut title: String = "".to_string();
        let textwrap = SETTINGS.read().unwrap().get_str("textwrap").unwrap();
        let textwrap_int = textwrap.parse::<usize>().unwrap();
        let mut viewport_width = self.get_viewport_width() - 7;
        viewport_width = std::cmp::min(textwrap_int, viewport_width);
        info!("Viewport-width = {}", viewport_width);
        let mut app = self.app.write().unwrap();
        app.call_on_name("main", |v: &mut ui::layout::Layout| {
            v.set_view("content");
        });
        let msg = String::new();

        app.call_on_name("content", |view: &mut SelectView<GopherMapEntry>| {
            view.clear();
            let lines = content.lines();
            let mut gophermap = Vec::new();
            let mut first = true;
            for l in lines {
                if first {
                    if l.starts_with('/') {
                        title = l.to_string();
                    }
                    first = false;
                }
                if l != "." {
                    match GopherMapEntry::parse(l.to_string()) {
                        Ok(gl) => {
                            gophermap.push(gl);
                        }
                        Err(err) => {
                            warn!("Invalid gophermap line: {}", err);
                        }
                    };
                }
            }
            for l in gophermap {
                let entry = l.clone();

                let label = entry.clone().label();
                if entry.item_type == ItemType::Inline && label.len() > viewport_width {
                    let iter = wrap_iter(&label, viewport_width);
                    // TODO: use cursive::utils::lines::simple::make_lines
                    for str in iter {
                        let mut formatted = StyledString::new();
                        let label = format!("{}  {}", ItemType::as_str(entry.item_type), str);
                        formatted.append(label);
                        view.add_item(formatted, l.clone());
                    }
                } else {
                    let mut formatted = StyledString::new();
                    let label = format!("{}  {}", ItemType::as_str(entry.item_type), entry.label());
                    formatted.append(label);
                    view.add_item(formatted, l.clone());
                }
            }
            view.set_on_submit(|app, entry| {
                app.with_user_data(|userdata: &mut UserData| {
                    // FIXME Remove duplicate code
                    if ItemType::is_download(entry.item_type)
                        || ItemType::is_text(entry.item_type)
                        || ItemType::is_dir(entry.item_type)
                    {
                        userdata
                            .ui_tx
                            .write()
                            .unwrap()
                            .send(UiMessage::OpenUrl(entry.url.clone(), true, 0))
                            .unwrap();
                    } else if ItemType::is_query(entry.item_type) {
                        userdata
                            .ui_tx
                            .write()
                            .unwrap()
                            .send(UiMessage::OpenQueryDialog(entry.url.clone()))
                            .unwrap();
                    } else if ItemType::is_html(entry.item_type) {
                        userdata
                            .controller_tx
                            .write()
                            .unwrap()
                            .send(ControllerMessage::OpenHtml(entry.url.clone()))
                            .unwrap();
                    } else if ItemType::is_image(entry.item_type) {
                        userdata
                            .controller_tx
                            .write()
                            .unwrap()
                            .send(ControllerMessage::OpenImage(entry.url.clone()))
                            .unwrap();
                    } else if ItemType::is_telnet(entry.item_type) {
                        userdata
                            .controller_tx
                            .write()
                            .unwrap()
                            .send(ControllerMessage::OpenTelnet(entry.url.clone()))
                            .unwrap();
                    }
                });
            });
            view.set_selection(index);
        });
        if !msg.is_empty() {
            app.with_user_data(|userdata: &mut UserData| {
                userdata
                    .ui_tx
                    .read()
                    .unwrap()
                    .send(UiMessage::ShowMessage(msg))
                    .unwrap()
            });
        }

        // FIXME: Call this from the previous callback
        if !title.is_empty() {
            trace!("TITLE SET");
            app.call_on_name("main", |v: &mut ui::layout::Layout| {
                trace!("SET TITLE");
                v.set_title("content".to_string(), title);
            });
        }
    }
/// Renders a gophermap in a cursive::TextView
Renders a gophermap in a cursive::TextView
Renders a gophermap in a cursive :: TextView
fn show_gophermap(&mut self, content: String, index: usize) {
        let mut title: String = "".to_string();
        let textwrap = SETTINGS.read().unwrap().get_str("textwrap").unwrap();
        let textwrap_int = textwrap.parse::<usize>().unwrap();
        let mut viewport_width = self.get_viewport_width() - 7;
        viewport_width = std::cmp::min(textwrap_int, viewport_width);
        info!("Viewport-width = {}", viewport_width);
        let mut app = self.app.write().unwrap();
        app.call_on_name("main", |v: &mut ui::layout::Layout| {
            v.set_view("content");
        });
        let msg = String::new();
        app.call_on_name("content", |view: &mut SelectView<GopherMapEntry>| {
            view.clear();
            let lines = content.lines();
            let mut gophermap = Vec::new();
            let mut first = true;
            for l in lines {
                if first {
                    if l.starts_with('/') {
                        title = l.to_string();
                    }
                    first = false;
                }
                if l != "." {
                    match GopherMapEntry::parse(l.to_string()) {
                        Ok(gl) => {
                            gophermap.push(gl);
                        }
                        Err(err) => {
                            warn!("Invalid gophermap line: {}", err);
                        }
                    };
                }
            }
            for l in gophermap {
                let entry = l.clone();
                let label = entry.clone().label();
                if entry.item_type == ItemType::Inline && label.len() > viewport_width {
                    let iter = wrap_iter(&label, viewport_width);
                    // TODO: use cursive::utils::lines::simple::make_lines
                    for str in iter {
                        let mut formatted = StyledString::new();
                        let label = format!("{}  {}", ItemType::as_str(entry.item_type), str);
                        formatted.append(label);
                        view.add_item(formatted, l.clone());
                    }
                } else {
                    let mut formatted = StyledString::new();
                    let label = format!("{}  {}", ItemType::as_str(entry.item_type), entry.label());
                    formatted.append(label);
                    view.add_item(formatted, l.clone());
                }
            }
            view.set_on_submit(|app, entry| {
                app.with_user_data(|userdata: &mut UserData| {
                    // FIXME Remove duplicate code
                    if ItemType::is_download(entry.item_type)
                        || ItemType::is_text(entry.item_type)
                        || ItemType::is_dir(entry.item_type)
                    {
                        userdata
                            .ui_tx
                            .write()
                            .unwrap()
                            .send(UiMessage::OpenUrl(entry.url.clone(), true, 0))
                            .unwrap();
                    } else if ItemType::is_query(entry.item_type) {
                        userdata
                            .ui_tx
                            .write()
                            .unwrap()
                            .send(UiMessage::OpenQueryDialog(entry.url.clone()))
                            .unwrap();
                    } else if ItemType::is_html(entry.item_type) {
                        userdata
                            .controller_tx
                            .write()
                            .unwrap()
                            .send(ControllerMessage::OpenHtml(entry.url.clone()))
                            .unwrap();
                    } else if ItemType::is_image(entry.item_type) {
                        userdata
                            .controller_tx
                            .write()
                            .unwrap()
                            .send(ControllerMessage::OpenImage(entry.url.clone()))
                            .unwrap();
                    } else if ItemType::is_telnet(entry.item_type) {
                        userdata
                            .controller_tx
                            .write()
                            .unwrap()
                            .send(ControllerMessage::OpenTelnet(entry.url.clone()))
                            .unwrap();
                    }
                });
            });
            view.set_selection(index);
        });
        if !msg.is_empty() {
            app.with_user_data(|userdata: &mut UserData| {
                userdata
                    .ui_tx
                    .read()
                    .unwrap()
                    .send(UiMessage::ShowMessage(msg))
                    .unwrap()
            });
        }
        // FIXME: Call this from the previous callback
        if !title.is_empty() {
            trace!("TITLE SET");
            app.call_on_name("main", |v: &mut ui::layout::Layout| {
                trace!("SET TITLE");
                v.set_title("content".to_string(), title);
            });
        }
    }
fn show_gophermap ( & mut self , content : String , index : usize ) { let mut title : String = " " . to_string ( ) ; let textwrap = SETTINGS . read ( ) . unwrap ( ) . get_str ( " " ) . unwrap ( ) ; let textwrap_int = textwrap . parse :: < usize > ( ) . unwrap ( ) ; let mut viewport_width = self . get_viewport_width ( ) - 7 ; viewport_width = std :: cmp :: min ( textwrap_int , viewport_width ) ; info ! ( " " viewport_width ) ; let mut app = self . app . write ( ) . unwrap ( ) ; app . call_on_name ( " " , | v : & mut ui :: layout :: Layout | { v . set_view ( " " ) ; } ) ; let msg = String :: new ( ) ; app . call_on_name ( " " , | view : & mut SelectView < GopherMapEntry > | { view . clear ( ) ; let lines = content . lines ( ) ; let mut gophermap = Vec :: new ( ) ; let mut first = true ; for l in lines { if first { if l . starts_with ( '/' ) { title = l . to_string ( ) ; } first = false ; } if l != " " { match GopherMapEntry :: parse ( l . to_string ( ) ) { Ok ( gl ) => { gophermap . push ( gl ) ; } Err ( err ) => { warn ! ( " " err ) ; } } ; } } for l in gophermap { let entry = l . clone ( ) ; let label = entry . clone ( ) . label ( ) ; if entry . item_type == ItemType :: Inline && label . len ( ) > viewport_width { let iter = wrap_iter ( & label , viewport_width ) ; // TODO: use cursive::utils::lines::simple::make_lines for str in iter { let mut formatted = StyledString :: new ( ) ; let label = format ! ( " " ItemType as_str ( entry item_type ) str ) ; formatted . append ( label ) ; view . add_item ( formatted , l . clone ( ) ) ; } } else { let mut formatted = StyledString :: new ( ) ; let label = format ! ( " " ItemType as_str ( entry item_type ) entry label ( ) ) ; formatted . append ( label ) ; view . add_item ( formatted , l . clone ( ) ) ; } } view . set_on_submit ( | app , entry | { app . with_user_data ( | userdata : & mut UserData | { // FIXME Remove duplicate code if ItemType :: is_download ( entry . item_type ) || ItemType :: is_text ( entry . item_type ) || ItemType :: is_dir ( entry . item_type ) { userdata . ui_tx . write ( ) . unwrap ( ) . send ( UiMessage :: OpenUrl ( entry . url . clone ( ) , true , 0 ) ) . unwrap ( ) ; } else if ItemType :: is_query ( entry . item_type ) { userdata . ui_tx . write ( ) . unwrap ( ) . send ( UiMessage :: OpenQueryDialog ( entry . url . clone ( ) ) ) . unwrap ( ) ; } else if ItemType :: is_html ( entry . item_type ) { userdata . controller_tx . write ( ) . unwrap ( ) . send ( ControllerMessage :: OpenHtml ( entry . url . clone ( ) ) ) . unwrap ( ) ; } else if ItemType :: is_image ( entry . item_type ) { userdata . controller_tx . write ( ) . unwrap ( ) . send ( ControllerMessage :: OpenImage ( entry . url . clone ( ) ) ) . unwrap ( ) ; } else if ItemType :: is_telnet ( entry . item_type ) { userdata . controller_tx . write ( ) . unwrap ( ) . send ( ControllerMessage :: OpenTelnet ( entry . url . clone ( ) ) ) . unwrap ( ) ; } } ) ; } ) ; view . set_selection ( index ) ; } ) ; if ! msg . is_empty ( ) { app . with_user_data ( | userdata : & mut UserData | { userdata . ui_tx . read ( ) . unwrap ( ) . send ( UiMessage :: ShowMessage ( msg ) ) . unwrap ( ) } ) ; } // FIXME: Call this from the previous callback if ! title . is_empty ( ) { trace ! ( " " ) ; app . call_on_name ( " " , | v : & mut ui :: layout :: Layout | { trace ! ( " " ) ; v . set_title ( " " . to_string ( ) , title ) ; } ) ; } }
Renders a gophermap in a cursive::TextView
Renders a gophermap in a cursive :: TextView
&mut self
content
String
index
usize
&mut self
content
String
index
usize