WIP: Add partition description

This commit is contained in:
2Shirt 2025-01-15 23:21:42 -08:00
parent 843e46fc86
commit a8597a22a6
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 81 additions and 15 deletions

View file

@ -36,7 +36,7 @@ use crate::{
footer::Footer, fps::FpsCounter, left::Left, popup, right::Right, title::Title, Component,
},
config::Config,
line::{get_disk_description_right, DVLine},
line::{get_disk_description_right, get_part_description, DVLine},
state::{CloneSettings, Mode},
system::{
boot,
@ -105,6 +105,31 @@ impl App {
})
}
pub fn get_boot_part_index(&self) -> usize {
if let Some(index) = self.clone.part_index_boot {
index
} else if let Some(index) = self.selections[0] {
index
} else {
self.cur_index
}
}
pub fn get_os_part_index(&self) -> Option<usize> {
let mut os_part_index = None;
if let Some(index) = self.clone.part_index_os {
os_part_index = Some(index);
} else if let Some(index) = self.selections[1] {
os_part_index = Some(index);
} else if self.list_size > 0 {
// Highlighted entry
if self.cur_index == self.get_boot_part_index() {
os_part_index = Some(self.cur_index);
}
}
os_part_index
}
pub fn get_dest_index(&self) -> Option<usize> {
let mut dest_index = None;
if let Some(index) = self.clone.disk_index_dest {
@ -549,16 +574,16 @@ fn get_chunks(r: Rect) -> Vec<Rect> {
chunks
}
fn get_right_selections(app: &App, prev_mode: Mode, cur_mode: Mode) -> Vec<Vec<DVLine>> {
fn get_right_selections(app: &App, prev_mode: Mode, cur_mode: Mode) -> (usize, Vec<Vec<DVLine>>) {
let mut selections = Vec::new();
// Main header
let mut start_index = 0;
match (prev_mode, cur_mode) {
(_, Mode::InstallDrivers) => {
selections.push(vec![DVLine {
line_parts: vec![String::from("CPU"), get_cpu_name()],
line_colors: vec![Color::Cyan, Color::Reset],
}]);
start_index = 1;
}
(_, Mode::SelectDisks | Mode::SelectTableType)
| (Mode::SelectDisks | Mode::SelectTableType, Mode::Confirm) => {
@ -575,14 +600,13 @@ fn get_right_selections(app: &App, prev_mode: Mode, cur_mode: Mode) -> Vec<Vec<D
if let Some(disk) = disk_list.get(index) {
let mut disk_description = get_disk_description_right(&disk, "Dest");
// Add warning(s)
if app.clone.disk_index_dest.is_some() {
disk_description[0] // i.e. "Dest:"
.line_parts
.push(format!(" (WARNING: ALL DATA WILL BE DELETED!)"));
disk_description[0].line_colors.push(Color::Red);
};
// Add format warning
disk_description[0] // i.e. "Dest:"
.line_parts
.push(format!(" (WARNING: ALL DATA WILL BE DELETED!)"));
disk_description[0].line_colors.push(Color::Red);
if let Some(table_type) = &app.clone.table_type {
// Show table type
let type_str = match table_type {
PartitionTableType::Guid => "GPT",
PartitionTableType::Legacy => "MBR",
@ -599,10 +623,30 @@ fn get_right_selections(app: &App, prev_mode: Mode, cur_mode: Mode) -> Vec<Vec<D
}
}
}
(Mode::SelectParts, Mode::Confirm) => {
//
(_, Mode::SelectParts) | (Mode::SelectParts, Mode::Confirm) => {
if let Some(index) = app.get_dest_index() {
start_index = 1;
let disk_list = app.clone.disk_list.lock().unwrap();
if let Some(disk) = disk_list.get(index) {
// Disk Details
selections.push(get_disk_description_right(&disk, "Disk"));
// Boot Partition
let index = app.get_boot_part_index();
if let Some(part) = disk.parts.get(index) {
selections.push(get_part_description(&part, "Boot"));
}
// OS Partition
if let Some(index) = app.get_os_part_index() {
if let Some(part) = disk.parts.get(index) {
selections.push(get_part_description(&part, "OS"));
}
}
}
}
}
_ => {}
}
selections
(start_index, selections)
}

View file

@ -20,7 +20,7 @@ use ratatui::{
use serde::{Deserialize, Serialize};
use std::iter::zip;
use crate::system::disk::Disk;
use crate::system::disk::{Disk, Partition};
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DVLine {
@ -80,3 +80,25 @@ pub fn get_disk_description_right(disk: &Disk, label: &str) -> Vec<DVLine> {
}
description
}
pub fn get_part_description(part: &Partition, label: &str) -> Vec<DVLine> {
let description: Vec<DVLine> = vec![
DVLine {
line_parts: vec![String::from(label)],
line_colors: vec![Color::Cyan],
},
DVLine::blank(),
DVLine {
line_parts: vec![format!(
"{:<8} {:>11} {:<7} {}",
"Part ID", "Size", "(FS)", "\"Label\""
)],
line_colors: vec![Color::Blue],
},
DVLine {
line_parts: vec![format!("{part}")],
line_colors: vec![Color::Reset],
},
];
description
}