morpheus_bootloader/tui/storage_manager/render/
partition_view.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
use super::super::StorageManager;
use crate::tui::renderer::{Screen, EFI_BLACK, EFI_CYAN, EFI_DARKGREEN, EFI_GREEN, EFI_LIGHTGREEN};

impl StorageManager {
    pub(in super::super) fn render_partition_view(&self, screen: &mut Screen) {
        let title = "=== PARTITION VIEW ===";
        screen.put_str_at(
            screen.center_x(title.len()),
            2,
            title,
            EFI_LIGHTGREEN,
            EFI_BLACK,
        );

        let subtitle = "Disk selected - viewing partitions";
        screen.put_str_at(
            screen.center_x(subtitle.len()),
            4,
            subtitle,
            EFI_CYAN,
            EFI_BLACK,
        );

        if !self.partition_table.has_gpt {
            let no_gpt = "GPT: Not detected";
            screen.put_str_at(
                screen.center_x(no_gpt.len()),
                5,
                no_gpt,
                EFI_LIGHTGREEN,
                EFI_BLACK,
            );
            let raw_msg = "Raw block device - no partition table";
            screen.put_str_at(
                screen.center_x(raw_msg.len()),
                7,
                raw_msg,
                EFI_GREEN,
                EFI_BLACK,
            );
            let help = "[C] Create GPT | [ESC] Back to disk list";
            screen.put_str_at(
                screen.center_x(help.len()),
                9,
                help,
                EFI_DARKGREEN,
                EFI_BLACK,
            );
            return;
        }

        let gpt_ok = "GPT: Present";
        screen.put_str_at(
            screen.center_x(gpt_ok.len()),
            5,
            gpt_ok,
            EFI_GREEN,
            EFI_BLACK,
        );

        // Partition table with dynamic centering
        let table_width = 70;
        let table_x = screen.center_x(table_width);
        let table_y = 7;

        screen.put_str_at(table_x, table_y, "IDX", EFI_LIGHTGREEN, EFI_BLACK);
        screen.put_str_at(table_x + 7, table_y, "TYPE", EFI_LIGHTGREEN, EFI_BLACK);
        screen.put_str_at(
            table_x + 25,
            table_y,
            "START LBA",
            EFI_LIGHTGREEN,
            EFI_BLACK,
        );
        screen.put_str_at(table_x + 39, table_y, "END LBA", EFI_LIGHTGREEN, EFI_BLACK);
        screen.put_str_at(
            table_x + 53,
            table_y,
            "SIZE (MB)",
            EFI_LIGHTGREEN,
            EFI_BLACK,
        );

        let separator = "=======================================================================";
        screen.put_str_at(table_x, table_y + 1, separator, EFI_GREEN, EFI_BLACK);

        let mut row_count = 0;

        if self.partition_table.count() == 0 {
            let empty_msg = "(No partitions - press N to create)";
            screen.put_str_at(
                screen.center_x(empty_msg.len()),
                table_y + 3,
                empty_msg,
                EFI_DARKGREEN,
                EFI_BLACK,
            );
        } else {
            for (i, part) in self.partition_table.iter().enumerate() {
                let entry_y = table_y + 2 + i;

                let color = if i == self.selected_partition {
                    EFI_LIGHTGREEN
                } else {
                    EFI_GREEN
                };

                let marker = if i == self.selected_partition {
                    ">"
                } else {
                    " "
                };
                screen.put_str_at(table_x - 2, entry_y, marker, color, EFI_BLACK);

                let mut idx_buf = [0u8; 8];
                let idx_len = Self::format_number(part.index as u64, &mut idx_buf);
                screen.put_str_at(
                    table_x,
                    entry_y,
                    core::str::from_utf8(&idx_buf[..idx_len]).unwrap_or("?"),
                    color,
                    EFI_BLACK,
                );

                screen.put_str_at(table_x + 7, entry_y, part.type_name(), color, EFI_BLACK);

                let mut start_buf = [0u8; 20];
                let start_len = Self::format_number(part.start_lba, &mut start_buf);
                screen.put_str_at(
                    table_x + 25,
                    entry_y,
                    core::str::from_utf8(&start_buf[..start_len]).unwrap_or("?"),
                    color,
                    EFI_BLACK,
                );

                let mut end_buf = [0u8; 20];
                let end_len = Self::format_number(part.end_lba, &mut end_buf);
                screen.put_str_at(
                    table_x + 39,
                    entry_y,
                    core::str::from_utf8(&end_buf[..end_len]).unwrap_or("?"),
                    color,
                    EFI_BLACK,
                );

                let mut size_buf = [0u8; 20];
                let size_len = Self::format_number(part.size_mb(), &mut size_buf);
                screen.put_str_at(
                    table_x + 53,
                    entry_y,
                    core::str::from_utf8(&size_buf[..size_len]).unwrap_or("?"),
                    color,
                    EFI_BLACK,
                );

                row_count = i + 1;
            }
        }

        let status_y = table_y + 2 + row_count + 1;
        let help_text =
            "[UP/DOWN] Navigate | [N] New | [F] Format | [S] Shrink | [D] Delete | [ESC] Back";
        screen.put_str_at(
            screen.center_x(help_text.len()),
            status_y,
            help_text,
            EFI_DARKGREEN,
            EFI_BLACK,
        );

        // Display free space (centered)
        let free_y = status_y + 2;
        let free_label = "Unpartitioned: ";

        if self.free_space_mb > 0 {
            let mut free_buf = [0u8; 20];
            let free_len = Self::format_number(self.free_space_mb, &mut free_buf);
            let free_str = core::str::from_utf8(&free_buf[..free_len]).unwrap_or("?");
            let suffix = " MB available";
            let total_len = free_label.len() + free_str.len() + suffix.len();
            let free_x = screen.center_x(total_len);

            screen.put_str_at(free_x, free_y, free_label, EFI_DARKGREEN, EFI_BLACK);
            screen.put_str_at(
                free_x + free_label.len(),
                free_y,
                free_str,
                EFI_GREEN,
                EFI_BLACK,
            );
            screen.put_str_at(
                free_x + free_label.len() + free_len,
                free_y,
                suffix,
                EFI_DARKGREEN,
                EFI_BLACK,
            );
        } else {
            let full_msg = "Unpartitioned: 0 MB (disk full)";
            screen.put_str_at(
                screen.center_x(full_msg.len()),
                free_y,
                full_msg,
                EFI_DARKGREEN,
                EFI_BLACK,
            );
        }
    }
}