pub fn run(
        mut self,
        con: &AppContext,
        skin: Skin,
    ) -> Result<Option<Launchable>, ProgramError> {
        let mut screen = Screen::new(con, skin)?;

        // create the initial state
        if let Some(bs) = BrowserState::new(
            con.launch_args.root.clone(),
            con.launch_args.tree_options.clone(),
            &screen,
            &TaskLifetime::unlimited(),
        )? {
            self.push(Box::new(bs));
        } else {
            unreachable!();
        }

        let mut cmd = Command::new();

        // if some commands were passed to the application
        //  we execute them before even starting listening for events
        if let Some(unparsed_commands) = &con.launch_args.commands {
            let commands = parse_command_sequence(unparsed_commands, con)?;
            for arg_cmd in &commands {
                cmd = (*arg_cmd).clone();
                cmd = self.apply_command(cmd, &mut screen, con)?;
                self.do_pending_tasks(&cmd, &mut screen, con, TaskLifetime::unlimited())?;
                if self.quitting {
                    return Ok(self.launch_at_end.take());
                }
            }
        }

        // we listen for events in a separate thread so that we can go on listening
        // when a long search is running, and interrupt it if needed
        let event_source = EventSource::new();
        let rx_events = event_source.receiver();

        screen.input_field.display();
        self.mut_state().display(&mut screen, con)?;
        screen.write_status_text("Hit <esc> to quit, '?' for help, or some letters to search")?;
        self.state().write_flags(&mut screen, con)?;
        loop {
            let tl = TaskLifetime::new(event_source.shared_event_count());
            if !self.quitting {
                self.do_pending_tasks(&cmd, &mut screen, con, tl)?;
            }
            let event = match rx_events.recv() {
                Ok(event) => event,
                Err(_) => {
                    // this is how we quit the application,
                    // when the input thread is properly closed
                    break;
                }
            };
            cmd.add_event(&event, &mut screen.input_field, con);
            cmd = self.apply_command(cmd, &mut screen, con)?;
            event_source.unblock(self.quitting);
        }
        Ok(self.launch_at_end.take())
    }
/// This is the main loop of the application
This is the main loop of the application
This is the main loop of the application
pub fn run(
        mut self,
        con: &AppContext,
        skin: Skin,
    ) -> Result<Option<Launchable>, ProgramError> {
        let mut screen = Screen::new(con, skin)?;
        // create the initial state
        if let Some(bs) = BrowserState::new(
            con.launch_args.root.clone(),
            con.launch_args.tree_options.clone(),
            &screen,
            &TaskLifetime::unlimited(),
        )? {
            self.push(Box::new(bs));
        } else {
            unreachable!();
        }
        let mut cmd = Command::new();
        // if some commands were passed to the application
        //  we execute them before even starting listening for events
        if let Some(unparsed_commands) = &con.launch_args.commands {
            let commands = parse_command_sequence(unparsed_commands, con)?;
            for arg_cmd in &commands {
                cmd = (*arg_cmd).clone();
                cmd = self.apply_command(cmd, &mut screen, con)?;
                self.do_pending_tasks(&cmd, &mut screen, con, TaskLifetime::unlimited())?;
                if self.quitting {
                    return Ok(self.launch_at_end.take());
                }
            }
        }
        // we listen for events in a separate thread so that we can go on listening
        // when a long search is running, and interrupt it if needed
        let event_source = EventSource::new();
        let rx_events = event_source.receiver();
        screen.input_field.display();
        self.mut_state().display(&mut screen, con)?;
        screen.write_status_text("Hit <esc> to quit, '?' for help, or some letters to search")?;
        self.state().write_flags(&mut screen, con)?;
        loop {
            let tl = TaskLifetime::new(event_source.shared_event_count());
            if !self.quitting {
                self.do_pending_tasks(&cmd, &mut screen, con, tl)?;
            }
            let event = match rx_events.recv() {
                Ok(event) => event,
                Err(_) => {
                    // this is how we quit the application,
                    // when the input thread is properly closed
                    break;
                }
            };
            cmd.add_event(&event, &mut screen.input_field, con);
            cmd = self.apply_command(cmd, &mut screen, con)?;
            event_source.unblock(self.quitting);
        }
        Ok(self.launch_at_end.take())
    }
pub fn run ( mut self , con : & AppContext , skin : Skin , ) -> Result < Option < Launchable > , ProgramError > { let mut screen = Screen :: new ( con , skin ) ? ; // create the initial state if let Some ( bs ) = BrowserState :: new ( con . launch_args . root . clone ( ) , con . launch_args . tree_options . clone ( ) , & screen , & TaskLifetime :: unlimited ( ) , ) ? { self . push ( Box :: new ( bs ) ) ; } else { unreachable ! ( ) ; } let mut cmd = Command :: new ( ) ; // if some commands were passed to the application //  we execute them before even starting listening for events if let Some ( unparsed_commands ) = & con . launch_args . commands { let commands = parse_command_sequence ( unparsed_commands , con ) ? ; for arg_cmd in & commands { cmd = ( * arg_cmd ) . clone ( ) ; cmd = self . apply_command ( cmd , & mut screen , con ) ? ; self . do_pending_tasks ( & cmd , & mut screen , con , TaskLifetime :: unlimited ( ) ) ? ; if self . quitting { return Ok ( self . launch_at_end . take ( ) ) ; } } } // we listen for events in a separate thread so that we can go on listening // when a long search is running, and interrupt it if needed let event_source = EventSource :: new ( ) ; let rx_events = event_source . receiver ( ) ; screen . input_field . display ( ) ; self . mut_state ( ) . display ( & mut screen , con ) ? ; screen . write_status_text ( " " ) ? ; self . state ( ) . write_flags ( & mut screen , con ) ? ; loop { let tl = TaskLifetime :: new ( event_source . shared_event_count ( ) ) ; if ! self . quitting { self . do_pending_tasks ( & cmd , & mut screen , con , tl ) ? ; } let event = match rx_events . recv ( ) { Ok ( event ) => event , Err ( _ ) => { // this is how we quit the application, // when the input thread is properly closed break ; } } ; cmd . add_event ( & event , & mut screen . input_field , con ) ; cmd = self . apply_command ( cmd , & mut screen , con ) ? ; event_source . unblock ( self . quitting ) ; } Ok ( self . launch_at_end . take ( ) ) }
This is the main loop of the application
This is the main loop of the application
mut self
con
&AppContext
skin
Skin
mut self
con
&AppContext
skin
Skin