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,
|
footer::Footer, fps::FpsCounter, left::Left, popup, right::Right, title::Title, Component,
|
||||||
},
|
},
|
||||||
config::Config,
|
config::Config,
|
||||||
line::DVLine,
|
line::{get_disk_description_right, DVLine},
|
||||||
state::{CloneSettings, Mode},
|
state::{CloneSettings, Mode},
|
||||||
system::{
|
system::{
|
||||||
boot,
|
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>) {
|
pub fn next_mode(&mut self) -> (Option<Mode>, Option<Mode>) {
|
||||||
let new_mode = match (self.prev_mode, self.cur_mode) {
|
let new_mode = match (self.prev_mode, self.cur_mode) {
|
||||||
(_, Mode::InstallDrivers) => Mode::ScanDisks,
|
(_, Mode::InstallDrivers) => Mode::ScanDisks,
|
||||||
|
|
@ -514,67 +548,38 @@ fn get_chunks(r: Rect) -> Vec<Rect> {
|
||||||
chunks
|
chunks
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_right_headers(prev_mode: Mode, cur_mode: Mode) -> Vec<DVLine> {
|
fn get_right_selections(app: &App, prev_mode: Mode, cur_mode: Mode) -> Vec<Vec<DVLine>> {
|
||||||
let mut headers = Vec::new();
|
let mut selections = Vec::new();
|
||||||
|
|
||||||
// Main header
|
// Main header
|
||||||
match (prev_mode, cur_mode) {
|
match (prev_mode, cur_mode) {
|
||||||
(_, Mode::InstallDrivers) => headers.push(DVLine {
|
(_, Mode::InstallDrivers) => {
|
||||||
line_parts: vec![String::from("CPU"), get_cpu_name()],
|
selections.push(vec![DVLine {
|
||||||
line_colors: vec![Color::Cyan, Color::Reset],
|
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::SelectDisks | Mode::SelectTableType, Mode::Confirm) => {
|
| (Mode::SelectDisks | Mode::SelectTableType, Mode::Confirm) => {
|
||||||
// Source Disk Details
|
// Source Disk Details
|
||||||
headers.push(DVLine {
|
if let Some(index) = app.get_source_index() {
|
||||||
line_parts: vec![String::from("Source")],
|
let disk_list = app.clone.disk_list.lock().unwrap();
|
||||||
line_colors: vec![Color::Cyan],
|
if let Some(disk) = disk_list.get(index) {
|
||||||
});
|
selections.push(get_disk_description_right(&disk, "Source"));
|
||||||
headers.push(DVLine {
|
}
|
||||||
line_parts: vec![String::new()],
|
}
|
||||||
line_colors: vec![Color::Reset],
|
// Dest Disk Details
|
||||||
});
|
if let Some(index) = app.get_dest_index() {
|
||||||
headers.push(DVLine {
|
let disk_list = app.clone.disk_list.lock().unwrap();
|
||||||
line_parts: vec![String::new()],
|
if let Some(disk) = disk_list.get(index) {
|
||||||
line_colors: vec![Color::Reset],
|
selections.push(get_disk_description_right(&disk, "Dest"));
|
||||||
});
|
}
|
||||||
headers.push(DVLine {
|
}
|
||||||
line_parts: vec![format!(
|
}
|
||||||
"{:<8} {:>11} {:<4} {:<4} {}",
|
(Mode::SelectParts, Mode::Confirm) => {
|
||||||
"Disk ID", "Size", "Conn", "Type", "Model (Serial)"
|
//
|
||||||
)],
|
|
||||||
line_colors: vec![Color::Green],
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
selections
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ use ratatui::{
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::iter::zip;
|
use std::iter::zip;
|
||||||
|
|
||||||
|
use crate::system::disk::Disk;
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct DVLine {
|
pub struct DVLine {
|
||||||
pub line_parts: Vec<String>,
|
pub line_parts: Vec<String>,
|
||||||
|
|
@ -34,4 +36,47 @@ impl DVLine {
|
||||||
.map(|(part, color)| spans.push(Span::styled(part, Style::default().fg(color))));
|
.map(|(part, color)| spans.push(Span::styled(part, Style::default().fg(color))));
|
||||||
Line::from(spans)
|
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