WIP
This commit is contained in:
parent
86b1f34330
commit
2abd6c6582
2 changed files with 105 additions and 55 deletions
|
|
@ -36,7 +36,7 @@ use crate::{
|
|||
footer::Footer, fps::FpsCounter, left::Left, popup, right::Right, title::Title, Component,
|
||||
},
|
||||
config::Config,
|
||||
line::DVLine,
|
||||
line::{get_disk_description_right, DVLine},
|
||||
state::{CloneSettings, Mode},
|
||||
system::{
|
||||
boot,
|
||||
|
|
@ -104,6 +104,40 @@ impl App {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn get_dest_index(&self) -> Option<usize> {
|
||||
let mut dest_index = None;
|
||||
if let Some(index) = self.clone.disk_index_dest {
|
||||
// Selected in prior mode
|
||||
dest_index = Some(index);
|
||||
} else if let Some(index) = self.selections[1] {
|
||||
// Selected in this mode
|
||||
dest_index = Some(index);
|
||||
} else if self.list_size > 0 {
|
||||
// Highlighted entry
|
||||
if let Some(source_index) = self.get_source_index() {
|
||||
if self.cur_index == source_index {
|
||||
dest_index = Some(self.cur_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
dest_index
|
||||
}
|
||||
|
||||
pub fn get_source_index(&self) -> Option<usize> {
|
||||
let mut source_index = None;
|
||||
if let Some(index) = self.clone.disk_index_source {
|
||||
// Selected in prior mode
|
||||
source_index = Some(index);
|
||||
} else if let Some(index) = self.selections[0] {
|
||||
// Selected in this mode
|
||||
source_index = Some(index);
|
||||
} else if self.list_size > 0 {
|
||||
// Highlighted entry
|
||||
source_index = Some(self.cur_index);
|
||||
}
|
||||
source_index
|
||||
}
|
||||
|
||||
pub fn next_mode(&mut self) -> (Option<Mode>, Option<Mode>) {
|
||||
let new_mode = match (self.prev_mode, self.cur_mode) {
|
||||
(_, Mode::InstallDrivers) => Mode::ScanDisks,
|
||||
|
|
@ -514,67 +548,38 @@ fn get_chunks(r: Rect) -> Vec<Rect> {
|
|||
chunks
|
||||
}
|
||||
|
||||
fn get_right_headers(prev_mode: Mode, cur_mode: Mode) -> Vec<DVLine> {
|
||||
let mut headers = Vec::new();
|
||||
fn get_right_selections(app: &App, prev_mode: Mode, cur_mode: Mode) -> Vec<Vec<DVLine>> {
|
||||
let mut selections = Vec::new();
|
||||
|
||||
// Main header
|
||||
match (prev_mode, cur_mode) {
|
||||
(_, Mode::InstallDrivers) => headers.push(DVLine {
|
||||
line_parts: vec![String::from("CPU"), get_cpu_name()],
|
||||
line_colors: vec![Color::Cyan, Color::Reset],
|
||||
}),
|
||||
(_, Mode::InstallDrivers) => {
|
||||
selections.push(vec![DVLine {
|
||||
line_parts: vec![String::from("CPU"), get_cpu_name()],
|
||||
line_colors: vec![Color::Cyan, Color::Reset],
|
||||
}]);
|
||||
}
|
||||
(_, Mode::SelectDisks | Mode::SelectTableType)
|
||||
| (Mode::SelectDisks | Mode::SelectTableType, Mode::Confirm) => {
|
||||
// Source Disk Details
|
||||
headers.push(DVLine {
|
||||
line_parts: vec![String::from("Source")],
|
||||
line_colors: vec![Color::Cyan],
|
||||
});
|
||||
headers.push(DVLine {
|
||||
line_parts: vec![String::new()],
|
||||
line_colors: vec![Color::Reset],
|
||||
});
|
||||
headers.push(DVLine {
|
||||
line_parts: vec![String::new()],
|
||||
line_colors: vec![Color::Reset],
|
||||
});
|
||||
headers.push(DVLine {
|
||||
line_parts: vec![format!(
|
||||
"{:<8} {:>11} {:<4} {:<4} {}",
|
||||
"Disk ID", "Size", "Conn", "Type", "Model (Serial)"
|
||||
)],
|
||||
line_colors: vec![Color::Green],
|
||||
});
|
||||
if let Some(index) = app.get_source_index() {
|
||||
let disk_list = app.clone.disk_list.lock().unwrap();
|
||||
if let Some(disk) = disk_list.get(index) {
|
||||
selections.push(get_disk_description_right(&disk, "Source"));
|
||||
}
|
||||
}
|
||||
// Dest Disk Details
|
||||
if let Some(index) = app.get_dest_index() {
|
||||
let disk_list = app.clone.disk_list.lock().unwrap();
|
||||
if let Some(disk) = disk_list.get(index) {
|
||||
selections.push(get_disk_description_right(&disk, "Dest"));
|
||||
}
|
||||
}
|
||||
}
|
||||
(Mode::SelectParts, Mode::Confirm) => {
|
||||
//
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// First selection
|
||||
match (prev_mode, cur_mode) {
|
||||
(_, Mode::SelectDisks | Mode::SelectTableType)
|
||||
| (Mode::SelectDisks | Mode::SelectTableType, Mode::Confirm) => headers.push(DVLine {
|
||||
line_parts: vec![String::from("Source"), get_cpu_name()],
|
||||
line_colors: vec![Color::Cyan, Color::Reset],
|
||||
}),
|
||||
(Mode::SelectParts, Mode::Confirm) => {
|
||||
headers.push(DVLine {
|
||||
line_parts: vec![String::from("Dest")],
|
||||
line_colors: vec![Color::Cyan],
|
||||
});
|
||||
// Disk details
|
||||
// Part details
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
// Source
|
||||
// SelectDisks
|
||||
// SelectTableType
|
||||
// Confirm (for above ^)
|
||||
// Dest
|
||||
// SelectParts
|
||||
// (SelectParts, Confirm)
|
||||
|
||||
// Second selection
|
||||
|
||||
headers
|
||||
selections
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ use ratatui::{
|
|||
use serde::{Deserialize, Serialize};
|
||||
use std::iter::zip;
|
||||
|
||||
use crate::system::disk::Disk;
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct DVLine {
|
||||
pub line_parts: Vec<String>,
|
||||
|
|
@ -34,4 +36,47 @@ impl DVLine {
|
|||
.map(|(part, color)| spans.push(Span::styled(part, Style::default().fg(color))));
|
||||
Line::from(spans)
|
||||
}
|
||||
|
||||
pub fn blank() -> Self {
|
||||
Self {
|
||||
line_parts: vec![String::new()],
|
||||
line_colors: vec![Color::Reset],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_disk_description_right(disk: &Disk, label: &str) -> Vec<DVLine> {
|
||||
let mut 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} {:<4} {:<4} {}",
|
||||
"Disk ID", "Size", "Conn", "Type", "Model (Serial)"
|
||||
)],
|
||||
line_colors: vec![Color::Green],
|
||||
},
|
||||
DVLine {
|
||||
line_parts: vec![disk.description.clone()],
|
||||
line_colors: vec![Color::Reset],
|
||||
},
|
||||
DVLine::blank(),
|
||||
DVLine {
|
||||
line_parts: vec![format!(
|
||||
"{:<8} {:>11} {:<7} {}",
|
||||
"Part ID", "Size", "(FS)", "\"Label\""
|
||||
)],
|
||||
line_colors: vec![Color::Blue],
|
||||
},
|
||||
];
|
||||
for line in &disk.parts_description {
|
||||
description.push(DVLine {
|
||||
line_parts: vec![line.clone()],
|
||||
line_colors: vec![Color::Reset],
|
||||
});
|
||||
}
|
||||
description
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue