fn apply_command(
        &mut self,
        w: &mut impl Write,
        mut cmd: Command,
        screen: &mut Screen,
        con: &AppContext,
    ) -> Result<Command, ProgramError> {
        debug!("action: {:?}", &cmd.action);
        let mut error: Option<String> = None;
        match self.mut_state().apply(&mut cmd, screen, con)? {
            AppStateCmdResult::Quit => {
                debug!("cmd result quit");
                self.quitting = true;
            }
            AppStateCmdResult::Launch(launchable) => {
                self.launch_at_end = Some(*launchable);
                self.quitting = true;
            }
            AppStateCmdResult::NewState(boxed_state, new_cmd) => {
                self.push(boxed_state);
                cmd = new_cmd;
            }
            AppStateCmdResult::RefreshState { clear_cache } => {
                if clear_cache {
                    file_sizes::clear_cache();
                }
                cmd = self.mut_state().refresh(screen, con);
            }
            AppStateCmdResult::PopState => {
                if self.states.len() == 1 {
                    debug!("quitting on last pop state");
                    self.quitting = true;
                } else {
                    self.states.pop();
                    cmd = self.mut_state().refresh(screen, con);
                }
            }
            AppStateCmdResult::PopStateAndReapply => {
                if self.states.len() == 1 {
                    debug!("quitting on last pop state");
                    self.quitting = true;
                } else {
                    self.states.pop();
                    debug!("about to reapply {:?}", &cmd);
                    return self.apply_command(w, cmd, screen, con);
                }
            }
            AppStateCmdResult::DisplayError(txt) => {
                error = Some(txt);
            }
            _ => {}
        }
        self.mut_state().display(w, screen, con)?;
        match error {
            Some(text) => Status::from_error(Composite::from_inline(&text)).display(w, screen)?,
            None => self.state().write_status(w, &cmd, screen, con)?,
        }
        screen.input_field.set_content(&cmd.raw);
        screen.input_field.display_on(w)?;
        self.state().write_flags(w, screen, con)?;
        Ok(cmd)
    }
/// apply a command, and returns a command, which may be the same (modified or not)
///  or a new one.
/// This normally mutates self
apply a command, and returns a command, which may be the same (modified or not)
or a new one.
This normally mutates self
apply a command and returns a command which may be the same ( modified or not ) or a new one . This normally mutates self
fn apply_command(
        &mut self,
        w: &mut impl Write,
        mut cmd: Command,
        screen: &mut Screen,
        con: &AppContext,
    ) -> Result<Command, ProgramError> {
        debug!("action: {:?}", &cmd.action);
        let mut error: Option<String> = None;
        match self.mut_state().apply(&mut cmd, screen, con)? {
            AppStateCmdResult::Quit => {
                debug!("cmd result quit");
                self.quitting = true;
            }
            AppStateCmdResult::Launch(launchable) => {
                self.launch_at_end = Some(*launchable);
                self.quitting = true;
            }
            AppStateCmdResult::NewState(boxed_state, new_cmd) => {
                self.push(boxed_state);
                cmd = new_cmd;
            }
            AppStateCmdResult::RefreshState { clear_cache } => {
                if clear_cache {
                    file_sizes::clear_cache();
                }
                cmd = self.mut_state().refresh(screen, con);
            }
            AppStateCmdResult::PopState => {
                if self.states.len() == 1 {
                    debug!("quitting on last pop state");
                    self.quitting = true;
                } else {
                    self.states.pop();
                    cmd = self.mut_state().refresh(screen, con);
                }
            }
            AppStateCmdResult::PopStateAndReapply => {
                if self.states.len() == 1 {
                    debug!("quitting on last pop state");
                    self.quitting = true;
                } else {
                    self.states.pop();
                    debug!("about to reapply {:?}", &cmd);
                    return self.apply_command(w, cmd, screen, con);
                }
            }
            AppStateCmdResult::DisplayError(txt) => {
                error = Some(txt);
            }
            _ => {}
        }
        self.mut_state().display(w, screen, con)?;
        match error {
            Some(text) => Status::from_error(Composite::from_inline(&text)).display(w, screen)?,
            None => self.state().write_status(w, &cmd, screen, con)?,
        }
        screen.input_field.set_content(&cmd.raw);
        screen.input_field.display_on(w)?;
        self.state().write_flags(w, screen, con)?;
        Ok(cmd)
    }
fn apply_command ( & mut self , w : & mut impl Write , mut cmd : Command , screen : & mut Screen , con : & AppContext , ) -> Result < Command , ProgramError > { debug ! ( " " cmd action ) ; let mut error : Option < String > = None ; match self . mut_state ( ) . apply ( & mut cmd , screen , con ) ? { AppStateCmdResult :: Quit => { debug ! ( " " ) ; self . quitting = true ; } AppStateCmdResult :: Launch ( launchable ) => { self . launch_at_end = Some ( * launchable ) ; self . quitting = true ; } AppStateCmdResult :: NewState ( boxed_state , new_cmd ) => { self . push ( boxed_state ) ; cmd = new_cmd ; } AppStateCmdResult :: RefreshState { clear_cache } => { if clear_cache { file_sizes :: clear_cache ( ) ; } cmd = self . mut_state ( ) . refresh ( screen , con ) ; } AppStateCmdResult :: PopState => { if self . states . len ( ) == 1 { debug ! ( " " ) ; self . quitting = true ; } else { self . states . pop ( ) ; cmd = self . mut_state ( ) . refresh ( screen , con ) ; } } AppStateCmdResult :: PopStateAndReapply => { if self . states . len ( ) == 1 { debug ! ( " " ) ; self . quitting = true ; } else { self . states . pop ( ) ; debug ! ( " " cmd ) ; return self . apply_command ( w , cmd , screen , con ) ; } } AppStateCmdResult :: DisplayError ( txt ) => { error = Some ( txt ) ; } _ => { } } self . mut_state ( ) . display ( w , screen , con ) ? ; match error { Some ( text ) => Status :: from_error ( Composite :: from_inline ( & text ) ) . display ( w , screen ) ? , None => self . state ( ) . write_status ( w , & cmd , screen , con ) ? , } screen . input_field . set_content ( & cmd . raw ) ; screen . input_field . display_on ( w ) ? ; self . state ( ) . write_flags ( w , screen , con ) ? ; Ok ( cmd ) }
apply a command, and returns a command, which may be the same (modified or not)
or a new one.
apply a command and returns a command which may be the same ( modified or not ) or a new one .
&mut self
w
&mut impl Write
cmd
Command
screen
&mut Screen
con
&AppContext
&mut self
w
&mut impl Write
cmd
Command
screen
&mut Screen
con
&AppContext