WIP: Add partition description
This commit is contained in:
parent
843e46fc86
commit
a8597a22a6
2 changed files with 81 additions and 15 deletions
|
|
@ -36,7 +36,7 @@ use crate::{
|
||||||
footer::Footer, fps::FpsCounter, left::Left, popup, right::Right, title::Title, Component,
|
footer::Footer, fps::FpsCounter, left::Left, popup, right::Right, title::Title, Component,
|
||||||
},
|
},
|
||||||
config::Config,
|
config::Config,
|
||||||
line::{get_disk_description_right, DVLine},
|
line::{get_disk_description_right, get_part_description, DVLine},
|
||||||
state::{CloneSettings, Mode},
|
state::{CloneSettings, Mode},
|
||||||
system::{
|
system::{
|
||||||
boot,
|
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> {
|
pub fn get_dest_index(&self) -> Option<usize> {
|
||||||
let mut dest_index = None;
|
let mut dest_index = None;
|
||||||
if let Some(index) = self.clone.disk_index_dest {
|
if let Some(index) = self.clone.disk_index_dest {
|
||||||
|
|
@ -549,16 +574,16 @@ fn get_chunks(r: Rect) -> Vec<Rect> {
|
||||||
chunks
|
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();
|
let mut selections = Vec::new();
|
||||||
|
let mut start_index = 0;
|
||||||
// Main header
|
|
||||||
match (prev_mode, cur_mode) {
|
match (prev_mode, cur_mode) {
|
||||||
(_, Mode::InstallDrivers) => {
|
(_, Mode::InstallDrivers) => {
|
||||||
selections.push(vec![DVLine {
|
selections.push(vec![DVLine {
|
||||||
line_parts: vec![String::from("CPU"), get_cpu_name()],
|
line_parts: vec![String::from("CPU"), get_cpu_name()],
|
||||||
line_colors: vec![Color::Cyan, Color::Reset],
|
line_colors: vec![Color::Cyan, Color::Reset],
|
||||||
}]);
|
}]);
|
||||||
|
start_index = 1;
|
||||||
}
|
}
|
||||||
(_, Mode::SelectDisks | Mode::SelectTableType)
|
(_, Mode::SelectDisks | Mode::SelectTableType)
|
||||||
| (Mode::SelectDisks | Mode::SelectTableType, Mode::Confirm) => {
|
| (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) {
|
if let Some(disk) = disk_list.get(index) {
|
||||||
let mut disk_description = get_disk_description_right(&disk, "Dest");
|
let mut disk_description = get_disk_description_right(&disk, "Dest");
|
||||||
|
|
||||||
// Add warning(s)
|
// Add format warning
|
||||||
if app.clone.disk_index_dest.is_some() {
|
disk_description[0] // i.e. "Dest:"
|
||||||
disk_description[0] // i.e. "Dest:"
|
.line_parts
|
||||||
.line_parts
|
.push(format!(" (WARNING: ALL DATA WILL BE DELETED!)"));
|
||||||
.push(format!(" (WARNING: ALL DATA WILL BE DELETED!)"));
|
disk_description[0].line_colors.push(Color::Red);
|
||||||
disk_description[0].line_colors.push(Color::Red);
|
|
||||||
};
|
|
||||||
if let Some(table_type) = &app.clone.table_type {
|
if let Some(table_type) = &app.clone.table_type {
|
||||||
|
// Show table type
|
||||||
let type_str = match table_type {
|
let type_str = match table_type {
|
||||||
PartitionTableType::Guid => "GPT",
|
PartitionTableType::Guid => "GPT",
|
||||||
PartitionTableType::Legacy => "MBR",
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ use ratatui::{
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::iter::zip;
|
use std::iter::zip;
|
||||||
|
|
||||||
use crate::system::disk::Disk;
|
use crate::system::disk::{Disk, Partition};
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct DVLine {
|
pub struct DVLine {
|
||||||
|
|
@ -80,3 +80,25 @@ pub fn get_disk_description_right(disk: &Disk, label: &str) -> Vec<DVLine> {
|
||||||
}
|
}
|
||||||
description
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue