pub fn new(app: Cursive, url: Url) -> Result<Controller, Box<dyn Error>> {
        let (tx, rx) = mpsc::channel::<ControllerMessage>();
        let mut ncgopher = NcGopher::new(app, tx.clone());

        let controller = Controller {
            rx: Arc::new(rx),
            tx: Arc::new(RwLock::new(tx)),
            ui: Arc::new(RwLock::new(ncgopher.clone())),
            history: Arc::new(Mutex::new(History::new()?)),
            bookmarks: Arc::new(Mutex::new(Bookmarks::new())),
            certificates: Arc::new(Mutex::new(Certificates::new())),
            content: Arc::new(Mutex::new(String::new())),
            current_url: Arc::new(Mutex::new(Url::parse("gopher://host.none").unwrap())),
        };
        ncgopher.setup_ui();
        // Add old entries to history on start-up
        let entries = controller
            .history
            .lock()
            .unwrap()
            .get_latest_history(10)
            .expect("Could not get latest history");
        for entry in entries {
            controller
                .ui
                .read()
                .unwrap()
                .ui_tx
                .read()
                .unwrap()
                .send(UiMessage::AddToHistoryMenu(entry))?;
        }
        info!("Adding existing bookmarks to menu");
        let entries = controller.bookmarks.lock().unwrap().get_bookmarks();
        for entry in entries {
            info!("Found bookmark entry");
            controller
                .ui
                .read()
                .unwrap()
                .ui_tx
                .read()
                .unwrap()
                .send(UiMessage::AddToBookmarkMenu(entry))?;
        }
        // Add bookmarks to bookmark menu on startup
        ncgopher.open_url(url, true, 0);
        info!("Controller::new()");
        Ok(controller)
    }
/// Create a new controller (created in main.rs)
Create a new controller (created in main.rs)
Create a new controller ( created in main . rs )
pub fn new(app: Cursive, url: Url) -> Result<Controller, Box<dyn Error>> {
        let (tx, rx) = mpsc::channel::<ControllerMessage>();
        let mut ncgopher = NcGopher::new(app, tx.clone());
        let controller = Controller {
            rx: Arc::new(rx),
            tx: Arc::new(RwLock::new(tx)),
            ui: Arc::new(RwLock::new(ncgopher.clone())),
            history: Arc::new(Mutex::new(History::new()?)),
            bookmarks: Arc::new(Mutex::new(Bookmarks::new())),
            certificates: Arc::new(Mutex::new(Certificates::new())),
            content: Arc::new(Mutex::new(String::new())),
            current_url: Arc::new(Mutex::new(Url::parse("gopher://host.none").unwrap())),
        };
        ncgopher.setup_ui();
        // Add old entries to history on start-up
        let entries = controller
            .history
            .lock()
            .unwrap()
            .get_latest_history(10)
            .expect("Could not get latest history");
        for entry in entries {
            controller
                .ui
                .read()
                .unwrap()
                .ui_tx
                .read()
                .unwrap()
                .send(UiMessage::AddToHistoryMenu(entry))?;
        }
        info!("Adding existing bookmarks to menu");
        let entries = controller.bookmarks.lock().unwrap().get_bookmarks();
        for entry in entries {
            info!("Found bookmark entry");
            controller
                .ui
                .read()
                .unwrap()
                .ui_tx
                .read()
                .unwrap()
                .send(UiMessage::AddToBookmarkMenu(entry))?;
        }
        // Add bookmarks to bookmark menu on startup
        ncgopher.open_url(url, true, 0);
        info!("Controller::new()");
        Ok(controller)
    }
pub fn new ( app : Cursive , url : Url ) -> Result < Controller , Box < dyn Error > > { let ( tx , rx ) = mpsc :: channel :: < ControllerMessage > ( ) ; let mut ncgopher = NcGopher :: new ( app , tx . clone ( ) ) ; let controller = Controller { rx : Arc :: new ( rx ) , tx : Arc :: new ( RwLock :: new ( tx ) ) , ui : Arc :: new ( RwLock :: new ( ncgopher . clone ( ) ) ) , history : Arc :: new ( Mutex :: new ( History :: new ( ) ? ) ) , bookmarks : Arc :: new ( Mutex :: new ( Bookmarks :: new ( ) ) ) , certificates : Arc :: new ( Mutex :: new ( Certificates :: new ( ) ) ) , content : Arc :: new ( Mutex :: new ( String :: new ( ) ) ) , current_url : Arc :: new ( Mutex :: new ( Url :: parse ( " " ) . unwrap ( ) ) ) , } ; ncgopher . setup_ui ( ) ; // Add old entries to history on start-up let entries = controller . history . lock ( ) . unwrap ( ) . get_latest_history ( 10 ) . expect ( " " ) ; for entry in entries { controller . ui . read ( ) . unwrap ( ) . ui_tx . read ( ) . unwrap ( ) . send ( UiMessage :: AddToHistoryMenu ( entry ) ) ? ; } info ! ( " " ) ; let entries = controller . bookmarks . lock ( ) . unwrap ( ) . get_bookmarks ( ) ; for entry in entries { info ! ( " " ) ; controller . ui . read ( ) . unwrap ( ) . ui_tx . read ( ) . unwrap ( ) . send ( UiMessage :: AddToBookmarkMenu ( entry ) ) ? ; } // Add bookmarks to bookmark menu on startup ncgopher . open_url ( url , true , 0 ) ; info ! ( " " ) ; Ok ( controller ) }
Create a new controller (created in main.rs)
Create a new controller ( created in main . rs )
app
Cursive
url
Url
app
Cursive
url
Url