Skip to content

Commit

Permalink
accept true/false for boolean variables
Browse files Browse the repository at this point in the history
  • Loading branch information
nn1ks committed Jun 26, 2020
1 parent 9651319 commit 61451e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ end
- A ANSII number (e.g. `1` for red)
- A hex color beginning with `#` (e.g. `#00F` or `#0000FF` for blue)

- **`Boolean`**: Takes either `0` (deactivate setting) or `1` (activate setting) as value
- **`Boolean`**: Takes either `0`/`false` (deactivate setting) or `1`/`true` (activate setting) as value

- **`String`**: Takes any value

Expand Down Expand Up @@ -95,7 +95,7 @@ end

Disables the git branch and icon.

Type: `Boolean`, Default: `0`
Type: `Boolean`, Default: `false`

- **`MSHP_GIT_STATUS_STAGED_ICON`**

Expand Down Expand Up @@ -137,7 +137,7 @@ end

Disables the above mentioned icons.

Type: `Boolean`, Default: `0`
Type: `Boolean`, Default: `false`

- **`MSHP_USER_INDICATOR`**

Expand Down
12 changes: 8 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ impl Default for Config {

fn deserialize_bool<'de, D: Deserializer<'de>>(deserializer: D) -> Result<bool, D::Error> {
let string = String::deserialize(deserializer)?;
Ok(match string.as_ref() {
"1" => true,
_ => false,
})
match string.as_ref() {
"0" | "false" => Ok(false),
"1" | "true" => Ok(true),
other => Err(D::Error::invalid_value(
Unexpected::Str(other),
&"either `0`, `false`, `1`, or `true`",
)),
}
}

fn deserialize_color<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Color, D::Error> {
Expand Down

0 comments on commit 61451e8

Please sign in to comment.