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

Add shorthand method for creating a Color from RGB components #73

Merged
merged 2 commits into from
Sep 12, 2022
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
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Changelog

<!-- next-header -->

## [Unreleased] - ReleaseDate

- Add shorthand method `rgb(r: u8, g: u8, b: u8)` to create a `Color` struct from RGB components. Thanks to @tpoliaw for the PR! [#73](https://github.com/mikaelmello/inquire/pull/73)

## [0.3.0] - 2022-08-19

### Breaking Changes
Expand Down Expand Up @@ -39,7 +42,7 @@ Input validation, suggestions and completions are now fallible operations.

The return type of validators has been changed to `Result<Validation, CustomUserError>`. This means that validating the input can now be a fallible operation. The docs contain more thorough explanations and full-featured examples.

- Successful executions of the validator should return a variant of the `Validation` enum, which can be either `Valid` or `Invalid(ErrorMessage)`.
- Successful executions of the validator should return a variant of the `Validation` enum, which can be either `Valid` or `Invalid(ErrorMessage)`.
- Unsuccessful executions return a `CustomUserError` type, which is an alias for `Box<dyn std::error::Error + Send + Sync + 'static>`.

The return type of suggesters has also been changed to allow fallible executions. The return type in successful executions continues to be `Vec<String>`, while `CustomUserError` is used with errors.
Expand Down Expand Up @@ -193,7 +196,8 @@ The library is already featureful enough to warrant a higher version number, bum
- Add DateSelect prompt

<!-- next-url -->
[Unreleased]: https://github.com/mikaelmello/inquire/compare/v0.3.0...HEAD

[unreleased]: https://github.com/mikaelmello/inquire/compare/v0.3.0...HEAD
[unreleased]: https://github.com/mikaelmello/inquire/compare/v0.2.1...v0.3.0
[0.2.1]: https://github.com/mikaelmello/inquire/compare/v0.2.0...v0.2.1
[0.2.0]: https://github.com/mikaelmello/inquire/compare/v0.1.0...v0.2.0
Expand Down
13 changes: 13 additions & 0 deletions src/ui/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,16 @@ pub enum Color {
/// Supported on all terminal back-ends: `crossterm`, `termion` and `console`.
AnsiValue(u8),
}

impl Color {
/// Shorthand method for creating a Color from RGB components
///
/// ```
/// # use inquire::ui::Color;
///
/// assert_eq!(Color::rgb(42, 17, 97), Color::Rgb { r: 42, g: 17, b: 97 });
/// ```
pub fn rgb(r: u8, g: u8, b: u8) -> Color {
Color::Rgb { r, g, b }
}
}