From eee91f7a53aef29ece9d29ca94f2d762b58cd919 Mon Sep 17 00:00:00 2001 From: Mikael Mello Date: Sun, 10 Mar 2024 16:31:25 -0700 Subject: [PATCH 1/4] Solve linting warnings (#231) --- inquire/src/prompts/dateselect/prompt.rs | 20 ++++++++++++++++---- inquire/src/ui/backend.rs | 4 +++- inquire/src/utils.rs | 24 ++++++++++++------------ 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/inquire/src/prompts/dateselect/prompt.rs b/inquire/src/prompts/dateselect/prompt.rs index cf968710..70543b0f 100644 --- a/inquire/src/prompts/dateselect/prompt.rs +++ b/inquire/src/prompts/dateselect/prompt.rs @@ -145,10 +145,22 @@ where fn handle(&mut self, action: DateSelectPromptAction) -> InquireResult { 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), diff --git a/inquire/src/ui/backend.rs b/inquire/src/ui/backend.rs index e84c7596..a6baf917 100644 --- a/inquire/src/ui/backend.rs +++ b/inquire/src/ui/backend.rs @@ -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() { diff --git a/inquire/src/utils.rs b/inquire/src/utils.rs index d366d033..61d8b9d4 100644 --- a/inquire/src/utils.rs +++ b/inquire/src/utils.rs @@ -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)] @@ -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() - } -} From 5ed6fbe7a08b0b23e74bbe260d1ee71e6caafb69 Mon Sep 17 00:00:00 2001 From: Mikael Mello Date: Sun, 10 Mar 2024 16:35:16 -0700 Subject: [PATCH 2/4] Fix render issue when using `console` crate as the terminal backend. (#230) * Fix frame rendering when using console crate * Add changelog entry --- CHANGELOG.md | 2 +- inquire/src/terminal/console.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9997cfe9..a7e986dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ## [Unreleased] -- No changes since the latest release below. +- 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 diff --git a/inquire/src/terminal/console.rs b/inquire/src/terminal/console.rs index 7def0731..1c56c487 100644 --- a/inquire/src/terminal/console.rs +++ b/inquire/src/terminal/console.rs @@ -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<()> { From 8eb60467010f046adb7ae618a8587c5a9155d980 Mon Sep 17 00:00:00 2001 From: Mikael Mello Date: Sun, 10 Mar 2024 16:48:05 -0700 Subject: [PATCH 3/4] chore: release v0.7.1 --- CHANGELOG.md | 7 ++++++- README.md | 8 ++++---- inquire-derive/CRATE_README.md | 8 ++++---- inquire-derive/Cargo.toml | 2 +- inquire/CRATE_README.md | 4 ++-- inquire/Cargo.toml | 2 +- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7e986dd..36b65d92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ## [Unreleased] +- No changes since the latest release below. + +## [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 @@ -302,7 +306,8 @@ The library is already featureful enough to warrant a higher version number, bum -[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 diff --git a/README.md b/README.md index 586f8aa3..0cfbf119 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/inquire-derive/CRATE_README.md b/inquire-derive/CRATE_README.md index 058af484..e921d355 100644 --- a/inquire-derive/CRATE_README.md +++ b/inquire-derive/CRATE_README.md @@ -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" } ``` diff --git a/inquire-derive/Cargo.toml b/inquire-derive/Cargo.toml index b695b9a9..cc74ec03 100644 --- a/inquire-derive/Cargo.toml +++ b/inquire-derive/Cargo.toml @@ -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" diff --git a/inquire/CRATE_README.md b/inquire/CRATE_README.md index 568f4ba3..aefe453e 100644 --- a/inquire/CRATE_README.md +++ b/inquire/CRATE_README.md @@ -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 diff --git a/inquire/Cargo.toml b/inquire/Cargo.toml index 3345e9c3..34560f09 100644 --- a/inquire/Cargo.toml +++ b/inquire/Cargo.toml @@ -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" From 70ded79dc1a54640f5d928d1aaef84af81eb1886 Mon Sep 17 00:00:00 2001 From: Mike Cvet Date: Tue, 12 Mar 2024 22:41:30 -0700 Subject: [PATCH 4/4] Add "Ctrl+D" to list of actions which cancel the current prompt session (#232) * add "cntl-D" to list of actions which cancel the current session * Add changelog entry --------- Co-authored-by: Mikael Mello --- CHANGELOG.md | 2 +- inquire/src/prompts/action.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36b65d92..defff12b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ## [Unreleased] -- No changes since the latest release below. +- Pressing Ctrl+D now cancels the prompt. ## [0.7.1] - 2024-03-10 diff --git a/inquire/src/prompts/action.rs b/inquire/src/prompts/action.rs index dde0d74c..907545da 100644 --- a/inquire/src/prompts/action.rs +++ b/inquire/src/prompts/action.rs @@ -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), }