• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

veeso / tui-realm-stdlib / 13283025409

12 Feb 2025 10:15AM UTC coverage: 68.369% (-4.7%) from 73.043%
13283025409

push

github

web-flow
Fix coverage tui (stdlib) (#29)

* chore(workflows/coverage): replace "actions-rs/toolchain" with "dtolnay/rust-toolchain"

* chore(workflows/ratatui): remove unknown option "override"

* chore(workflows/coverage): update "coverallsapp/github-action" to 2.x

* chore(workflows/coverage): replace coverage generation with "cargo-llvm-cov"

3279 of 4796 relevant lines covered (68.37%)

1.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

43.48
/src/components/container.rs
1
//! ## Container
2
//!
3
//! `Container` represents an empty container where you can put other components into it.
4
//! It will render components based on how you defined the layout.
5
//! The way it updates properties is usually assigning the attributes to all the children components, but
6
//! when defining the component you can override these behaviours implementing `attr()` by yourself.
7
//! By default it will forward `Commands' to all the children and will return a `CmdResult::Batch` with all the results.
8

9
use tuirealm::command::{Cmd, CmdResult};
10
use tuirealm::props::{Alignment, AttrValue, Attribute, Borders, Color, Layout, Props};
11
use tuirealm::ratatui::layout::Rect;
12
use tuirealm::{Frame, MockComponent, State};
13

14
// -- Component
15

16
/// ## Container
17
///
18
/// represents a read-only text component without any container.
19
#[derive(Default)]
20
pub struct Container {
21
    props: Props,
22
    /// Container children
23
    pub children: Vec<Box<dyn MockComponent>>,
24
}
25

26
impl Container {
27
    pub fn foreground(mut self, fg: Color) -> Self {
1✔
28
        self.attr(Attribute::Foreground, AttrValue::Color(fg));
1✔
29
        self
1✔
30
    }
1✔
31

32
    pub fn background(mut self, bg: Color) -> Self {
1✔
33
        self.attr(Attribute::Background, AttrValue::Color(bg));
1✔
34
        self
1✔
35
    }
1✔
36

37
    pub fn borders(mut self, b: Borders) -> Self {
×
38
        self.attr(Attribute::Borders, AttrValue::Borders(b));
×
39
        self
×
40
    }
×
41

42
    pub fn title<S: Into<String>>(mut self, t: S, a: Alignment) -> Self {
1✔
43
        self.attr(Attribute::Title, AttrValue::Title((t.into(), a)));
1✔
44
        self
1✔
45
    }
1✔
46

47
    pub fn layout(mut self, layout: Layout) -> Self {
×
48
        self.attr(Attribute::Layout, AttrValue::Layout(layout));
×
49
        self
×
50
    }
×
51

52
    pub fn children(mut self, children: Vec<Box<dyn MockComponent>>) -> Self {
×
53
        self.children = children;
×
54
        self
×
55
    }
×
56
}
57

58
impl MockComponent for Container {
59
    fn view(&mut self, render: &mut Frame, area: Rect) {
×
60
        // Make a Span
×
61
        if self.props.get_or(Attribute::Display, AttrValue::Flag(true)) == AttrValue::Flag(true) {
×
62
            // Make block
63
            let borders = self
×
64
                .props
×
65
                .get_or(Attribute::Borders, AttrValue::Borders(Borders::default()))
×
66
                .unwrap_borders();
×
67
            let title = self.props.get(Attribute::Title).map(|x| x.unwrap_title());
×
68
            let div = crate::utils::get_block(borders, title, true, None);
×
69
            // Render block
×
70
            render.render_widget(div, area);
×
71
            // Render children
72
            if let Some(layout) = self.props.get(Attribute::Layout).map(|x| x.unwrap_layout()) {
×
73
                // make chunks
74
                let chunks = layout.chunks(area);
×
75
                // iter chunks
76
                for (i, chunk) in chunks.into_iter().enumerate() {
×
77
                    if let Some(child) = self.children.get_mut(i) {
×
78
                        child.view(render, chunk);
×
79
                    }
×
80
                }
81
            }
×
82
        }
×
83
    }
×
84

85
    fn query(&self, attr: Attribute) -> Option<AttrValue> {
×
86
        self.props.get(attr)
×
87
    }
×
88

89
    fn attr(&mut self, attr: Attribute, value: AttrValue) {
3✔
90
        self.props.set(attr, value.clone());
3✔
91
        // Patch attribute to children
3✔
92
        self.children
3✔
93
            .iter_mut()
3✔
94
            .for_each(|x| x.attr(attr, value.clone()));
3✔
95
    }
3✔
96

97
    fn state(&self) -> State {
1✔
98
        State::None
1✔
99
    }
1✔
100

101
    fn perform(&mut self, cmd: Cmd) -> CmdResult {
×
102
        // Send command to children and return batch
×
103
        CmdResult::Batch(self.children.iter_mut().map(|x| x.perform(cmd)).collect())
×
104
    }
×
105
}
106

107
#[cfg(test)]
108
mod tests {
109

110
    use super::*;
111

112
    use pretty_assertions::assert_eq;
113

114
    #[test]
115
    fn test_components_paragraph() {
1✔
116
        let component = Container::default()
1✔
117
            .background(Color::Blue)
1✔
118
            .foreground(Color::Red)
1✔
119
            .title("title", Alignment::Center);
1✔
120
        // Get value
1✔
121
        assert_eq!(component.state(), State::None);
1✔
122
    }
1✔
123
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc