1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use tty_interface::layout::{InterfaceLayout, SegmentLayout};
use tty_interface::segment::SegmentId;

#[derive(Debug)]
pub struct LayoutAccessor {
    layout: InterfaceLayout,
}

impl LayoutAccessor {
    pub(crate) fn new(layout: InterfaceLayout) -> LayoutAccessor {
        LayoutAccessor { layout }
    }

    pub(crate) fn get_segment(&self, segment_id: SegmentId) -> Option<&SegmentLayout> {
        for line_layout in self.layout.lines() {
            for segment_layout in line_layout.segments() {
                if segment_layout.segment_id() == Some(segment_id) {
                    return Some(segment_layout);
                }
            }
        }

        None
    }
}