television_screen/
metadata.rs

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
use std::fmt::Display;

use crate::{
    colors::Colorscheme,
    mode::{mode_color, Mode},
};
use ratatui::{
    layout::Constraint,
    style::Style,
    text::Span,
    widgets::{Cell, Row, Table},
};
use television_channels::channels::UnitChannel;
use television_utils::metadata::AppMetadata;

impl Display for Mode {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Mode::Channel => write!(f, "Channel"),
            Mode::RemoteControl => write!(f, "Remote Control"),
            Mode::SendToChannel => write!(f, "Send to Channel"),
        }
    }
}

pub fn build_metadata_table<'a>(
    mode: Mode,
    current_channel: UnitChannel,
    app_metadata: &'a AppMetadata,
    colorscheme: &'a Colorscheme,
) -> Table<'a> {
    let version_row = Row::new(vec![
        Cell::from(Span::styled(
            "version: ",
            Style::default().fg(colorscheme.help.metadata_field_name_fg),
        )),
        Cell::from(Span::styled(
            &app_metadata.version,
            Style::default().fg(colorscheme.help.metadata_field_value_fg),
        )),
    ]);

    let target_triple_row = Row::new(vec![
        Cell::from(Span::styled(
            "target triple: ",
            Style::default().fg(colorscheme.help.metadata_field_name_fg),
        )),
        Cell::from(Span::styled(
            &app_metadata.build.target_triple,
            Style::default().fg(colorscheme.help.metadata_field_value_fg),
        )),
    ]);

    let build_row = Row::new(vec![
        Cell::from(Span::styled(
            "build: ",
            Style::default().fg(colorscheme.help.metadata_field_name_fg),
        )),
        Cell::from(Span::styled(
            &app_metadata.build.rustc_version,
            Style::default().fg(colorscheme.help.metadata_field_value_fg),
        )),
        Cell::from(Span::styled(
            " (",
            Style::default().fg(colorscheme.help.metadata_field_name_fg),
        )),
        Cell::from(Span::styled(
            &app_metadata.build.build_date,
            Style::default().fg(colorscheme.help.metadata_field_value_fg),
        )),
        Cell::from(Span::styled(
            ")",
            Style::default().fg(colorscheme.help.metadata_field_name_fg),
        )),
    ]);

    let current_dir_row = Row::new(vec![
        Cell::from(Span::styled(
            "current directory: ",
            Style::default().fg(colorscheme.help.metadata_field_name_fg),
        )),
        Cell::from(Span::styled(
            std::env::current_dir()
                .expect("Could not get current directory")
                .display()
                .to_string(),
            Style::default().fg(colorscheme.help.metadata_field_value_fg),
        )),
    ]);

    let current_channel_row = Row::new(vec![
        Cell::from(Span::styled(
            "current channel: ",
            Style::default().fg(colorscheme.help.metadata_field_name_fg),
        )),
        Cell::from(Span::styled(
            current_channel.to_string(),
            Style::default().fg(colorscheme.help.metadata_field_value_fg),
        )),
    ]);

    let current_mode_row = Row::new(vec![
        Cell::from(Span::styled(
            "current mode: ",
            Style::default().fg(colorscheme.help.metadata_field_name_fg),
        )),
        Cell::from(Span::styled(
            mode.to_string(),
            Style::default().fg(mode_color(mode, &colorscheme.mode)),
        )),
    ]);

    let widths = vec![Constraint::Fill(1), Constraint::Fill(2)];

    Table::new(
        vec![
            version_row,
            target_triple_row,
            build_row,
            current_dir_row,
            current_channel_row,
            current_mode_row,
        ],
        widths,
    )
}