| @@ -11,6 +11,7 @@ use std::process; |
| 11 | use clap::Parser; |
11 | use clap::Parser; |
| 12 | use matrix_sdk::ruma::{OwnedUserId, UserId}; |
12 | use matrix_sdk::ruma::{OwnedUserId, UserId}; |
| 13 | use serde::{de::Error as SerdeError, de::Visitor, Deserialize, Deserializer}; |
13 | use serde::{de::Error as SerdeError, de::Visitor, Deserialize, Deserializer}; |
| |
14 | use tracing::Level; |
| 14 | use url::Url; |
15 | use url::Url; |
| 15 | |
16 | |
| 16 | use modalkit::tui::{ |
17 | use modalkit::tui::{ |
| @@ -108,6 +109,47 @@ pub enum ConfigError { |
| 108 | Invalid(#[from] serde_json::Error), |
109 | Invalid(#[from] serde_json::Error), |
| 109 | } |
110 | } |
| 110 | |
111 | |
| |
112 | #[derive(Clone, Debug, Eq, PartialEq)] |
| |
113 | pub struct LogLevel(pub Level); |
| |
114 | pub struct LogLevelVisitor; |
| |
115 | |
| |
116 | impl From<LogLevel> for Level { |
| |
117 | fn from(level: LogLevel) -> Level { |
| |
118 | level.0 |
| |
119 | } |
| |
120 | } |
| |
121 | |
| |
122 | impl<'de> Visitor<'de> for LogLevelVisitor { |
| |
123 | type Value = LogLevel; |
| |
124 | |
| |
125 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
| |
126 | formatter.write_str("a valid log level (e.g. \"warn\" or \"debug\")") |
| |
127 | } |
| |
128 | |
| |
129 | fn visit_str<E>(self, value: &str) -> Result<Self::Value, E> |
| |
130 | where |
| |
131 | E: SerdeError, |
| |
132 | { |
| |
133 | match value { |
| |
134 | "info" => Ok(LogLevel(Level::INFO)), |
| |
135 | "debug" => Ok(LogLevel(Level::DEBUG)), |
| |
136 | "warn" => Ok(LogLevel(Level::WARN)), |
| |
137 | "error" => Ok(LogLevel(Level::ERROR)), |
| |
138 | "trace" => Ok(LogLevel(Level::TRACE)), |
| |
139 | _ => Err(E::custom("Could not parse log level")), |
| |
140 | } |
| |
141 | } |
| |
142 | } |
| |
143 | |
| |
144 | impl<'de> Deserialize<'de> for LogLevel { |
| |
145 | fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> |
| |
146 | where |
| |
147 | D: Deserializer<'de>, |
| |
148 | { |
| |
149 | deserializer.deserialize_str(LogLevelVisitor) |
| |
150 | } |
| |
151 | } |
| |
152 | |
| 111 | #[derive(Clone, Debug, Eq, PartialEq)] |
153 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 112 | pub struct UserColor(pub Color); |
154 | pub struct UserColor(pub Color); |
| 113 | pub struct UserColorVisitor; |
155 | pub struct UserColorVisitor; |
| @@ -180,6 +222,7 @@ fn merge_users(a: Option<UserOverrides>, b: Option<UserOverrides>) -> Option<Use |
| 180 | |
222 | |
| 181 | #[derive(Clone)] |
223 | #[derive(Clone)] |
| 182 | pub struct TunableValues { |
224 | pub struct TunableValues { |
| |
225 | pub log_level: Level, |
| 183 | pub reaction_display: bool, |
226 | pub reaction_display: bool, |
| 184 | pub reaction_shortcode_display: bool, |
227 | pub reaction_shortcode_display: bool, |
| 185 | pub read_receipt_send: bool, |
228 | pub read_receipt_send: bool, |
| @@ -193,6 +236,7 @@ pub struct TunableValues { |
| 193 | |
236 | |
| 194 | #[derive(Clone, Default, Deserialize)] |
237 | #[derive(Clone, Default, Deserialize)] |
| 195 | pub struct Tunables { |
238 | pub struct Tunables { |
| |
239 | pub log_level: Option<LogLevel>, |
| 196 | pub reaction_display: Option<bool>, |
240 | pub reaction_display: Option<bool>, |
| 197 | pub reaction_shortcode_display: Option<bool>, |
241 | pub reaction_shortcode_display: Option<bool>, |
| 198 | pub read_receipt_send: Option<bool>, |
242 | pub read_receipt_send: Option<bool>, |
| @@ -207,6 +251,7 @@ pub struct Tunables { |
| 207 | impl Tunables { |
251 | impl Tunables { |
| 208 | fn merge(self, other: Self) -> Self { |
252 | fn merge(self, other: Self) -> Self { |
| 209 | Tunables { |
253 | Tunables { |
| |
254 | log_level: self.log_level.or(other.log_level), |
| 210 | reaction_display: self.reaction_display.or(other.reaction_display), |
255 | reaction_display: self.reaction_display.or(other.reaction_display), |
| 211 | reaction_shortcode_display: self |
256 | reaction_shortcode_display: self |
| 212 | .reaction_shortcode_display |
257 | .reaction_shortcode_display |
| @@ -223,6 +268,7 @@ impl Tunables { |
| 223 | |
268 | |
| 224 | fn values(self) -> TunableValues { |
269 | fn values(self) -> TunableValues { |
| 225 | TunableValues { |
270 | TunableValues { |
| |
271 | log_level: self.log_level.map(Level::from).unwrap_or(Level::INFO), |
| 226 | reaction_display: self.reaction_display.unwrap_or(true), |
272 | reaction_display: self.reaction_display.unwrap_or(true), |
| 227 | reaction_shortcode_display: self.reaction_shortcode_display.unwrap_or(false), |
273 | reaction_shortcode_display: self.reaction_shortcode_display.unwrap_or(false), |
| 228 | read_receipt_send: self.read_receipt_send.unwrap_or(true), |
274 | read_receipt_send: self.read_receipt_send.unwrap_or(true), |