Drop implementations cleanup (#237)
This commit is contained in:
parent
41de9a63a1
commit
06c791714a
@ -75,6 +75,6 @@ impl AlternateScreen {
|
|||||||
impl Drop for AlternateScreen {
|
impl Drop for AlternateScreen {
|
||||||
/// This will switch back to the main screen on drop.
|
/// This will switch back to the main screen on drop.
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.to_main().unwrap();
|
let _ = self.to_main();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ use crate::sys;
|
|||||||
///
|
///
|
||||||
/// Please note that if this type drops, the raw screen will be undone. To prevent this behaviour call `disable_drop`.
|
/// Please note that if this type drops, the raw screen will be undone. To prevent this behaviour call `disable_drop`.
|
||||||
pub struct RawScreen {
|
pub struct RawScreen {
|
||||||
drop: bool,
|
disable_raw_mode_on_drop: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RawScreen {
|
impl RawScreen {
|
||||||
@ -37,7 +37,9 @@ impl RawScreen {
|
|||||||
|
|
||||||
command.enable()?;
|
command.enable()?;
|
||||||
|
|
||||||
Ok(RawScreen { drop: true })
|
Ok(RawScreen {
|
||||||
|
disable_raw_mode_on_drop: true,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Put terminal back in original modes.
|
/// Put terminal back in original modes.
|
||||||
@ -52,8 +54,8 @@ impl RawScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This will disable the drop logic of this type, which means that the rawscreen will not be disabled when this instance goes out of scope.
|
/// This will disable the drop logic of this type, which means that the rawscreen will not be disabled when this instance goes out of scope.
|
||||||
pub fn disable_drop(&mut self) {
|
pub fn disable_raw_mode_on_drop(&mut self) {
|
||||||
self.drop = false;
|
self.disable_raw_mode_on_drop = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,14 +78,16 @@ impl IntoRawMode for Stdout {
|
|||||||
fn into_raw_mode(self) -> Result<RawScreen> {
|
fn into_raw_mode(self) -> Result<RawScreen> {
|
||||||
RawScreen::into_raw_mode()?;
|
RawScreen::into_raw_mode()?;
|
||||||
// this make's sure that raw screen will be disabled when it goes out of scope.
|
// this make's sure that raw screen will be disabled when it goes out of scope.
|
||||||
Ok(RawScreen { drop: true })
|
Ok(RawScreen {
|
||||||
|
disable_raw_mode_on_drop: true,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for RawScreen {
|
impl Drop for RawScreen {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if self.drop == true {
|
if self.disable_raw_mode_on_drop {
|
||||||
RawScreen::disable_raw_mode().unwrap();
|
let _ = RawScreen::disable_raw_mode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user