Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

Commit

Permalink
to_alternate: Switch back to main screen if into_raw_mode fails (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersk authored and TimonPost committed Oct 1, 2019
1 parent e9f7624 commit 8fe5b7f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/screen/alternate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ impl AlternateScreen {

command.enable()?;

let mut alternate = AlternateScreen {
command,
_raw_screen: None,
};

if raw_mode {
let raw_screen = RawScreen::into_raw_mode()?;
return Ok(AlternateScreen {
command,
_raw_screen: Some(raw_screen),
});
// If into_raw_mode fails, alternate will be dropped and
// we'll switch back to the main screen.
alternate._raw_screen = Some(RawScreen::into_raw_mode()?);
}

Ok(AlternateScreen {
command,
_raw_screen: None,
})
Ok(alternate)
}

/// Switch the alternate screen back to the main screen.
Expand Down

0 comments on commit 8fe5b7f

Please sign in to comment.