Skip to content

Commit

Permalink
use Drop trait instead of defer
Browse files Browse the repository at this point in the history
  • Loading branch information
ynqa committed Feb 26, 2024
1 parent 794bb1d commit c7d9c28
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ path = "src/lib.rs"
crossterm = { version = "0.27.0", features = ["use-dev-tty"] }
indexmap = "2.2.3"
radix_trie = "0.2.1"
scopeguard = "1.1.0"
serde = { version = "1.0.197" }
serde_json = { version = "1.0.114", features = ["preserve_order"] }
thiserror = "1.0.50"
Expand Down
17 changes: 8 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@
//! ## Stargazers over time
//! [![Stargazers over time](https://starchart.cc/ynqa/promkit.svg?variant=adaptive)](https://starchart.cc/ynqa/promkit)
extern crate scopeguard;

pub use crossterm;

mod core;
Expand All @@ -112,8 +110,6 @@ pub mod validate;
use std::io;
use std::sync::Once;

use scopeguard::defer;

use crate::{
crossterm::{
cursor,
Expand All @@ -139,6 +135,14 @@ pub struct Prompt<T> {

static ONCE: Once = Once::new();

impl<T> Drop for Prompt<T> {
fn drop(&mut self) {
execute!(io::stdout(), cursor::MoveToNextLine(1)).ok();
execute!(io::stdout(), cursor::Show).ok();
disable_raw_mode().ok();
}
}

impl<T> Prompt<T> {
/// Creates a new `Prompt` instance
/// with specified renderables, evaluator, and output functions.
Expand Down Expand Up @@ -199,11 +203,6 @@ impl<T> Prompt<T> {

enable_raw_mode()?;
execute!(io::stdout(), cursor::Hide)?;
defer! {{
execute!(io::stdout(), cursor::MoveToNextLine(1)).ok();
execute!(io::stdout(), cursor::Show).ok();
disable_raw_mode().ok();
}};

let mut terminal = Terminal::start_session(&mut engine)?;
let size = engine.size()?;
Expand Down

0 comments on commit c7d9c28

Please sign in to comment.