Skip to main content

fpv/app/
status.rs

1use crate::app::navigation_result::{ActionOutcome, NavigationActionResult};
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub enum StatusLevel {
5    Info,
6    Warning,
7    Error,
8}
9
10#[derive(Debug, Clone)]
11pub struct StatusMessage {
12    pub level: StatusLevel,
13    pub text: String,
14}
15
16impl StatusMessage {
17    pub fn info(text: impl Into<String>) -> Self {
18        Self {
19            level: StatusLevel::Info,
20            text: text.into(),
21        }
22    }
23
24    pub fn warning(text: impl Into<String>) -> Self {
25        Self {
26            level: StatusLevel::Warning,
27            text: text.into(),
28        }
29    }
30
31    pub fn error(text: impl Into<String>) -> Self {
32        Self {
33            level: StatusLevel::Error,
34            text: text.into(),
35        }
36    }
37}
38
39pub fn navigation_status_message(result: &NavigationActionResult) -> String {
40    match result.outcome {
41        ActionOutcome::Changed => result.message.to_string(),
42        ActionOutcome::Blocked | ActionOutcome::NoChange => result.message.to_string(),
43    }
44}