Skip to content

Commit

Permalink
Merge branch 'main' into vi-multi-select
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelmello authored Mar 13, 2024
2 parents eeb5dad + 70ded79 commit e1db6ad
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 33 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

## [Unreleased] <!-- ReleaseDate -->

- Accept 'h' and 'l' keys in `MultiSelect` vim_mode to current clear selection and select all.
- Pressing Ctrl+D now cancels the prompt.
- Add support for `h` and `l` bindings when vim_mode is enabled on MultiSelect prompts, clearing or selecting all options respectively.

## [0.7.1] - 2024-03-10

- Fix render issue [#228](https://github.com/mikaelmello/inquire/pull/228) when using `console` crate as the terminal backend. Thanks @maospr for reporting.

## [0.7.0] - 2024-02-24

Expand Down Expand Up @@ -302,7 +307,8 @@ The library is already featureful enough to warrant a higher version number, bum

<!-- next-url -->

[unreleased]: https://github.com/mikaelmello/inquire/compare/v0.7.0...HEAD
[unreleased]: https://github.com/mikaelmello/inquire/compare/v0.7.1...HEAD
[0.7.1]: https://github.com/mikaelmello/inquire/compare/v0.7.0...v0.7.1
[0.7.0]: https://github.com/mikaelmello/inquire/compare/v0.6.2...v0.7.0
[0.6.2]: https://github.com/mikaelmello/inquire/compare/v0.6.1...v0.6.2
[0.6.1]: https://github.com/mikaelmello/inquire/compare/v0.6.0...v0.6.1
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ cargo run --example expense_tracker --features date
Put this line in your `Cargo.toml`, under `[dependencies]`.

```
inquire = "0.7.0"
inquire = "0.7.1"
```

\* This prompt type is gated under a feature flag, e.g.:

```
inquire = { version = "0.7.0", features = ["date"] }
inquire = { version = "0.7.1", features = ["date"] }
```

# Cross-cutting concerns
Expand Down Expand Up @@ -125,13 +125,13 @@ Binary Rust applications that intend to manipulate terminals will probably pick
However, if your application already uses a dependency other than crossterm, such as console or termion, you can enable another terminal via feature flags. It is also important to disable inquire's default features as it comes with `crossterm` enabled by default. Such as this:

```toml
inquire = { version = "0.7.0", default-features = false, features = ["termion", "date"] }
inquire = { version = "0.7.1", default-features = false, features = ["termion", "date"] }
```

or this:

```toml
inquire = { version = "0.7.0", default-features = false, features = ["console", "date"] }
inquire = { version = "0.7.1", default-features = false, features = ["console", "date"] }
```

## Formatting
Expand Down
8 changes: 4 additions & 4 deletions inquire-derive/CRATE_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
Put these lines in your `Cargo.toml`, under `[dependencies]`.

```
inquire = "0.7.0"
inquire-derive = "0.7.0"
inquire = "0.7.1"
inquire-derive = "0.7.1"
```

```
inquire = { version = "0.7.0", features = ["date", "editor"] }
inquire-derive = { version = "0.7.0" }
inquire = { version = "0.7.1", features = ["date", "editor"] }
inquire-derive = { version = "0.7.1" }
```
2 changes: 1 addition & 1 deletion inquire-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "inquire-derive"
version = "0.7.0"
version = "0.7.1"
description = "" # TODO
publish = false # TODO
repository = "https://github.com/mikaelmello/inquire"
Expand Down
4 changes: 2 additions & 2 deletions inquire/CRATE_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ It provides several different prompts in order to interactively ask the user for
Put this line in your `Cargo.toml`, under `[dependencies]`.

```
inquire = "0.7.0"
inquire = "0.7.1"
```

\* This prompt type is gated under a feature flag, e.g.:

```
inquire = { version = "0.7.0", features = ["date", "editor"] }
inquire = { version = "0.7.1", features = ["date", "editor"] }
```

[`text`]: https://docs.rs/inquire/*/inquire/prompts/text/struct.Text.html
Expand Down
2 changes: 1 addition & 1 deletion inquire/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "inquire"
version = "0.7.0"
version = "0.7.1"
description = "inquire is a library for building interactive prompts on terminals"
repository = "https://github.com/mikaelmello/inquire"
license = "MIT"
Expand Down
4 changes: 3 additions & 1 deletion inquire/src/prompts/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ where
Key::Enter
| Key::Char('\n', KeyModifiers::NONE)
| Key::Char('j', KeyModifiers::CONTROL) => Some(Action::Submit),
Key::Escape | Key::Char('g', KeyModifiers::CONTROL) => Some(Action::Cancel),
Key::Escape
| Key::Char('g', KeyModifiers::CONTROL)
| Key::Char('d', KeyModifiers::CONTROL) => Some(Action::Cancel),
Key::Char('c', KeyModifiers::CONTROL) => Some(Action::Interrupt),
key => I::from_key(key, config).map(Action::Inner),
}
Expand Down
20 changes: 16 additions & 4 deletions inquire/src/prompts/dateselect/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,22 @@ where

fn handle(&mut self, action: DateSelectPromptAction) -> InquireResult<ActionResult> {
let result = match action {
DateSelectPromptAction::GoToPrevWeek => self.shift_date(Duration::weeks(-1)),
DateSelectPromptAction::GoToNextWeek => self.shift_date(Duration::weeks(1)),
DateSelectPromptAction::GoToPrevDay => self.shift_date(Duration::days(-1)),
DateSelectPromptAction::GoToNextDay => self.shift_date(Duration::days(1)),
DateSelectPromptAction::GoToPrevWeek => self.shift_date(
Duration::try_weeks(-1)
.expect("unexpected overflow when calculating duration of 1 week"),
),
DateSelectPromptAction::GoToNextWeek => self.shift_date(
Duration::try_weeks(1)
.expect("unexpected overflow when calculating duration of 1 week"),
),
DateSelectPromptAction::GoToPrevDay => self.shift_date(
Duration::try_days(-1)
.expect("unexpected overflow when calculating duration of 1 day"),
),
DateSelectPromptAction::GoToNextDay => self.shift_date(
Duration::try_days(1)
.expect("unexpected overflow when calculating duration of 1 day"),
),
DateSelectPromptAction::GoToPrevYear => self.shift_months(-12),
DateSelectPromptAction::GoToNextYear => self.shift_months(12),
DateSelectPromptAction::GoToPrevMonth => self.shift_months(-1),
Expand Down
2 changes: 1 addition & 1 deletion inquire/src/terminal/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Terminal for ConsoleTerminal {
}

fn clear_until_new_line(&mut self) -> Result<()> {
self.term.clear_to_end_of_screen()
write!(self.term, "\x1b[K")
}

fn cursor_hide(&mut self) -> Result<()> {
Expand Down
4 changes: 3 additions & 1 deletion inquire/src/ui/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,9 @@ pub mod date {
let mut date_it = get_start_date(month, year);
// first date of week-line is possibly in the previous month
if date_it.weekday() == week_start {
date_it = date_it.sub(Duration::weeks(1));
date_it = date_it.sub(
Duration::try_weeks(1).expect("overflow when calculating duration of 1 week"),
);
} else {
while date_it.weekday() != week_start {
date_it = match date_it.pred_opt() {
Expand Down
24 changes: 12 additions & 12 deletions inquire/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ where
len
}

impl<'a, T> Debug for Page<'a, T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Page")
.field("first", &self.first)
.field("last", &self.last)
.field("content", &format!("({} elements)", &self.content.len()))
.field("cursor", &self.cursor)
.field("total", &self.total)
.finish()
}
}

#[cfg(test)]
mod test {
#![allow(clippy::bool_assert_comparison)]
Expand Down Expand Up @@ -249,15 +261,3 @@ mod test {
assert_eq!(6, page.total);
}
}

impl<'a, T> Debug for Page<'a, T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Page")
.field("first", &self.first)
.field("last", &self.last)
.field("content", &format!("({} elements)", &self.content.len()))
.field("cursor", &self.cursor)
.field("total", &self.total)
.finish()
}
}

0 comments on commit e1db6ad

Please sign in to comment.