rusk_profile/
theme.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4//
5// Copyright (c) DUSK NETWORK. All rights reserved.
6
7use console::Style;
8
9pub struct Theme {
10    success: Style,
11    error: Style,
12    warn: Style,
13    info: Style,
14}
15
16impl Default for Theme {
17    fn default() -> Self {
18        Self::new()
19    }
20}
21
22impl Theme {
23    pub fn new() -> Self {
24        let general = Style::new().bright().bold();
25
26        Self {
27            success: general.clone().green(),
28            error: general.clone().red(),
29            warn: general.clone().yellow(),
30            info: general.cyan(),
31        }
32    }
33    fn fmt(&self, style: &Style, s: impl AsRef<str>) -> String {
34        format!("{:>12}", style.apply_to(s.as_ref()))
35    }
36
37    pub fn success(&self, s: impl AsRef<str>) -> String {
38        self.fmt(&self.success, s)
39    }
40
41    pub fn action(&self, s: impl AsRef<str>) -> String {
42        self.fmt(&self.success, s)
43    }
44
45    pub fn error(&self, s: impl AsRef<str>) -> String {
46        self.fmt(&self.error, s)
47    }
48
49    pub fn warn(&self, s: impl AsRef<str>) -> String {
50        self.fmt(&self.warn, s)
51    }
52
53    pub fn info(&self, s: impl AsRef<str>) -> String {
54        self.fmt(&self.info, s)
55    }
56}