Compare commits
6 commits
e029e02cc2
...
528140b0e9
| Author | SHA1 | Date | |
|---|---|---|---|
| 528140b0e9 | |||
| a8597a22a6 | |||
| 843e46fc86 | |||
| 2abd6c6582 | |||
| 86b1f34330 | |||
| 353f2d5570 |
7 changed files with 561 additions and 420 deletions
|
|
@ -16,21 +16,28 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use strum::Display;
|
||||
|
||||
use crate::{components::popup::Type, line::DVLine, state::Mode, system::disk::Disk};
|
||||
use crate::{
|
||||
components::popup::Type,
|
||||
line::DVLine,
|
||||
state::Mode,
|
||||
system::{
|
||||
disk::{Disk, PartitionTableType},
|
||||
drivers::Driver,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)]
|
||||
pub enum Action {
|
||||
// App
|
||||
Highlight(usize),
|
||||
InstallDriver,
|
||||
Process,
|
||||
ScanDisks,
|
||||
Select(Option<usize>, Option<usize>), // indicies for (source, dest) etc
|
||||
SelectRight(Option<usize>, Option<usize>), // indicies for right info pane
|
||||
Select(Option<usize>, Option<usize>), // indicies for (source, dest) or (boot, os)
|
||||
SelectDriver(Driver),
|
||||
SelectTableType(PartitionTableType),
|
||||
UpdateDiskList(Vec<Disk>),
|
||||
UpdateFooter(String),
|
||||
UpdateLeft(String, Vec<String>, Vec<String>, bool), // (title, labels, items, select_one)
|
||||
UpdateRight(Vec<Vec<DVLine>>, usize, Vec<Vec<DVLine>>), // (labels, start_index, items) - items before start are always shown
|
||||
UpdateLeft(usize, Vec<Vec<DVLine>>), // (start_index, lines) - lines before start are always shown
|
||||
UpdateRight(usize, Vec<Vec<DVLine>>), // Same as above
|
||||
// Screens
|
||||
DismissPopup,
|
||||
DisplayPopup(Type, String),
|
||||
|
|
|
|||
|
|
@ -101,43 +101,102 @@ impl App {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn prev_mode(&mut self) -> Option<Mode> {
|
||||
let new_mode = match self.cur_mode {
|
||||
Mode::Failed => Some(Mode::Failed),
|
||||
Mode::Done => Some(Mode::Done),
|
||||
Mode::SelectParts => Some(Mode::SelectParts),
|
||||
Mode::Confirm => Some(Mode::SelectTableType),
|
||||
Mode::SelectTableType => Some(Mode::SelectDisks),
|
||||
Mode::SelectDisks => Some(Mode::ScanDisks),
|
||||
//
|
||||
Mode::InstallDrivers
|
||||
| Mode::ScanDisks
|
||||
| Mode::PreClone
|
||||
| Mode::Clone
|
||||
| Mode::PostClone => None,
|
||||
};
|
||||
new_mode
|
||||
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.list.selected().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn next_mode(&mut self) -> Option<Mode> {
|
||||
let new_mode = match self.cur_mode {
|
||||
Mode::InstallDrivers => Mode::ScanDisks,
|
||||
Mode::ScanDisks => Mode::SelectDisks,
|
||||
Mode::SelectDisks => Mode::SelectTableType,
|
||||
Mode::SelectTableType => Mode::Confirm,
|
||||
Mode::Confirm => Mode::PreClone,
|
||||
Mode::PreClone => Mode::Clone,
|
||||
Mode::Clone => Mode::SelectParts,
|
||||
Mode::SelectParts => Mode::PostClone,
|
||||
Mode::PostClone | Mode::Done => Mode::Done,
|
||||
Mode::Failed => Mode::Failed,
|
||||
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 {
|
||||
// Highlighted entry
|
||||
if let Some(index) = self.list.selected() {
|
||||
if index != self.get_boot_part_index() {
|
||||
os_part_index = Some(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 {
|
||||
// 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 let Some(index) = self.list.selected() {
|
||||
// Highlighted entry
|
||||
if let Some(source_index) = self.get_source_index() {
|
||||
if index != source_index {
|
||||
dest_index = Some(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
dest_index
|
||||
}
|
||||
|
||||
pub fn get_source_index(&self) -> Option<usize> {
|
||||
if let Some(index) = self.clone.disk_index_source {
|
||||
// Selected in prior mode
|
||||
Some(index)
|
||||
} else if let Some(index) = self.selections[0] {
|
||||
// Selected in this mode
|
||||
Some(index)
|
||||
} else {
|
||||
self.list.selected()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn next_mode(&mut self) -> (Option<Mode>, Option<Mode>) {
|
||||
let new_mode = match (self.prev_mode, self.cur_mode) {
|
||||
(_, Mode::InstallDrivers) => Mode::ScanDisks,
|
||||
(_, Mode::ScanDisks) => Mode::SelectDisks,
|
||||
(_, Mode::SelectDisks | Mode::SelectTableType | Mode::SelectParts) => {
|
||||
if self.selections[1].is_some() {
|
||||
Mode::Confirm
|
||||
} else {
|
||||
self.cur_mode
|
||||
}
|
||||
}
|
||||
(Mode::SelectDisks, Mode::Confirm) => Mode::SelectTableType,
|
||||
(Mode::SelectTableType, Mode::Confirm) => Mode::PreClone,
|
||||
(_, Mode::PreClone) => Mode::Clone,
|
||||
(_, Mode::Clone) => Mode::SelectParts,
|
||||
(Mode::SelectParts, Mode::Confirm) => Mode::PostClone,
|
||||
(_, Mode::PostClone | Mode::Done) => Mode::Done,
|
||||
(_, Mode::Failed) => Mode::Failed,
|
||||
// Invalid states
|
||||
(_, Mode::Confirm) => panic!("This shouldn't happen."),
|
||||
};
|
||||
|
||||
let prev_mode = {
|
||||
match self.cur_mode {
|
||||
Mode::Confirm => Some(self.prev_mode),
|
||||
Mode::PreClone | Mode::Clone | Mode::PostClone | Mode::Done => {
|
||||
// Override since we're past the point of no return
|
||||
Some(self.cur_mode)
|
||||
}
|
||||
_ => Some(self.cur_mode),
|
||||
}
|
||||
};
|
||||
|
||||
if new_mode == self.cur_mode {
|
||||
// No mode change needed
|
||||
None
|
||||
(None, None)
|
||||
} else {
|
||||
Some(new_mode)
|
||||
(prev_mode, Some(new_mode))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +204,6 @@ impl App {
|
|||
info!("Setting mode to {new_mode:?}");
|
||||
self.cur_mode = new_mode;
|
||||
match new_mode {
|
||||
Mode::InstallDrivers => self.clone.scan_drivers(),
|
||||
Mode::ScanDisks => {
|
||||
self.prev_mode = self.cur_mode;
|
||||
if self.tasks.idle() {
|
||||
|
|
@ -244,7 +302,10 @@ impl App {
|
|||
String::from("COMPLETE\n\n\nThank you for using this tool!"),
|
||||
))?;
|
||||
}
|
||||
_ => {}
|
||||
_ => {
|
||||
//TODO
|
||||
//FIXME
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -358,41 +419,37 @@ impl App {
|
|||
Action::InstallDriver => {
|
||||
self.action_tx.send(Action::SetMode(Mode::InstallDrivers))?;
|
||||
}
|
||||
Action::Process => match self.cur_mode {
|
||||
Mode::Confirm => {
|
||||
self.action_tx.send(Action::NextScreen)?;
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
Action::SelectDriver(ref driver) => {
|
||||
self.clone.driver = Some(driver.clone());
|
||||
drivers::load(&driver.inf_paths);
|
||||
self.action_tx.send(Action::NextScreen)?;
|
||||
}
|
||||
Action::SelectTableType(ref table_type) => {
|
||||
self.clone.table_type = Some(table_type.clone());
|
||||
self.action_tx.send(Action::NextScreen)?;
|
||||
}
|
||||
Action::Resize(w, h) => self.handle_resize(tui, w, h)?,
|
||||
Action::Render => self.render(tui)?,
|
||||
Action::PrevScreen => {
|
||||
if let Some(new_mode) = self.prev_mode() {
|
||||
self.prev_mode = new_mode;
|
||||
self.cur_mode = new_mode;
|
||||
self.action_tx.send(Action::SetMode(new_mode))?;
|
||||
}
|
||||
let new_mode = match (self.prev_mode, self.cur_mode) {
|
||||
(Mode::SelectTableType, Mode::SelectTableType) => Mode::SelectDisks,
|
||||
(_, _) => self.prev_mode,
|
||||
};
|
||||
self.action_tx.send(Action::SetMode(new_mode))?;
|
||||
}
|
||||
Action::NextScreen => match self.next_mode() {
|
||||
None => {}
|
||||
Some(next) => {
|
||||
self.prev_mode = self.cur_mode;
|
||||
(None, None) => {}
|
||||
(Some(prev), Some(next)) => {
|
||||
self.prev_mode = prev;
|
||||
self.cur_mode = next;
|
||||
self.action_tx.send(Action::DismissPopup)?;
|
||||
self.action_tx.send(Action::SetMode(next))?;
|
||||
}
|
||||
_ => panic!("Failed to determine next mode"),
|
||||
},
|
||||
Action::ScanDisks => self.action_tx.send(Action::SetMode(Mode::ScanDisks))?,
|
||||
Action::Select(one, two) => {
|
||||
match self.cur_mode {
|
||||
Mode::InstallDrivers => {
|
||||
if let Some(index) = one {
|
||||
if let Some(driver) = self.clone.driver_list.get(index).cloned() {
|
||||
drivers::load(&driver.inf_paths);
|
||||
self.clone.driver = Some(driver);
|
||||
}
|
||||
}
|
||||
}
|
||||
Mode::SelectDisks => {
|
||||
self.clone.disk_index_source = one;
|
||||
self.clone.disk_index_dest = two;
|
||||
|
|
@ -401,21 +458,6 @@ impl App {
|
|||
self.clone.part_index_boot = one;
|
||||
self.clone.part_index_os = two;
|
||||
}
|
||||
Mode::SelectTableType => {
|
||||
self.clone.table_type = {
|
||||
if let Some(index) = one {
|
||||
match index {
|
||||
0 => Some(PartitionTableType::Guid),
|
||||
1 => Some(PartitionTableType::Legacy),
|
||||
index => {
|
||||
panic!("Failed to select PartitionTableType: {}", index)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
self.selections[0] = one;
|
||||
|
|
@ -423,42 +465,8 @@ impl App {
|
|||
}
|
||||
Action::SetMode(new_mode) => {
|
||||
self.set_mode(new_mode)?;
|
||||
self.action_tx
|
||||
.send(Action::UpdateFooter(build_footer_string(self.cur_mode)))?;
|
||||
let (title, labels, items, select_one) = build_left_items(self, self.cur_mode);
|
||||
self.action_tx
|
||||
.send(Action::UpdateLeft(title, labels, items, select_one))?;
|
||||
let (labels, start, items) = build_right_items(self, self.cur_mode);
|
||||
self.action_tx
|
||||
.send(Action::UpdateRight(labels, start, items))?;
|
||||
match new_mode {
|
||||
// Mode::InstallDrivers | Mode::SelectDisks => {
|
||||
// self.action_tx.send(Action::Select(None, None))?
|
||||
// }
|
||||
Mode::SelectTableType | Mode::Confirm => {
|
||||
// Select source/dest disks
|
||||
self.action_tx.send(Action::SelectRight(
|
||||
self.clone.disk_index_source,
|
||||
self.clone.disk_index_dest,
|
||||
))?;
|
||||
}
|
||||
Mode::SelectParts => {
|
||||
// Select first partition as boot partition
|
||||
self.action_tx.send(Action::Select(Some(0), None))?;
|
||||
|
||||
// Highlight 2nd or 3rd partition as OS partition
|
||||
let index = if let Some(table_type) = &self.clone.table_type {
|
||||
match table_type {
|
||||
PartitionTableType::Guid => 2,
|
||||
PartitionTableType::Legacy => 1,
|
||||
}
|
||||
} else {
|
||||
1
|
||||
};
|
||||
self.action_tx.send(Action::Highlight(index))?;
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
let (start, lines) = get_right_selections(self, self.prev_mode, self.cur_mode);
|
||||
self.action_tx.send(Action::UpdateRight(start, lines))?;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
@ -552,145 +560,88 @@ fn get_chunks(r: Rect) -> Vec<Rect> {
|
|||
chunks
|
||||
}
|
||||
|
||||
fn build_footer_string(cur_mode: Mode) -> String {
|
||||
match cur_mode {
|
||||
Mode::ScanDisks | Mode::PreClone | Mode::Clone | Mode::PostClone => {
|
||||
String::from("(q) to quit")
|
||||
}
|
||||
Mode::SelectParts => String::from("(Enter) to select / (s) to start over / (q) to quit"),
|
||||
Mode::SelectDisks => String::from(
|
||||
"(Enter) to select / / (i) to install driver / (r) to rescan / (q) to quit",
|
||||
),
|
||||
Mode::SelectTableType => String::from("(Enter) to select / (b) to go back / (q) to quit"),
|
||||
Mode::Confirm => String::from("(Enter) to confirm / (b) to go back / (q) to quit"),
|
||||
Mode::Done | Mode::Failed | Mode::InstallDrivers => String::from("(Enter) or (q) to quit"),
|
||||
}
|
||||
}
|
||||
fn build_left_items(app: &App, cur_mode: Mode) -> (String, Vec<String>, Vec<String>, bool) {
|
||||
let title: String;
|
||||
let mut items = Vec::new();
|
||||
let mut labels: Vec<String> = Vec::new();
|
||||
let mut select_one = false;
|
||||
match cur_mode {
|
||||
Mode::InstallDrivers => {
|
||||
title = String::from("Install Drivers");
|
||||
select_one = true;
|
||||
app.clone
|
||||
.driver_list
|
||||
.iter()
|
||||
.for_each(|driver| items.push(driver.to_string()));
|
||||
}
|
||||
Mode::SelectDisks => {
|
||||
title = String::from("Select Source and Destination Disks");
|
||||
labels.push(String::from("source"));
|
||||
labels.push(String::from("dest"));
|
||||
let disk_list = app.clone.disk_list.lock().unwrap();
|
||||
disk_list
|
||||
.iter()
|
||||
.for_each(|disk| items.push(disk.description.to_string()));
|
||||
}
|
||||
Mode::SelectTableType => {
|
||||
title = String::from("Select Partition Table Type");
|
||||
select_one = true;
|
||||
items.push(format!("{}", PartitionTableType::Guid));
|
||||
items.push(format!("{}", PartitionTableType::Legacy));
|
||||
}
|
||||
Mode::Confirm => {
|
||||
title = String::from("Confirm Selections");
|
||||
}
|
||||
Mode::PreClone | Mode::Clone | Mode::PostClone | Mode::ScanDisks => {
|
||||
title = String::from("Processing");
|
||||
}
|
||||
Mode::SelectParts => {
|
||||
title = String::from("Select Boot and OS Partitions");
|
||||
labels.push(String::from("boot"));
|
||||
labels.push(String::from("os"));
|
||||
let disk_list = app.clone.disk_list.lock().unwrap();
|
||||
if let Some(index) = app.clone.disk_index_dest {
|
||||
if let Some(disk) = disk_list.get(index) {
|
||||
disk.get_parts().iter().for_each(|part| {
|
||||
items.push(part.to_string());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Mode::Done | Mode::Failed => title = String::from("Done"),
|
||||
};
|
||||
(title, labels, items, select_one)
|
||||
}
|
||||
|
||||
fn build_right_items(app: &App, cur_mode: Mode) -> (Vec<Vec<DVLine>>, usize, Vec<Vec<DVLine>>) {
|
||||
let mut items = Vec::new();
|
||||
let mut labels: Vec<Vec<DVLine>> = Vec::new();
|
||||
fn get_right_selections(app: &App, prev_mode: Mode, cur_mode: Mode) -> (usize, Vec<Vec<DVLine>>) {
|
||||
let mut selections = Vec::new();
|
||||
let mut start_index = 0;
|
||||
match cur_mode {
|
||||
Mode::InstallDrivers => {
|
||||
items.push(vec![DVLine {
|
||||
match (prev_mode, cur_mode) {
|
||||
(_, Mode::InstallDrivers) => {
|
||||
info!("get_right_selections: InstallDrivers");
|
||||
selections.push(vec![DVLine {
|
||||
line_parts: vec![String::from("CPU")],
|
||||
line_colors: vec![Color::Cyan],
|
||||
}]);
|
||||
items.push(vec![DVLine {
|
||||
selections.push(vec![DVLine {
|
||||
line_parts: vec![get_cpu_name()],
|
||||
line_colors: vec![Color::Reset],
|
||||
}]);
|
||||
start_index = 2;
|
||||
}
|
||||
Mode::SelectDisks | Mode::SelectTableType | Mode::Confirm => {
|
||||
// Labels
|
||||
labels.push(vec![DVLine {
|
||||
line_parts: vec![String::from("Source")],
|
||||
line_colors: vec![Color::Cyan],
|
||||
}]);
|
||||
let dest_dv_line = DVLine {
|
||||
line_parts: vec![
|
||||
String::from("Dest"),
|
||||
String::from(" (WARNING: ALL DATA WILL BE DELETED!)"),
|
||||
],
|
||||
line_colors: vec![Color::Cyan, 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",
|
||||
};
|
||||
labels.push(vec![
|
||||
dest_dv_line,
|
||||
DVLine {
|
||||
line_parts: vec![format!(" (Will be formatted {type_str})")],
|
||||
line_colors: vec![Color::Yellow],
|
||||
},
|
||||
]);
|
||||
} else {
|
||||
labels.push(vec![dest_dv_line]);
|
||||
(_, Mode::SelectDisks | Mode::SelectTableType)
|
||||
| (Mode::SelectDisks | Mode::SelectTableType, Mode::Confirm) => {
|
||||
info!("get_right_selections: SelectDisks");
|
||||
// Source Disk Details
|
||||
if let Some(index) = app.get_source_index() {
|
||||
info!("get_right_selections: Source Disk Index: {}", 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) {
|
||||
let mut disk_description = get_disk_description_right(&disk, "Dest");
|
||||
|
||||
// Add format warning
|
||||
disk_description[0] // i.e. "Dest:"
|
||||
.line_parts
|
||||
.push(" (WARNING: ALL DATA WILL BE DELETED!)".to_string());
|
||||
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",
|
||||
};
|
||||
disk_description.insert(
|
||||
1,
|
||||
DVLine {
|
||||
line_parts: vec![format!(" (Will be formatted {type_str}")],
|
||||
line_colors: vec![Color::Yellow],
|
||||
},
|
||||
);
|
||||
}
|
||||
selections.push(disk_description)
|
||||
}
|
||||
}
|
||||
let disk_list = app.clone.disk_list.lock().unwrap();
|
||||
disk_list
|
||||
.iter()
|
||||
.for_each(|disk| items.push(get_disk_description_right(&disk)));
|
||||
}
|
||||
Mode::SelectParts => {
|
||||
vec!["Boot", "OS"].iter().for_each(|s| {
|
||||
labels.push(vec![DVLine {
|
||||
line_parts: vec![String::from(*s)],
|
||||
line_colors: vec![Color::Cyan],
|
||||
}])
|
||||
});
|
||||
if let Some(index) = app.clone.disk_index_dest {
|
||||
(_, Mode::SelectParts) | (Mode::SelectParts, Mode::Confirm) => {
|
||||
info!("get_right_selections: SelectParts");
|
||||
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
|
||||
items.push(get_disk_description_right(&disk));
|
||||
selections.push(get_disk_description_right(&disk, "Disk"));
|
||||
|
||||
// Partition Details
|
||||
disk.parts
|
||||
.iter()
|
||||
.for_each(|part| items.push(get_part_description(&part)));
|
||||
// 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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
(labels, start_index, items)
|
||||
info!("Right Selections: {:?}", &selections);
|
||||
(start_index, selections)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,9 +51,25 @@ impl Component for Footer {
|
|||
}
|
||||
|
||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||
match action {
|
||||
Action::UpdateFooter(text) => self.text = text,
|
||||
_ => {}
|
||||
if let Action::SetMode(new_mode) = action {
|
||||
self.text = match new_mode {
|
||||
Mode::ScanDisks | Mode::PreClone | Mode::Clone | Mode::PostClone => {
|
||||
String::from("(q) to quit")
|
||||
}
|
||||
Mode::SelectParts => {
|
||||
String::from("(Enter) to select / (s) to start over / (q) to quit")
|
||||
}
|
||||
Mode::SelectDisks => String::from(
|
||||
"(Enter) to select / / (i) to install driver / (r) to rescan / (q) to quit",
|
||||
),
|
||||
Mode::SelectTableType => {
|
||||
String::from("(Enter) to select / (b) to go back / (q) to quit")
|
||||
}
|
||||
Mode::Confirm => String::from("(Enter) to confirm / (b) to go back / (q) to quit"),
|
||||
Mode::Done | Mode::Failed | Mode::InstallDrivers => {
|
||||
String::from("(Enter) or (q) to quit")
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,37 +20,42 @@ use ratatui::{
|
|||
widgets::{Block, Borders, HighlightSpacing, List, ListItem, Padding, Paragraph},
|
||||
};
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
use tracing::info;
|
||||
|
||||
use super::{state::StatefulList, Component};
|
||||
use crate::{action::Action, config::Config};
|
||||
use super::{popup, state::StatefulList, Component};
|
||||
use crate::{
|
||||
action::Action,
|
||||
config::Config,
|
||||
state::Mode,
|
||||
system::{
|
||||
disk::{Disk, Partition, PartitionTableType},
|
||||
drivers::{self, Driver},
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Left {
|
||||
command_tx: Option<UnboundedSender<Action>>,
|
||||
config: Config,
|
||||
labels: Vec<String>,
|
||||
list: StatefulList<String>,
|
||||
select_one: bool,
|
||||
selections: Vec<Option<usize>>,
|
||||
selections_saved: Vec<Option<usize>>,
|
||||
disk_id_dest: Option<usize>,
|
||||
table_type: Option<PartitionTableType>,
|
||||
title_text: String,
|
||||
list_disks: StatefulList<Disk>,
|
||||
list_drivers: StatefulList<Driver>,
|
||||
list_parts: StatefulList<Partition>,
|
||||
list_table_types: StatefulList<PartitionTableType>,
|
||||
mode: Mode,
|
||||
selections: Vec<Option<usize>>,
|
||||
}
|
||||
|
||||
impl Left {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
select_one: false,
|
||||
labels: vec![String::from("one"), String::from("two")],
|
||||
selections: vec![None, None],
|
||||
selections_saved: vec![None, None],
|
||||
title_text: String::from("Home"),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn set_highlight(&mut self, index: usize) {
|
||||
self.list.select(index);
|
||||
}
|
||||
}
|
||||
|
||||
impl Component for Left {
|
||||
|
|
@ -71,59 +76,181 @@ impl Component for Left {
|
|||
|
||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||
match action {
|
||||
Action::Highlight(index) => self.set_highlight(index),
|
||||
Action::KeyUp => self.list.previous(),
|
||||
Action::KeyDown => self.list.next(),
|
||||
Action::Process => {
|
||||
if let Some(command_tx) = self.command_tx.clone() {
|
||||
match (self.selections[0], self.selections[1]) {
|
||||
(None, None) => {
|
||||
// Making first selection
|
||||
command_tx.send(Action::Select(self.list.selected(), None))?;
|
||||
if self.select_one {
|
||||
// Confirm selection
|
||||
command_tx.send(Action::NextScreen)?;
|
||||
Action::KeyUp => match self.mode {
|
||||
Mode::InstallDrivers => self.list_drivers.previous(),
|
||||
Mode::SelectDisks => self.list_disks.previous(),
|
||||
Mode::SelectTableType => self.list_table_types.previous(),
|
||||
Mode::SelectParts => self.list_parts.previous(),
|
||||
_ => {}
|
||||
},
|
||||
Action::KeyDown => match self.mode {
|
||||
Mode::InstallDrivers => self.list_drivers.next(),
|
||||
Mode::SelectDisks => self.list_disks.next(),
|
||||
Mode::SelectTableType => self.list_table_types.next(),
|
||||
Mode::SelectParts => self.list_parts.next(),
|
||||
_ => {}
|
||||
},
|
||||
Action::Process => match self.mode {
|
||||
// NOTE: Remove all variants except Mode::Confirm?
|
||||
Mode::Confirm => {
|
||||
if let Some(command_tx) = self.command_tx.clone() {
|
||||
command_tx.send(Action::NextScreen)?;
|
||||
}
|
||||
}
|
||||
Mode::InstallDrivers
|
||||
| Mode::SelectDisks
|
||||
| Mode::SelectTableType
|
||||
| Mode::SelectParts => {
|
||||
// Menu selection sections
|
||||
let selection: Option<usize> = match self.mode {
|
||||
Mode::InstallDrivers => self.list_drivers.selected(),
|
||||
Mode::SelectDisks => self.list_disks.selected(),
|
||||
Mode::SelectTableType => self.list_table_types.selected(),
|
||||
Mode::SelectParts => self.list_parts.selected(),
|
||||
_ => panic!("This shouldn't happen!"),
|
||||
};
|
||||
if let Some(index) = selection {
|
||||
if let Some(command_tx) = self.command_tx.clone() {
|
||||
let mut selection_one: Option<usize> = None;
|
||||
let mut selection_two: Option<usize> = None;
|
||||
|
||||
// Get selection(s)
|
||||
if self.selections[0].is_none() {
|
||||
// First selection
|
||||
selection_one = Some(index);
|
||||
selection_two = None;
|
||||
} else {
|
||||
// Second selection
|
||||
if let Some(source_index) = self.selections[0] {
|
||||
if index == source_index {
|
||||
// Toggle first selection
|
||||
selection_one = None;
|
||||
self.selections[0] = None;
|
||||
} else {
|
||||
selection_one = self.selections[0];
|
||||
selection_two = Some(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send selection(s) if needed
|
||||
// NOTE: This is needed to keep the app and all components in sync
|
||||
match self.mode {
|
||||
Mode::InstallDrivers => {
|
||||
// Only need to select one entry
|
||||
if let Some(driver) = self.list_drivers.get_selected() {
|
||||
command_tx.send(Action::SelectDriver(driver.clone()))?;
|
||||
}
|
||||
}
|
||||
Mode::SelectTableType => {
|
||||
// Only need to select one entry
|
||||
if let Some(table_type) = self.list_table_types.get_selected() {
|
||||
self.table_type = Some(table_type.clone());
|
||||
command_tx.send(Action::SelectTableType(table_type))?;
|
||||
}
|
||||
}
|
||||
Mode::SelectDisks | Mode::SelectParts => {
|
||||
command_tx
|
||||
.send(Action::Select(selection_one, selection_two))?;
|
||||
|
||||
// Advance screen if both selections made
|
||||
if selection_two.is_some() {
|
||||
command_tx.send(Action::NextScreen)?;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
Action::Select(Some(index), None) => self.selections[0] = Some(index),
|
||||
Action::Select(_, Some(index)) => {
|
||||
if self.mode == Mode::SelectDisks {
|
||||
self.disk_id_dest = Some(index);
|
||||
}
|
||||
}
|
||||
Action::SetMode(new_mode) => {
|
||||
let prev_mode = self.mode;
|
||||
self.mode = new_mode;
|
||||
match (prev_mode, new_mode) {
|
||||
(_, Mode::ScanDisks) => {
|
||||
self.list_disks.clear_items();
|
||||
self.title_text = String::new();
|
||||
}
|
||||
(_, Mode::InstallDrivers) => {
|
||||
self.list_drivers.set_items(drivers::scan());
|
||||
self.selections[0] = None;
|
||||
self.selections[1] = None;
|
||||
self.title_text = String::from("Install Drivers");
|
||||
if self.list_drivers.is_empty() {
|
||||
if let Some(command_tx) = self.command_tx.clone() {
|
||||
command_tx.send(Action::DisplayPopup(
|
||||
popup::Type::Error,
|
||||
String::from("No drivers available to install"),
|
||||
))?;
|
||||
}
|
||||
}
|
||||
(Some(first_index), None) => {
|
||||
if let Some(second_index) = self.list.selected() {
|
||||
// Making second selection
|
||||
if first_index == second_index {
|
||||
// Toggle first selection
|
||||
command_tx.send(Action::Select(None, None))?;
|
||||
} else {
|
||||
// Both selections made, proceed to next screen
|
||||
command_tx.send(Action::Select(
|
||||
Some(first_index),
|
||||
Some(second_index),
|
||||
))?;
|
||||
command_tx.send(Action::NextScreen)?;
|
||||
}
|
||||
(_, Mode::SelectDisks) => {
|
||||
self.selections[0] = None;
|
||||
self.selections[1] = None;
|
||||
self.title_text = String::from("Select Source and Destination Disks");
|
||||
}
|
||||
(_, Mode::SelectTableType) => {
|
||||
self.list_table_types
|
||||
.set_items(vec![PartitionTableType::Guid, PartitionTableType::Legacy]);
|
||||
self.selections[0] = None;
|
||||
self.selections[1] = None;
|
||||
self.title_text = String::from("Select Partition Table Type");
|
||||
}
|
||||
(_, Mode::PreClone | Mode::Clone | Mode::PostClone) => {
|
||||
self.title_text = String::from("Processing");
|
||||
}
|
||||
(_, Mode::SelectParts) => {
|
||||
self.title_text = String::from("Select Boot and OS Partitions");
|
||||
}
|
||||
(Mode::SelectDisks | Mode::SelectParts, Mode::Confirm) => {
|
||||
self.title_text = String::from("Confirm Selections");
|
||||
}
|
||||
(Mode::SelectTableType, Mode::Confirm) => {
|
||||
self.title_text = String::from("Confirm Selections (Again)");
|
||||
}
|
||||
(_, Mode::Done | Mode::Failed) => self.title_text = String::from("Done"),
|
||||
// Invalid states
|
||||
(_, Mode::Confirm) => panic!("This shouldn't happen."),
|
||||
}
|
||||
}
|
||||
Action::UpdateDiskList(disks) => {
|
||||
info!("Updating disk list");
|
||||
self.list_disks.set_items(disks);
|
||||
if self.mode == Mode::Clone {
|
||||
if let Some(index) = self.disk_id_dest {
|
||||
if let Some(disk) = self.list_disks.get(index) {
|
||||
self.list_parts.set_items(disk.get_parts());
|
||||
|
||||
// Auto-select first partition and highlight likely OS partition
|
||||
if let Some(table_type) = &self.table_type {
|
||||
match table_type {
|
||||
PartitionTableType::Guid => {
|
||||
if disk.num_parts() >= 3 {
|
||||
self.selections[0] = Some(0);
|
||||
self.list_parts.select(2);
|
||||
}
|
||||
}
|
||||
PartitionTableType::Legacy => {
|
||||
if disk.num_parts() >= 2 {
|
||||
self.selections[0] = Some(0);
|
||||
self.list_parts.select(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => panic!("This shouldn't happen?"),
|
||||
}
|
||||
}
|
||||
}
|
||||
Action::Select(one, two) => {
|
||||
self.selections[0] = one;
|
||||
self.selections[1] = two;
|
||||
self.selections_saved[0] = one;
|
||||
self.selections_saved[1] = two;
|
||||
}
|
||||
Action::SetMode(_) => {
|
||||
self.selections[0] = None;
|
||||
self.selections[1] = None;
|
||||
}
|
||||
Action::UpdateLeft(title, labels, items, select_one) => {
|
||||
self.title_text = title;
|
||||
self.labels = labels
|
||||
.iter()
|
||||
.map(|label| format!(" ~{}~", label.to_lowercase()))
|
||||
.collect();
|
||||
self.list.set_items(items);
|
||||
self.select_one = select_one;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
Ok(None)
|
||||
|
|
@ -136,69 +263,125 @@ impl Component for Left {
|
|||
.areas(area);
|
||||
|
||||
// Title
|
||||
let title_text = if self.selections[1].is_some() || self.select_one {
|
||||
"Confirm Selections"
|
||||
} else {
|
||||
self.title_text.as_str()
|
||||
};
|
||||
let title =
|
||||
Paragraph::new(Line::from(Span::styled(title_text, Style::default())).centered())
|
||||
Paragraph::new(Line::from(Span::styled(&self.title_text, Style::default())).centered())
|
||||
.block(Block::default().borders(Borders::NONE));
|
||||
frame.render_widget(title, title_area);
|
||||
|
||||
// Body (Blank)
|
||||
if self.list.is_empty() {
|
||||
// Leave blank
|
||||
let paragraph = Paragraph::new(String::new()).block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.padding(Padding::new(1, 1, 1, 1)),
|
||||
);
|
||||
frame.render_widget(paragraph, body_area);
|
||||
|
||||
// Bail early
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Body
|
||||
let list_items: Vec<ListItem> = self
|
||||
.list
|
||||
.items
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, item)| {
|
||||
let mut style = Style::default();
|
||||
let text = if self.selections[0].is_some_and(|first_index| first_index == index) {
|
||||
if let Some(label) = self.labels.get(0) {
|
||||
style = style.yellow();
|
||||
label.as_str()
|
||||
} else {
|
||||
""
|
||||
}
|
||||
} else if self.selections[1].is_some_and(|second_index| second_index == index) {
|
||||
if let Some(label) = self.labels.get(1) {
|
||||
style = style.yellow();
|
||||
label.as_str()
|
||||
} else {
|
||||
""
|
||||
}
|
||||
} else {
|
||||
""
|
||||
match self.mode {
|
||||
Mode::ScanDisks
|
||||
| Mode::PreClone
|
||||
| Mode::Clone
|
||||
| Mode::PostClone
|
||||
| Mode::Done
|
||||
| Mode::Failed => {
|
||||
// Leave blank
|
||||
let paragraph = Paragraph::new(String::new()).block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.padding(Padding::new(1, 1, 1, 1)),
|
||||
);
|
||||
frame.render_widget(paragraph, body_area);
|
||||
|
||||
// Bail early
|
||||
return Ok(());
|
||||
}
|
||||
Mode::Confirm => {
|
||||
// Nag the user
|
||||
let paragraph = Paragraph::new(String::from("Are the listed selections correct?"))
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.padding(Padding::new(1, 1, 1, 1)),
|
||||
);
|
||||
frame.render_widget(paragraph, body_area);
|
||||
|
||||
// Bail early
|
||||
return Ok(());
|
||||
}
|
||||
Mode::InstallDrivers
|
||||
| Mode::SelectDisks
|
||||
| Mode::SelectTableType
|
||||
| Mode::SelectParts => {
|
||||
// List modes
|
||||
let mut list_items = Vec::<ListItem>::new();
|
||||
let list_items_strings: Vec<String> = match self.mode {
|
||||
Mode::InstallDrivers => self
|
||||
.list_drivers
|
||||
.items
|
||||
.iter()
|
||||
.map(|i| format!("{i}"))
|
||||
.collect(),
|
||||
Mode::SelectDisks => self
|
||||
.list_disks
|
||||
.items
|
||||
.iter()
|
||||
.map(|i| format!("{i}"))
|
||||
.collect(),
|
||||
Mode::SelectTableType => self
|
||||
.list_table_types
|
||||
.items
|
||||
.iter()
|
||||
.map(|i| format!("{i}"))
|
||||
.collect(),
|
||||
Mode::SelectParts => self
|
||||
.list_parts
|
||||
.items
|
||||
.iter()
|
||||
.map(|i| format!("{i}"))
|
||||
.collect(),
|
||||
_ => panic!("This shouldn't happen."),
|
||||
};
|
||||
ListItem::new(format!(" {item}\n{text}\n\n")).style(style)
|
||||
})
|
||||
.collect();
|
||||
let list = List::new(list_items)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.padding(Padding::new(1, 1, 1, 1)),
|
||||
)
|
||||
.highlight_spacing(HighlightSpacing::Always)
|
||||
.highlight_style(Style::new().green().bold())
|
||||
.highlight_symbol(" --> ")
|
||||
.repeat_highlight_symbol(false);
|
||||
frame.render_stateful_widget(list, body_area, &mut self.list.state);
|
||||
if !list_items_strings.is_empty() {
|
||||
for (index, item) in list_items_strings.iter().enumerate() {
|
||||
let mut item_style = Style::default();
|
||||
let mut item_text_tail = "";
|
||||
if let Some(selection_one) = self.selections[0] {
|
||||
if selection_one == index {
|
||||
item_style = Style::new().yellow();
|
||||
item_text_tail = match self.mode {
|
||||
Mode::SelectDisks => " ~source disk~",
|
||||
Mode::SelectParts => " ~boot volume~",
|
||||
_ => "",
|
||||
}
|
||||
}
|
||||
}
|
||||
list_items.push(
|
||||
ListItem::new(format!(" {item}\n{item_text_tail}\n\n"))
|
||||
.style(item_style),
|
||||
);
|
||||
}
|
||||
}
|
||||
let list = List::new(list_items)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.padding(Padding::new(1, 1, 1, 1)),
|
||||
)
|
||||
.highlight_spacing(HighlightSpacing::Always)
|
||||
.highlight_style(Style::new().green().bold())
|
||||
.highlight_symbol(" --> ")
|
||||
.repeat_highlight_symbol(false);
|
||||
match self.mode {
|
||||
Mode::InstallDrivers => {
|
||||
frame.render_stateful_widget(list, body_area, &mut self.list_drivers.state);
|
||||
}
|
||||
Mode::SelectDisks => {
|
||||
frame.render_stateful_widget(list, body_area, &mut self.list_disks.state);
|
||||
}
|
||||
Mode::SelectTableType => frame.render_stateful_widget(
|
||||
list,
|
||||
body_area,
|
||||
&mut self.list_table_types.state,
|
||||
),
|
||||
Mode::SelectParts => {
|
||||
frame.render_stateful_widget(list, body_area, &mut self.list_parts.state);
|
||||
}
|
||||
_ => panic!("This shouldn't happen."),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Done
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -22,17 +22,16 @@ use ratatui::{
|
|||
use tokio::sync::mpsc::UnboundedSender;
|
||||
|
||||
use super::{state::StatefulList, Component};
|
||||
use crate::{action::Action, config::Config, line::DVLine};
|
||||
use crate::{action::Action, config::Config, line::DVLine, state::Mode};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Right {
|
||||
command_tx: Option<UnboundedSender<Action>>,
|
||||
config: Config,
|
||||
cur_mode: Mode,
|
||||
list_header: Vec<DVLine>,
|
||||
list_labels: Vec<Vec<DVLine>>,
|
||||
list: StatefulList<Vec<DVLine>>,
|
||||
selections: Vec<Option<usize>>,
|
||||
selections_saved: Vec<Option<usize>>,
|
||||
title: String,
|
||||
}
|
||||
|
||||
|
|
@ -40,37 +39,10 @@ impl Right {
|
|||
pub fn new() -> Self {
|
||||
Self {
|
||||
selections: vec![None, None],
|
||||
selections_saved: vec![None, None],
|
||||
title: String::from("Info"),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn get_first(&self) -> Option<usize> {
|
||||
if self.selections_saved[0].is_some() {
|
||||
self.selections_saved[0]
|
||||
} else if self.selections[0].is_some() {
|
||||
self.selections[0]
|
||||
} else {
|
||||
self.list.selected()
|
||||
}
|
||||
}
|
||||
|
||||
fn get_second(&self) -> Option<usize> {
|
||||
if self.selections_saved[1].is_some() {
|
||||
self.selections_saved[1]
|
||||
} else if self.selections[1].is_some() {
|
||||
self.selections[1]
|
||||
} else if self.selections[0].is_some() && self.selections[0] != self.list.selected() {
|
||||
self.list.selected()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn set_highlight(&mut self, index: usize) {
|
||||
self.list.select(index);
|
||||
}
|
||||
}
|
||||
|
||||
impl Component for Right {
|
||||
|
|
@ -91,32 +63,51 @@ impl Component for Right {
|
|||
|
||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||
match action {
|
||||
Action::Highlight(index) => self.set_highlight(index),
|
||||
Action::KeyUp => self.list.previous(),
|
||||
Action::KeyDown => self.list.next(),
|
||||
Action::Select(one, two) => {
|
||||
self.selections[0] = one;
|
||||
self.selections[1] = two;
|
||||
if self.selections_saved[1].is_none() {
|
||||
// Update selections_saved
|
||||
// Conversely, if both selections set then preserve previous choices
|
||||
self.selections_saved[0] = one;
|
||||
self.selections_saved[1] = two;
|
||||
}
|
||||
}
|
||||
Action::SelectRight(one, two) => {
|
||||
self.selections_saved[0] = one;
|
||||
self.selections_saved[1] = two;
|
||||
}
|
||||
Action::SetMode(_) => {
|
||||
Action::SetMode(new_mode) => {
|
||||
self.cur_mode = new_mode;
|
||||
self.selections[0] = None;
|
||||
self.selections[1] = None;
|
||||
self.selections_saved[0] = None;
|
||||
self.selections_saved[1] = None;
|
||||
}
|
||||
Action::UpdateRight(labels, start_index, list) => {
|
||||
// Action::UpdateDiskList(disks) => {
|
||||
// info!("Updating disk list");
|
||||
// self.list_disks.set_items(disks);
|
||||
// if self.cur_mode == Mode::Clone {
|
||||
// if let Some(index) = self.selected_disks[1] {
|
||||
// if let Some(disk) = self.list_disks.get(index) {
|
||||
// self.list_parts.set_items(disk.get_parts());
|
||||
// // Auto-select first partition and highlight likely OS partition
|
||||
// if let Some(index) = self.selected_disks[1] {
|
||||
// if let Some(disk) = self.list_disks.get(index) {
|
||||
// if let Some(table_type) = &self.table_type {
|
||||
// match table_type {
|
||||
// PartitionTableType::Guid => {
|
||||
// if disk.num_parts() >= 3 {
|
||||
// self.selections[0] = Some(0);
|
||||
// self.list_parts.select(2);
|
||||
// }
|
||||
// }
|
||||
// PartitionTableType::Legacy => {
|
||||
// if disk.num_parts() >= 2 {
|
||||
// self.selections[0] = Some(0);
|
||||
// self.list_parts.select(1);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Action::UpdateRight(start_index, list) => {
|
||||
self.list_header = list[..start_index].iter().flatten().cloned().collect();
|
||||
self.list_labels = labels;
|
||||
self.list.set_items(list[start_index..].to_vec());
|
||||
}
|
||||
_ => {}
|
||||
|
|
@ -148,14 +139,8 @@ impl Component for Right {
|
|||
}
|
||||
|
||||
// First selection
|
||||
if let Some(first_index) = self.get_first() {
|
||||
if let Some(first_index) = self.selections[0] {
|
||||
if let Some(first_desc) = self.list.get(first_index) {
|
||||
if let Some(label) = self.list_labels.get(0) {
|
||||
label
|
||||
.iter()
|
||||
.for_each(|dv| body_text.push(dv.as_line().bold()));
|
||||
}
|
||||
body_text.push(Line::from(""));
|
||||
first_desc
|
||||
.iter()
|
||||
.for_each(|dv| body_text.push(dv.as_line()));
|
||||
|
|
@ -163,18 +148,12 @@ impl Component for Right {
|
|||
}
|
||||
|
||||
// Second selection
|
||||
if let Some(second_index) = self.get_second() {
|
||||
if let Some(second_index) = self.selections[1] {
|
||||
if let Some(second_desc) = self.list.get(second_index) {
|
||||
// Divider
|
||||
body_text.push(Line::from(""));
|
||||
body_text.push(Line::from(str::repeat("─", (body_area.width - 4) as usize)));
|
||||
body_text.push(Line::from(""));
|
||||
if let Some(label) = self.list_labels.get(1) {
|
||||
label
|
||||
.iter()
|
||||
.for_each(|dv| body_text.push(dv.as_line().bold()));
|
||||
}
|
||||
body_text.push(Line::from(""));
|
||||
second_desc
|
||||
.iter()
|
||||
.for_each(|dv| body_text.push(dv.as_line()));
|
||||
|
|
|
|||
|
|
@ -45,8 +45,13 @@ impl DVLine {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_disk_description_right(disk: &Disk) -> Vec<DVLine> {
|
||||
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} {}",
|
||||
|
|
@ -76,8 +81,13 @@ pub fn get_disk_description_right(disk: &Disk) -> Vec<DVLine> {
|
|||
description
|
||||
}
|
||||
|
||||
pub fn get_part_description(part: &Partition) -> Vec<DVLine> {
|
||||
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} {}",
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
use crate::system::{
|
||||
disk::{Disk, PartitionTableType},
|
||||
drivers,
|
||||
drivers::Driver,
|
||||
};
|
||||
|
||||
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
|
|
@ -44,10 +44,9 @@ pub struct CloneSettings {
|
|||
pub disk_index_dest: Option<usize>,
|
||||
pub disk_index_source: Option<usize>,
|
||||
pub disk_list: Arc<Mutex<Vec<Disk>>>,
|
||||
pub driver_list: Vec<drivers::Driver>,
|
||||
pub part_index_boot: Option<usize>,
|
||||
pub part_index_os: Option<usize>,
|
||||
pub driver: Option<drivers::Driver>,
|
||||
pub driver: Option<Driver>,
|
||||
pub table_type: Option<PartitionTableType>,
|
||||
}
|
||||
|
||||
|
|
@ -58,8 +57,4 @@ impl CloneSettings {
|
|||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn scan_drivers(&mut self) {
|
||||
self.driver_list = drivers::scan();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue