Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mikaelmello/inquire
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.7.0
Choose a base ref
...
head repository: mikaelmello/inquire
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Feb 24, 2024

  1. Fix clippy warning

    mikaelmello committed Feb 24, 2024
    Copy the full SHA
    e04e7d8 View commit details
  2. Copy the full SHA
    62dfcb9 View commit details

Commits on Mar 10, 2024

  1. Copy the full SHA
    eee91f7 View commit details
  2. Fix render issue when using console crate as the terminal backend. (#…

    …230)
    
    * Fix frame rendering when using console crate
    
    * Add changelog entry
    mikaelmello authored Mar 10, 2024
    Copy the full SHA
    5ed6fbe View commit details
  3. chore: release v0.7.1

    mikaelmello committed Mar 10, 2024
    Copy the full SHA
    8eb6046 View commit details

Commits on Mar 13, 2024

  1. Add "Ctrl+D" to list of actions which cancel the current prompt sessi…

    …on (#232)
    
    * add "cntl-D" to list of actions which cancel the current session
    
    * Add changelog entry
    
    ---------
    
    Co-authored-by: Mikael Mello <git@mikaelmello.com>
    mikecvet and mikaelmello authored Mar 13, 2024
    Copy the full SHA
    70ded79 View commit details
  2. Accept h and l in vi mode (#227)

    to clear selection and select all.
    
    Co-authored-by: Mikael Mello <git@mikaelmello.com>
    afh and mikaelmello authored Mar 13, 2024
    Copy the full SHA
    0d04c7d View commit details

Commits on Mar 17, 2024

  1. Fix missing newlines at end of prompts (#234)

    * Fix missing newlines at end of prompts
    
    Fixes #233
    
    * Fix changelog
    mikaelmello authored Mar 17, 2024
    Copy the full SHA
    fdd89ad View commit details
  2. Fix lint warnings

    mikaelmello committed Mar 17, 2024
    Copy the full SHA
    1a5e2f5 View commit details
  3. chore: release v0.7.2

    mikaelmello committed Mar 17, 2024
    Copy the full SHA
    724c7e6 View commit details

Commits on Mar 21, 2024

  1. Copy the full SHA
    8225428 View commit details
  2. chore: release v0.7.3

    mikaelmello committed Mar 21, 2024
    Copy the full SHA
    82ab0e4 View commit details

Commits on Mar 25, 2024

  1. Copy the full SHA
    62ecc2e View commit details
  2. Copy the full SHA
    2b1c882 View commit details
  3. chore: release v0.7.4

    mikaelmello committed Mar 25, 2024
    Copy the full SHA
    4ac91f3 View commit details
  4. Copy the full SHA
    7fe8e5e View commit details

Commits on Apr 23, 2024

  1. Fix ANSI escape codes provided in input from being stripped when rend…

    …ering
    
    Fixes #248
    
    > A recent commit (possibly 8e515d1#diff-546b6385118f60f64674170f786acf59f0ccce53d5d6ad4400409fc8363cfce1R74) has made it so that ANSI escape codes are now stripped. This makes it impossible to have colorised text inside prompt messages, e.g. if you use Confirm with a string that contains color text the color won't show up. This is a regression as this was possible with older versions (at least with 0.5.0).
    mikaelmello committed Apr 23, 2024
    Copy the full SHA
    bf40860 View commit details
  2. Add changelog entry

    mikaelmello committed Apr 23, 2024
    Copy the full SHA
    e3db8d1 View commit details
  3. chore: release v0.7.5

    mikaelmello committed Apr 23, 2024
    Copy the full SHA
    0e39b45 View commit details

Commits on Sep 1, 2024

  1. Copy the full SHA
    c6d2cf8 View commit details

Commits on Sep 29, 2024

  1. Remove unused dependency

    Fix #267
    mikaelmello committed Sep 29, 2024
    Copy the full SHA
    fd977d1 View commit details
  2. Improve changelog message

    mikaelmello committed Sep 29, 2024
    Copy the full SHA
    4856ce8 View commit details
  3. Fix cargo fmt errors

    mikaelmello committed Sep 29, 2024
    Copy the full SHA
    35af303 View commit details
  4. Copy the full SHA
    3cd5d7a View commit details
  5. Fix autocomplete suggestions not being updated after a suggestion is …

    …accepted
    
    Co-authored-by: Ilia <istudyatuni@gmail.com>
    Co-authored-by: Moritz Hölting <moritz@hoelting.dev>
    3 people committed Sep 29, 2024
    Copy the full SHA
    398ea88 View commit details
  6. Copy the full SHA
    a896bac View commit details
  7. Fix typo in readme

    Closes #244
    mikaelmello committed Sep 29, 2024
    Copy the full SHA
    080b115 View commit details
  8. Fix lint warnings

    mikaelmello committed Sep 29, 2024
    Copy the full SHA
    446ce3d View commit details

Commits on Jan 4, 2025

  1. Copy the full SHA
    aea4e60 View commit details
37 changes: 35 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,35 @@

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

- No changes since the latest release below.
- Fix autocomplete suggestions not being updated after a suggestion is accepted. Thanks @moritz-hoelting and @istudyatuni for reporting and fixing it!
- Fix incorrect cursor placement when inputting CJK characters. Thanks @phostann (#270) for reporting it!
- Removed unused dependency (newline-converter). Thanks @jonassmedegaard (#267) for catching it!

## [0.7.5] - 2024-04-23

- Fix user-provided ANSI escape codes from being removed when rendering.
- Introduced on 0.7.0, this regression was making it impossible to have colorised text inside the prompt.
- Now ANSI escape codes are properly emitted when rendering the prompt in the terminal.

## [0.7.4] - 2024-03-25

- Fix unexpected behaviors of `keep_filter` option in MultiSelect prompts:
- Filter input is now correcly getting reset **only when** `keep_filter == false`.
- When the filter input is reset, the list of options is now correctly reset as well. Thanks @Swivelgames for reporting [#238](https://github.com/mikaelmello/inquire/issues/238).

## [0.7.3] - 2024-03-21

- Fix cursor occasionally blinking in unexpected places.

## [0.7.2] - 2024-03-17

- Pressing Ctrl+D now cancels the prompt. Thanks @mikecvet for the PR!
- Add support for `h` and `l` bindings when vim_mode is enabled on MultiSelect prompts, clearing or selecting all options respectively. Thanks @afh for the PR!
- Fix render issue [#233](https://github.com/mikaelmello/inquire/issues/233) where cursor positioning at the end of a prompt was incorrect. Thanks @msrd0 and @Sydonian for reporting!

## [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 +330,12 @@ 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.5...HEAD
[0.7.5]: https://github.com/mikaelmello/inquire/compare/v0.7.4...v0.7.5
[0.7.4]: https://github.com/mikaelmello/inquire/compare/v0.7.3...v0.7.4
[0.7.3]: https://github.com/mikaelmello/inquire/compare/v0.7.2...v0.7.3
[0.7.2]: https://github.com/mikaelmello/inquire/compare/v0.7.1...v0.7.2
[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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.5"
```

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

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

# Cross-cutting concerns
@@ -118,20 +118,20 @@ If you'd like to see more examples, the [`date.rs`](./inquire/examples/date.rs)

## Terminal Back-end

Currently, there are like 3 major libraries to manipulate terminals: [crossterm](https://lib.rs/crates/crossterm), [console](https://lib.rs/crates/console) and [termion](https://lib.rs/crates/crossterm).
Currently, there are like 3 major libraries to manipulate terminals: [crossterm](https://lib.rs/crates/crossterm), [console](https://lib.rs/crates/console) and [termion](https://lib.rs/crates/termion).

Binary Rust applications that intend to manipulate terminals will probably pick any one of these 3 to power underlying abstractions. `inquire` chose to support crossterm by default in order to support many features on Windows out-of-the-box.

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.5", default-features = false, features = ["termion", "date"] }
```

or this:

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

## Formatting
8 changes: 4 additions & 4 deletions inquire-derive/CRATE_README.md
Original file line number Diff line number Diff line change
@@ -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.5"
inquire-derive = "0.7.5"
```

```
inquire = { version = "0.7.0", features = ["date", "editor"] }
inquire-derive = { version = "0.7.0" }
inquire = { version = "0.7.5", features = ["date", "editor"] }
inquire-derive = { version = "0.7.5" }
```
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.5"
description = "" # TODO
publish = false # TODO
repository = "https://github.com/mikaelmello/inquire"
4 changes: 2 additions & 2 deletions inquire/CRATE_README.md
Original file line number Diff line number Diff line change
@@ -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.5"
```

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

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

[`text`]: https://docs.rs/inquire/*/inquire/prompts/text/struct.Text.html
3 changes: 1 addition & 2 deletions 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.5"
description = "inquire is a library for building interactive prompts on terminals"
repository = "https://github.com/mikaelmello/inquire"
license = "MIT"
@@ -46,7 +46,6 @@ fuzzy-matcher = { version = "0.3.7", default-features = false, optional = true }

bitflags = "2"
dyn-clone = "1"
newline-converter = "0.3"
once_cell = "1.18.0"
unicode-segmentation = "1"
unicode-width = "0.1"
69 changes: 28 additions & 41 deletions inquire/examples/complex_autocompletion.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::io::ErrorKind;

use fuzzy_matcher::skim::SkimMatcherV2;
use fuzzy_matcher::FuzzyMatcher;
use inquire::{
autocompletion::{Autocomplete, Replacement},
CustomUserError, Text,
@@ -29,12 +31,11 @@ fn main() {
pub struct FilePathCompleter {
input: String,
paths: Vec<String>,
lcp: String,
}

impl FilePathCompleter {
fn update_input(&mut self, input: &str) -> Result<(), CustomUserError> {
if input == self.input {
if input == self.input && !self.paths.is_empty() {
return Ok(());
}

@@ -67,59 +68,43 @@ impl FilePathCompleter {
}?
.collect::<Result<Vec<_>, _>>()?;

let mut idx = 0;
let limit = 15;

while idx < entries.len() && self.paths.len() < limit {
let entry = entries.get(idx).unwrap();

for entry in entries {
let path = entry.path();
let path_str = if path.is_dir() {
format!("{}/", path.to_string_lossy())
} else {
path.to_string_lossy().to_string()
};

if path_str.starts_with(&self.input) && path_str.len() != self.input.len() {
self.paths.push(path_str);
}

idx = idx.saturating_add(1);
self.paths.push(path_str);
}

self.lcp = self.longest_common_prefix();

Ok(())
}

fn longest_common_prefix(&self) -> String {
let mut ret: String = String::new();

let mut sorted = self.paths.clone();
sorted.sort();
if sorted.is_empty() {
return ret;
}

let mut first_word = sorted.first().unwrap().chars();
let mut last_word = sorted.last().unwrap().chars();
fn fuzzy_sort(&self, input: &str) -> Vec<(String, i64)> {
let mut matches: Vec<(String, i64)> = self
.paths
.iter()
.filter_map(|path| {
SkimMatcherV2::default()
.smart_case()
.fuzzy_match(path, input)
.map(|score| (path.clone(), score))
})
.collect();

loop {
match (first_word.next(), last_word.next()) {
(Some(c1), Some(c2)) if c1 == c2 => {
ret.push(c1);
}
_ => return ret,
}
}
matches.sort_by(|a, b| b.1.cmp(&a.1));
matches
}
}

impl Autocomplete for FilePathCompleter {
fn get_suggestions(&mut self, input: &str) -> Result<Vec<String>, CustomUserError> {
self.update_input(input)?;

Ok(self.paths.clone())
let matches = self.fuzzy_sort(input);
Ok(matches.into_iter().take(15).map(|(path, _)| path).collect())
}

fn get_completion(
@@ -129,12 +114,14 @@ impl Autocomplete for FilePathCompleter {
) -> Result<Replacement, CustomUserError> {
self.update_input(input)?;

Ok(match highlighted_suggestion {
Some(suggestion) => Replacement::Some(suggestion),
None => match self.lcp.is_empty() {
true => Replacement::None,
false => Replacement::Some(self.lcp.clone()),
},
Ok(if let Some(suggestion) = highlighted_suggestion {
Replacement::Some(suggestion)
} else {
let matches = self.fuzzy_sort(input);
matches
.first()
.map(|(path, _)| Replacement::Some(path.clone()))
.unwrap_or(Replacement::None)
})
}
}
16 changes: 8 additions & 8 deletions inquire/examples/confirm.rs
Original file line number Diff line number Diff line change
@@ -19,21 +19,21 @@ fn main() {
message: "Are you happy?",
starting_input: None,
default: Some(false),
placeholder: Some("si|no"),
placeholder: Some("sim|não"),
help_message: Some("It's alright if you're not"),
formatter: &|ans| match ans {
true => "si".to_owned(),
false => "no".to_owned(),
true => "sim".to_owned(),
false => "não".to_owned(),
},
parser: &|ans| match ans {
"si" => Ok(true),
"no" => Ok(false),
"sim" => Ok(true),
"não" => Ok(false),
_ => Err(()),
},
error_message: "Reply with 'si' or 'no'".into(),
error_message: "Reply with 'sim' or 'não'".into(),
default_value_formatter: &|def| match def {
true => String::from("si"),
false => String::from("no"),
true => String::from("sim"),
false => String::from("não"),
},
render_config: RenderConfig::default(),
}
1 change: 1 addition & 0 deletions inquire/src/ansi.rs
Original file line number Diff line number Diff line change
@@ -165,6 +165,7 @@ impl<'a> Iterator for AnsiStrippedChars<'a> {

/// Constructs an iterator over the chars of the input string, stripping away ANSI escape codes.
pub trait AnsiStrippable {
#[allow(unused)]
fn ansi_stripped_chars(&self) -> AnsiStrippedChars<'_>;
}

12 changes: 6 additions & 6 deletions inquire/src/date_utils.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ pub fn get_current_date() -> NaiveDate {
}

pub fn get_start_date(month: chrono::Month, year: i32) -> NaiveDate {
chrono::NaiveDate::from_ymd_opt(year, month.number_from_month(), 1).unwrap()
NaiveDate::from_ymd_opt(year, month.number_from_month(), 1).unwrap()
}

pub fn get_month(month: u32) -> chrono::Month {
@@ -43,23 +43,23 @@ mod tests {
fn test_get_start_date() {
assert_eq!(
get_start_date(chrono::Month::January, 2021),
chrono::NaiveDate::from_ymd_opt(2021, 1, 1).unwrap()
NaiveDate::from_ymd_opt(2021, 1, 1).unwrap()
);
assert_eq!(
get_start_date(chrono::Month::February, 2021),
chrono::NaiveDate::from_ymd_opt(2021, 2, 1).unwrap()
NaiveDate::from_ymd_opt(2021, 2, 1).unwrap()
);
assert_eq!(
get_start_date(chrono::Month::March, 2021),
chrono::NaiveDate::from_ymd_opt(2021, 3, 1).unwrap()
NaiveDate::from_ymd_opt(2021, 3, 1).unwrap()
);
assert_eq!(
get_start_date(chrono::Month::December, 1883),
chrono::NaiveDate::from_ymd_opt(1883, 12, 1).unwrap()
NaiveDate::from_ymd_opt(1883, 12, 1).unwrap()
);
assert_eq!(
get_start_date(chrono::Month::June, 3042),
chrono::NaiveDate::from_ymd_opt(3042, 6, 1).unwrap()
NaiveDate::from_ymd_opt(3042, 6, 1).unwrap()
);
}

20 changes: 20 additions & 0 deletions inquire/src/input/test.rs
Original file line number Diff line number Diff line change
@@ -114,6 +114,17 @@ fn new_with_content_is_correctly_initialized() {
let input = Input::new_with(content);
assert_eq!(11, input.length());
assert_eq!(11, input.cursor());
assert_eq!("great idea!", input.pre_cursor());
assert_eq!(content, input.content());
}

#[test]
fn new_with_chinese_content_is_correctly_initialized() {
let content = "请输";
let input = Input::new_with(content);
assert_eq!(2, input.length());
assert_eq!(2, input.cursor());
assert_eq!("请输", input.pre_cursor());
assert_eq!(content, input.content());
}

@@ -138,6 +149,15 @@ fn with_cursor_is_correctly_initialized() {
assert_eq!("great i", input.pre_cursor());
}

#[test]
fn chinese_with_cursor_is_correctly_initialized() {
let input = Input::new_with("请输入").with_cursor(1);
assert_eq!(3, input.length());
assert_eq!(1, input.cursor());
assert_eq!("请输入", input.content());
assert_eq!("请", input.pre_cursor());
}

#[test]
fn with_placeholder_is_correctly_initialized() {
let input = Input::new_with("great idea!").with_placeholder("placeholder");
1 change: 1 addition & 0 deletions inquire/src/lib.rs
Original file line number Diff line number Diff line change
@@ -63,6 +63,7 @@
//! [`Editor`]: crate::Editor
#![warn(missing_docs)]
#![deny(unused_crate_dependencies)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![allow(clippy::bool_to_int_with_if)]
mod ansi;
2 changes: 1 addition & 1 deletion inquire/src/prompts/action.rs
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ 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' | 'd', KeyModifiers::CONTROL) => Some(Action::Cancel),
Key::Char('c', KeyModifiers::CONTROL) => Some(Action::Interrupt),
key => I::from_key(key, config).map(Action::Inner),
}
Loading