Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.3.5 #21

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Put the package in your `Cargo.toml`.

```toml
[dependencies]
promkit = "0.3.4"
promkit = "0.3.5"
```

## Features
Expand Down
2 changes: 1 addition & 1 deletion promkit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "promkit"
version = "0.3.4"
version = "0.3.5"
authors = ["ynqa <[email protected]>"]
edition = "2021"
description = "A toolkit for building your own interactive command-line tools"
Expand Down
141 changes: 0 additions & 141 deletions promkit/src/engine.rs

This file was deleted.

57 changes: 34 additions & 23 deletions promkit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
//!
//! ```toml
//! [dependencies]
//! promkit = "0.3.4"
//! promkit = "0.3.5"
//! ```
//!
//! ## Features
//!
//! - Support cross-platform both UNIX and Windows owing to [crossterm](https://github.com/crossterm-rs/crossterm)
//! - Various building methods
//! - Preset; Support for quickly setting up a UI by providing simple parameters.
//! - [Readline](https://github.com/ynqa/promkit/tree/v0.3.4#readline)
//! - [Confirm](https://github.com/ynqa/promkit/tree/v0.3.4#confirm)
//! - [Password](https://github.com/ynqa/promkit/tree/v0.3.4#password)
//! - [Select](https://github.com/ynqa/promkit/tree/v0.3.4#select)
//! - [QuerySelect](https://github.com/ynqa/promkit/tree/v0.3.4#queryselect)
//! - [Checkbox](https://github.com/ynqa/promkit/tree/v0.3.4#checkbox)
//! - [Tree](https://github.com/ynqa/promkit/tree/v0.3.4#tree)
//! - [Readline](https://github.com/ynqa/promkit/tree/v0.3.5#readline)
//! - [Confirm](https://github.com/ynqa/promkit/tree/v0.3.5#confirm)
//! - [Password](https://github.com/ynqa/promkit/tree/v0.3.5#password)
//! - [Select](https://github.com/ynqa/promkit/tree/v0.3.5#select)
//! - [QuerySelect](https://github.com/ynqa/promkit/tree/v0.3.5#queryselect)
//! - [Checkbox](https://github.com/ynqa/promkit/tree/v0.3.5#checkbox)
//! - [Tree](https://github.com/ynqa/promkit/tree/v0.3.5#tree)
//! - Combining various UI components.
//! - They are provided with the same interface, allowing users to choose and
//! assemble them according to their preferences.
Expand All @@ -39,7 +39,7 @@
//!
//! ## Examples/Demos
//!
//! See [here](https://github.com/ynqa/promkit/tree/v0.3.4#examplesdemos)
//! See [here](https://github.com/ynqa/promkit/tree/v0.3.5#examplesdemos)
//!
//! ## Why *promkit*?
//!
Expand Down Expand Up @@ -97,7 +97,6 @@ pub use serde_json;

mod core;
pub use core::*;
pub mod engine;
mod error;
pub use error::{Error, Result};
pub mod grapheme;
Expand All @@ -120,7 +119,6 @@ use crate::{
execute,
terminal::{disable_raw_mode, enable_raw_mode},
},
engine::Engine,
pane::Pane,
terminal::Terminal,
};
Expand Down Expand Up @@ -210,9 +208,13 @@ pub struct Prompt<T> {

impl<T> Drop for Prompt<T> {
fn drop(&mut self) {
execute!(io::stdout(), cursor::MoveToNextLine(1)).ok();
execute!(io::stdout(), cursor::Show).ok();
execute!(io::stdout(), event::DisableMouseCapture).ok();
execute!(
io::stdout(),
cursor::Show,
event::DisableMouseCapture,
cursor::MoveToNextLine(1),
)
.ok();
disable_raw_mode().ok();
}
}
Expand Down Expand Up @@ -251,25 +253,34 @@ impl<T> Prompt<T> {
///
/// Returns a `Result` containing the produced result or an error.
pub fn run(&mut self) -> Result<T> {
let mut engine = Engine::new(io::stdout());

enable_raw_mode()?;
execute!(io::stdout(), cursor::Hide)?;

let size = engine.size()?;
let size = crossterm::terminal::size()?;
let panes = self.renderer.create_panes(size.0);
let mut terminal = Terminal::start_session(&mut engine, &panes)?;
terminal.draw(&mut engine, panes)?;
let mut terminal = Terminal::start_session(&panes)?;
terminal.draw(&panes)?;

loop {
let ev = event::read()?;

if (self.evaluator)(&ev, &mut self.renderer)? == PromptSignal::Quit {
break;
match &ev {
Event::Resize(_, _) => {
terminal.position = (0, 0);
crossterm::execute!(
io::stdout(),
crossterm::terminal::Clear(crossterm::terminal::ClearType::Purge),
)?;
}
_ => {
if (self.evaluator)(&ev, &mut self.renderer)? == PromptSignal::Quit {
break;
}
}
}

let size = engine.size()?;
terminal.draw(&mut engine, self.renderer.create_panes(size.0))?;
let size = crossterm::terminal::size()?;
terminal.draw(&self.renderer.create_panes(size.0))?;
}

(self.producer)(&*self.renderer)
Expand Down
Loading
Loading