-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prompts): implement
number
prompt, slightly restructure
- Loading branch information
Showing
9 changed files
with
152 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
pub use config::*; | ||
pub use utils::*; | ||
pub use value::*; | ||
|
||
pub mod actions; | ||
pub mod prompts; | ||
pub mod value; | ||
|
||
mod config; | ||
mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::fmt::{self, Display}; | ||
use std::str::FromStr; | ||
|
||
use miette::Diagnostic; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Diagnostic, Error)] | ||
#[error("`{0}` is not a valid number.")] | ||
#[diagnostic(code(arx::config::prompts::parse))] | ||
pub struct NumberParseError(pub String); | ||
|
||
/// Value of a number prompt. | ||
#[derive(Clone, Debug)] | ||
pub enum Number { | ||
/// Integer value. | ||
Integer(i64), | ||
/// Floating point value. | ||
Float(f64), | ||
} | ||
|
||
impl Display for Number { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
| Self::Integer(int) => write!(f, "{int}"), | ||
| Self::Float(float) => write!(f, "{float}"), | ||
} | ||
} | ||
} | ||
|
||
impl FromStr for Number { | ||
type Err = NumberParseError; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
s.parse::<i64>() | ||
.map(Self::Integer) | ||
.or_else(|_| s.parse::<f64>().map(Self::Float)) | ||
.map_err(|_| NumberParseError(s.to_string())) | ||
} | ||
} | ||
|
||
/// Replacement value. | ||
#[derive(Debug)] | ||
pub enum Value { | ||
/// A string value. | ||
String(String), | ||
// A number value. | ||
Number(Number), | ||
/// A boolean value. | ||
Bool(bool), | ||
} |