nu_protocol/config/
output.rs1use super::{config_update_string_enum, prelude::*};
2
3use crate::{self as nu_protocol};
4
5#[derive(Clone, Copy, Debug, IntoValue, PartialEq, Eq, Serialize, Deserialize)]
6pub enum ErrorStyle {
7 Plain,
8 Fancy,
9}
10
11impl FromStr for ErrorStyle {
12 type Err = &'static str;
13
14 fn from_str(s: &str) -> Result<Self, Self::Err> {
15 match s.to_ascii_lowercase().as_str() {
16 "fancy" => Ok(Self::Fancy),
17 "plain" => Ok(Self::Plain),
18 _ => Err("'fancy' or 'plain'"),
19 }
20 }
21}
22
23impl UpdateFromValue for ErrorStyle {
24 fn update(&mut self, value: &Value, path: &mut ConfigPath, errors: &mut ConfigErrors) {
25 config_update_string_enum(self, value, path, errors)
26 }
27}
28
29#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
31pub enum BannerKind {
32 None,
34 Short,
36 #[default]
38 Full,
39}
40
41impl IntoValue for BannerKind {
42 fn into_value(self, span: Span) -> Value {
43 match self {
44 BannerKind::None => Value::bool(false, span),
48 BannerKind::Short => Value::string("short", span),
49 BannerKind::Full => Value::bool(true, span),
50 }
51 }
52}
53
54impl UpdateFromValue for BannerKind {
55 fn update<'a>(
56 &mut self,
57 value: &'a Value,
58 path: &mut ConfigPath<'a>,
59 errors: &mut ConfigErrors,
60 ) {
61 match value {
62 Value::Bool { val, .. } => match val {
63 true => {
64 *self = BannerKind::Full;
65 }
66 false => {
67 *self = BannerKind::None;
68 }
69 },
70 Value::String { val, .. } => match val.as_str() {
71 "true" => {
72 *self = BannerKind::Full;
73 }
74 "full" => {
75 *self = BannerKind::Full;
76 }
77 "short" => {
78 *self = BannerKind::Short;
79 }
80 "false" => {
81 *self = BannerKind::None;
82 }
83 "none" => {
84 *self = BannerKind::None;
85 }
86 _ => {
87 errors.invalid_value(path, "true/'full', 'short', false/'none'", value);
88 }
89 },
90 _ => {
91 errors.invalid_value(path, "true/'full', 'short', false/'none'", value);
92 }
93 }
94 }
95}