Add remaining modes
- Refactored to use more pattern matching instead of if/then blocks - Fixed a bug in left.rs that always used the disk list
This commit is contained in:
parent
ed987c994d
commit
2f1f04dcab
5 changed files with 315 additions and 160 deletions
|
|
@ -1,15 +1,15 @@
|
||||||
{
|
{
|
||||||
"keybindings": {
|
"keybindings": {
|
||||||
"InstallDrivers": {
|
"ScanDisks": {
|
||||||
"<Enter>": "Process",
|
|
||||||
"<Up>": "KeyUp",
|
|
||||||
"<Down>": "KeyDown",
|
|
||||||
"<q>": "Quit", // Quit the application
|
"<q>": "Quit", // Quit the application
|
||||||
"<Ctrl-d>": "Quit", // Another way to quit
|
"<Ctrl-d>": "Quit", // Another way to quit
|
||||||
"<Ctrl-c>": "Quit", // Yet another way to quit
|
"<Ctrl-c>": "Quit", // Yet another way to quit
|
||||||
"<Ctrl-z>": "Suspend" // Suspend the application
|
"<Ctrl-z>": "Suspend" // Suspend the application
|
||||||
},
|
},
|
||||||
"ScanDisks": {
|
"InstallDrivers": {
|
||||||
|
"<Enter>": "Process",
|
||||||
|
"<Up>": "KeyUp",
|
||||||
|
"<Down>": "KeyDown",
|
||||||
"<q>": "Quit", // Quit the application
|
"<q>": "Quit", // Quit the application
|
||||||
"<Ctrl-d>": "Quit", // Another way to quit
|
"<Ctrl-d>": "Quit", // Another way to quit
|
||||||
"<Ctrl-c>": "Quit", // Yet another way to quit
|
"<Ctrl-c>": "Quit", // Yet another way to quit
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
"<Ctrl-c>": "Quit", // Yet another way to quit
|
"<Ctrl-c>": "Quit", // Yet another way to quit
|
||||||
"<Ctrl-z>": "Suspend" // Suspend the application
|
"<Ctrl-z>": "Suspend" // Suspend the application
|
||||||
},
|
},
|
||||||
"SelectParts": {
|
"SelectTableType": {
|
||||||
"<b>": "PrevScreen",
|
"<b>": "PrevScreen",
|
||||||
"<Enter>": "Process",
|
"<Enter>": "Process",
|
||||||
"<Up>": "KeyUp",
|
"<Up>": "KeyUp",
|
||||||
|
|
@ -44,11 +44,42 @@
|
||||||
"<Ctrl-c>": "Quit", // Yet another way to quit
|
"<Ctrl-c>": "Quit", // Yet another way to quit
|
||||||
"<Ctrl-z>": "Suspend" // Suspend the application
|
"<Ctrl-z>": "Suspend" // Suspend the application
|
||||||
},
|
},
|
||||||
|
"PreClone": {
|
||||||
|
"<Enter>": "Process",
|
||||||
|
"<q>": "Quit", // Quit the application
|
||||||
|
"<Ctrl-d>": "Quit", // Another way to quit
|
||||||
|
"<Ctrl-c>": "Quit", // Yet another way to quit
|
||||||
|
"<Ctrl-z>": "Suspend" // Suspend the application
|
||||||
|
},
|
||||||
|
"Clone": {
|
||||||
|
"<Enter>": "Process",
|
||||||
|
"<q>": "Quit", // Quit the application
|
||||||
|
"<Ctrl-d>": "Quit", // Another way to quit
|
||||||
|
"<Ctrl-c>": "Quit", // Yet another way to quit
|
||||||
|
"<Ctrl-z>": "Suspend" // Suspend the application
|
||||||
|
},
|
||||||
|
"SelectParts": {
|
||||||
|
"<Enter>": "Process",
|
||||||
|
"<Up>": "KeyUp",
|
||||||
|
"<Down>": "KeyDown",
|
||||||
|
"<q>": "Quit", // Quit the application
|
||||||
|
"<Ctrl-d>": "Quit", // Another way to quit
|
||||||
|
"<Ctrl-c>": "Quit", // Yet another way to quit
|
||||||
|
"<Ctrl-z>": "Suspend" // Suspend the application
|
||||||
|
},
|
||||||
|
"PostClone": {
|
||||||
|
"<Enter>": "Process",
|
||||||
|
"<q>": "Quit", // Quit the application
|
||||||
|
"<Ctrl-d>": "Quit", // Another way to quit
|
||||||
|
"<Ctrl-c>": "Quit", // Yet another way to quit
|
||||||
|
"<Ctrl-z>": "Suspend" // Suspend the application
|
||||||
|
},
|
||||||
"Done": {
|
"Done": {
|
||||||
"<Enter>": "Quit",
|
"<Enter>": "Quit",
|
||||||
"<q>": "Quit", // Quit the application
|
"<q>": "Quit", // Quit the application
|
||||||
"<Ctrl-d>": "Quit", // Another way to quit
|
"<Ctrl-d>": "Quit", // Another way to quit
|
||||||
"<Ctrl-c>": "Quit", // Yet another way to quit
|
"<Ctrl-c>": "Quit", // Yet another way to quit
|
||||||
|
"<Ctrl-z>": "Suspend" // Suspend the application
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,31 +19,40 @@ use strum::Display;
|
||||||
use crate::{
|
use crate::{
|
||||||
app::Mode,
|
app::Mode,
|
||||||
components::popup::Type,
|
components::popup::Type,
|
||||||
system::{disk::Disk, drivers::Driver},
|
system::{
|
||||||
|
disk::{Disk, PartitionTableType},
|
||||||
|
drivers::Driver,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)]
|
||||||
pub enum Action {
|
pub enum Action {
|
||||||
Tick,
|
// App
|
||||||
Render,
|
Command(String, String, Vec<String>), // (label, command, args)
|
||||||
Resize(u16, u16),
|
Diskpart(String, String), // (label, script_as_string)
|
||||||
Suspend,
|
|
||||||
Resume,
|
|
||||||
Quit,
|
|
||||||
ClearScreen,
|
|
||||||
DismissPopup,
|
|
||||||
DisplayPopup(Type, String),
|
|
||||||
Error(String),
|
|
||||||
Help,
|
|
||||||
InstallDriver,
|
InstallDriver,
|
||||||
SelectDriver(Driver),
|
|
||||||
KeyUp,
|
|
||||||
KeyDown,
|
|
||||||
SetMode(Mode),
|
|
||||||
PrevScreen,
|
|
||||||
NextScreen,
|
|
||||||
Process,
|
Process,
|
||||||
ScanDisks,
|
ScanDisks,
|
||||||
Select(Option<usize>, Option<usize>), // indicies for (source, dest) or (boot, os)
|
Select(Option<usize>, Option<usize>), // indicies for (source, dest) or (boot, os)
|
||||||
|
SelectDriver(Driver),
|
||||||
|
SelectTableType(PartitionTableType),
|
||||||
UpdateDiskList(Vec<Disk>),
|
UpdateDiskList(Vec<Disk>),
|
||||||
|
// Screens
|
||||||
|
DismissPopup,
|
||||||
|
DisplayPopup(Type, String),
|
||||||
|
NextScreen,
|
||||||
|
PrevScreen,
|
||||||
|
SetMode(Mode),
|
||||||
|
// TUI
|
||||||
|
ClearScreen,
|
||||||
|
Error(String),
|
||||||
|
Help,
|
||||||
|
KeyDown,
|
||||||
|
KeyUp,
|
||||||
|
Quit,
|
||||||
|
Render,
|
||||||
|
Resize(u16, u16),
|
||||||
|
Resume,
|
||||||
|
Suspend,
|
||||||
|
Tick,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
128
src/app.rs
128
src/app.rs
|
|
@ -42,27 +42,33 @@ use crate::{
|
||||||
},
|
},
|
||||||
config::Config,
|
config::Config,
|
||||||
system::{
|
system::{
|
||||||
disk::{get_disks, Disk},
|
disk::{get_disks, Disk, PartitionTableType},
|
||||||
drivers::{self, Driver},
|
drivers::{self, Driver},
|
||||||
},
|
},
|
||||||
tui::{Event, Tui},
|
tui::{Event, Tui},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
config: Config,
|
// TUI
|
||||||
tick_rate: f64,
|
action_rx: mpsc::UnboundedReceiver<Action>,
|
||||||
frame_rate: f64,
|
action_tx: mpsc::UnboundedSender<Action>,
|
||||||
components: Vec<Box<dyn Component>>,
|
components: Vec<Box<dyn Component>>,
|
||||||
disks: Arc<Mutex<Vec<Disk>>>,
|
config: Config,
|
||||||
driver: Option<Driver>,
|
frame_rate: f64,
|
||||||
|
last_tick_key_events: Vec<KeyEvent>,
|
||||||
should_quit: bool,
|
should_quit: bool,
|
||||||
should_suspend: bool,
|
should_suspend: bool,
|
||||||
|
tick_rate: f64,
|
||||||
|
// App
|
||||||
cur_mode: Mode,
|
cur_mode: Mode,
|
||||||
|
disk_dest: Option<Disk>,
|
||||||
|
disk_list: Arc<Mutex<Vec<Disk>>>,
|
||||||
|
disk_source: Option<Disk>,
|
||||||
|
driver: Option<Driver>,
|
||||||
prev_mode: Mode,
|
prev_mode: Mode,
|
||||||
selections: Vec<Option<usize>>,
|
selections: Vec<Option<usize>>,
|
||||||
last_tick_key_events: Vec<KeyEvent>,
|
table_type: Option<PartitionTableType>,
|
||||||
action_tx: mpsc::UnboundedSender<Action>,
|
task_handles: Vec<JoinHandle<()>>,
|
||||||
action_rx: mpsc::UnboundedReceiver<Action>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||||
|
|
@ -71,8 +77,12 @@ pub enum Mode {
|
||||||
ScanDisks,
|
ScanDisks,
|
||||||
InstallDrivers,
|
InstallDrivers,
|
||||||
SelectDisks,
|
SelectDisks,
|
||||||
SelectParts,
|
SelectTableType,
|
||||||
Confirm,
|
Confirm,
|
||||||
|
PreClone,
|
||||||
|
Clone,
|
||||||
|
SelectParts,
|
||||||
|
PostClone,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,8 +90,9 @@ impl App {
|
||||||
pub fn new(tick_rate: f64, frame_rate: f64) -> Result<Self> {
|
pub fn new(tick_rate: f64, frame_rate: f64) -> Result<Self> {
|
||||||
let (action_tx, action_rx) = mpsc::unbounded_channel();
|
let (action_tx, action_rx) = mpsc::unbounded_channel();
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
tick_rate,
|
// TUI
|
||||||
frame_rate,
|
action_rx,
|
||||||
|
action_tx,
|
||||||
components: vec![
|
components: vec![
|
||||||
Box::new(Title::new()),
|
Box::new(Title::new()),
|
||||||
Box::new(FpsCounter::default()),
|
Box::new(FpsCounter::default()),
|
||||||
|
|
@ -90,41 +101,56 @@ impl App {
|
||||||
Box::new(Footer::new()),
|
Box::new(Footer::new()),
|
||||||
Box::new(Popup::new()),
|
Box::new(Popup::new()),
|
||||||
],
|
],
|
||||||
disks: Arc::new(Mutex::new(Vec::new())),
|
config: Config::new()?,
|
||||||
driver: None,
|
frame_rate,
|
||||||
|
last_tick_key_events: Vec::new(),
|
||||||
should_quit: false,
|
should_quit: false,
|
||||||
should_suspend: false,
|
should_suspend: false,
|
||||||
config: Config::new()?,
|
tick_rate,
|
||||||
|
// App
|
||||||
cur_mode: Mode::ScanDisks,
|
cur_mode: Mode::ScanDisks,
|
||||||
|
disk_dest: None,
|
||||||
|
disk_list: Arc::new(Mutex::new(Vec::new())),
|
||||||
|
disk_source: None,
|
||||||
|
driver: None,
|
||||||
prev_mode: Mode::ScanDisks,
|
prev_mode: Mode::ScanDisks,
|
||||||
selections: vec![None, None],
|
selections: vec![None, None],
|
||||||
last_tick_key_events: Vec::new(),
|
table_type: None,
|
||||||
action_tx,
|
task_handles: Vec::new(),
|
||||||
action_rx,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_mode(&mut self) -> Option<Mode> {
|
pub fn next_mode(&mut self) -> Option<Mode> {
|
||||||
let new_mode = match self.cur_mode {
|
let new_mode = match (self.prev_mode, self.cur_mode) {
|
||||||
Mode::InstallDrivers => Mode::ScanDisks,
|
(_, Mode::InstallDrivers) => Mode::ScanDisks,
|
||||||
Mode::ScanDisks => Mode::SelectDisks,
|
(_, Mode::ScanDisks) => Mode::SelectDisks,
|
||||||
Mode::SelectDisks | Mode::SelectParts => {
|
(_, Mode::SelectDisks | Mode::SelectTableType | Mode::SelectParts) => {
|
||||||
if self.selections[1].is_some() {
|
if self.selections[1].is_some() {
|
||||||
Mode::Confirm
|
Mode::Confirm
|
||||||
} else {
|
} else {
|
||||||
self.cur_mode
|
self.cur_mode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mode::Done => Mode::Done,
|
(Mode::SelectDisks, Mode::Confirm) => Mode::SelectTableType,
|
||||||
Mode::Confirm => match self.prev_mode {
|
(Mode::SelectTableType, Mode::Confirm) => Mode::PreClone,
|
||||||
Mode::SelectDisks => Mode::SelectParts,
|
(_, Mode::PreClone) => Mode::Clone,
|
||||||
Mode::SelectParts => Mode::Done,
|
(_, Mode::Clone) => Mode::SelectParts,
|
||||||
_ => self.cur_mode,
|
(Mode::SelectParts, Mode::Confirm) => Mode::PostClone,
|
||||||
},
|
(_, Mode::PostClone) => Mode::Done,
|
||||||
|
(_, Mode::Done) => Mode::Done,
|
||||||
|
// Invalid states
|
||||||
|
(_, Mode::Confirm) => panic!("This shouldn't happen."),
|
||||||
};
|
};
|
||||||
|
|
||||||
if new_mode != self.cur_mode {
|
if new_mode != self.cur_mode {
|
||||||
if self.cur_mode != Mode::Confirm {
|
match self.cur_mode {
|
||||||
self.prev_mode = self.cur_mode;
|
// Update prev_mode if appropriate
|
||||||
|
Mode::Confirm => {}
|
||||||
|
Mode::PreClone | Mode::Clone | Mode::PostClone | Mode::Done => {
|
||||||
|
// Override since we're past the point of no return
|
||||||
|
self.prev_mode = self.cur_mode;
|
||||||
|
}
|
||||||
|
_ => self.prev_mode = self.cur_mode,
|
||||||
}
|
}
|
||||||
Some(new_mode)
|
Some(new_mode)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -133,8 +159,8 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run(&mut self) -> Result<()> {
|
pub async fn run(&mut self) -> Result<()> {
|
||||||
let disk_wrapper = Arc::clone(&self.disks);
|
let disk_list_arc = Arc::clone(&self.disk_list);
|
||||||
let _ = lazy_get_disks(disk_wrapper);
|
self.task_handles.push(lazy_get_disks(disk_list_arc));
|
||||||
let mut tui = Tui::new()?
|
let mut tui = Tui::new()?
|
||||||
// .mouse(true) // uncomment this line to enable mouse support
|
// .mouse(true) // uncomment this line to enable mouse support
|
||||||
.tick_rate(self.tick_rate)
|
.tick_rate(self.tick_rate)
|
||||||
|
|
@ -224,11 +250,24 @@ impl App {
|
||||||
match action {
|
match action {
|
||||||
Action::Tick => {
|
Action::Tick => {
|
||||||
self.last_tick_key_events.drain(..);
|
self.last_tick_key_events.drain(..);
|
||||||
// Continue to next screen if shared disks has been set
|
match self.cur_mode {
|
||||||
if self.cur_mode == Mode::ScanDisks {
|
Mode::ScanDisks | Mode::PreClone | Mode::Clone | Mode::PostClone => {
|
||||||
if let Ok(_) = &self.disks.try_lock() {
|
// Check background task
|
||||||
self.action_tx.send(Action::NextScreen)?;
|
if let Ok(_) = &self.disk_list.try_lock() {
|
||||||
|
if self.task_handles.is_empty() {
|
||||||
|
// All tasks complete
|
||||||
|
self.action_tx.send(Action::NextScreen)?;
|
||||||
|
} else {
|
||||||
|
// Tasks remain, check if current is complete
|
||||||
|
if let Some(handle) = self.task_handles.first() {
|
||||||
|
if handle.is_finished() {
|
||||||
|
self.task_handles.remove(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Action::Quit => self.should_quit = true,
|
Action::Quit => self.should_quit = true,
|
||||||
|
|
@ -243,6 +282,10 @@ impl App {
|
||||||
drivers::load(&driver.inf_paths);
|
drivers::load(&driver.inf_paths);
|
||||||
self.action_tx.send(Action::NextScreen)?;
|
self.action_tx.send(Action::NextScreen)?;
|
||||||
}
|
}
|
||||||
|
Action::SelectTableType(ref table_type) => {
|
||||||
|
self.table_type = Some(table_type.clone());
|
||||||
|
self.action_tx.send(Action::NextScreen)?;
|
||||||
|
}
|
||||||
Action::Resize(w, h) => self.handle_resize(tui, w, h)?,
|
Action::Resize(w, h) => self.handle_resize(tui, w, h)?,
|
||||||
Action::Render => self.render(tui)?,
|
Action::Render => self.render(tui)?,
|
||||||
Action::PrevScreen => {
|
Action::PrevScreen => {
|
||||||
|
|
@ -254,8 +297,8 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Action::ScanDisks => {
|
Action::ScanDisks => {
|
||||||
let disk_wrapper = Arc::clone(&self.disks);
|
let disk_list_arc = Arc::clone(&self.disk_list);
|
||||||
let _ = lazy_get_disks(disk_wrapper);
|
self.task_handles.push(lazy_get_disks(disk_list_arc));
|
||||||
self.action_tx.send(Action::SetMode(Mode::ScanDisks))?;
|
self.action_tx.send(Action::SetMode(Mode::ScanDisks))?;
|
||||||
}
|
}
|
||||||
Action::Select(one, two) => {
|
Action::Select(one, two) => {
|
||||||
|
|
@ -269,8 +312,9 @@ impl App {
|
||||||
self.prev_mode = self.cur_mode;
|
self.prev_mode = self.cur_mode;
|
||||||
}
|
}
|
||||||
Mode::SelectDisks | Mode::SelectParts => {
|
Mode::SelectDisks | Mode::SelectParts => {
|
||||||
let disks = self.disks.lock().unwrap();
|
let disk_list = self.disk_list.lock().unwrap();
|
||||||
self.action_tx.send(Action::UpdateDiskList(disks.clone()))?;
|
self.action_tx
|
||||||
|
.send(Action::UpdateDiskList(disk_list.clone()))?;
|
||||||
}
|
}
|
||||||
Mode::Done => {
|
Mode::Done => {
|
||||||
self.action_tx.send(Action::DisplayPopup(
|
self.action_tx.send(Action::DisplayPopup(
|
||||||
|
|
@ -373,9 +417,9 @@ fn get_chunks(r: Rect) -> Vec<Rect> {
|
||||||
chunks
|
chunks
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lazy_get_disks(disk_wrapper: Arc<Mutex<Vec<Disk>>>) -> JoinHandle<()> {
|
fn lazy_get_disks(disk_list_arc: Arc<Mutex<Vec<Disk>>>) -> JoinHandle<()> {
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let mut disks = disk_wrapper.lock().unwrap();
|
let mut disks = disk_list_arc.lock().unwrap();
|
||||||
*disks = get_disks();
|
*disks = get_disks();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,16 +57,22 @@ impl Component for Footer {
|
||||||
}
|
}
|
||||||
Action::SetMode(new_mode) => {
|
Action::SetMode(new_mode) => {
|
||||||
self.footer_text = match new_mode {
|
self.footer_text = match new_mode {
|
||||||
|
Mode::ScanDisks => String::from("(q) to quit"),
|
||||||
|
Mode::InstallDrivers
|
||||||
|
| Mode::PreClone
|
||||||
|
| Mode::Clone
|
||||||
|
| Mode::PostClone
|
||||||
|
| Mode::SelectParts => String::from("(Enter) to select / (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 => {
|
Mode::Confirm => {
|
||||||
String::from("(Enter) to confirm / (b) to go back / (q) to quit")
|
String::from("(Enter) to confirm / (b) to go back / (q) to quit")
|
||||||
}
|
}
|
||||||
Mode::Done => String::from("(Enter) or (q) to quit"),
|
Mode::Done => String::from("(Enter) or (q) to quit"),
|
||||||
Mode::InstallDrivers => String::from("(Enter) to select / (q) to quit"),
|
|
||||||
Mode::ScanDisks => String::from("(q) to quit"),
|
|
||||||
Mode::SelectDisks => String::from(
|
|
||||||
"(Enter) to select / / (i) to install driver / (r) to rescan / (q) to quit",
|
|
||||||
),
|
|
||||||
_ => String::from("(Enter) to select / (b) to go back / (q) to quit"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ use crate::{
|
||||||
app::Mode,
|
app::Mode,
|
||||||
config::Config,
|
config::Config,
|
||||||
system::{
|
system::{
|
||||||
disk::{Disk, Partition},
|
disk::{Disk, Partition, PartitionTableType},
|
||||||
drivers::{self, Driver},
|
drivers::{self, Driver},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -37,6 +37,7 @@ pub struct Left {
|
||||||
list_disks: StatefulList<Disk>,
|
list_disks: StatefulList<Disk>,
|
||||||
list_drivers: StatefulList<Driver>,
|
list_drivers: StatefulList<Driver>,
|
||||||
list_parts: StatefulList<Partition>,
|
list_parts: StatefulList<Partition>,
|
||||||
|
list_table_types: StatefulList<PartitionTableType>,
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
selections: Vec<Option<usize>>,
|
selections: Vec<Option<usize>>,
|
||||||
}
|
}
|
||||||
|
|
@ -76,20 +77,38 @@ impl Component for Left {
|
||||||
Action::Render => {
|
Action::Render => {
|
||||||
// add any logic here that should run on every render
|
// add any logic here that should run on every render
|
||||||
}
|
}
|
||||||
Action::KeyUp => self.list_disks.previous(),
|
Action::KeyUp => match self.mode {
|
||||||
Action::KeyDown => self.list_disks.next(),
|
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 {
|
Action::Process => match self.mode {
|
||||||
Mode::Confirm => {
|
// NOTE: Remove all variants except Mode::Confirm?
|
||||||
|
// Mode::Confirm => {
|
||||||
|
Mode::Confirm | Mode::PreClone | Mode::Clone | Mode::PostClone => {
|
||||||
if let Some(command_tx) = self.command_tx.clone() {
|
if let Some(command_tx) = self.command_tx.clone() {
|
||||||
command_tx.send(Action::NextScreen)?;
|
command_tx.send(Action::NextScreen)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mode::InstallDrivers | Mode::SelectDisks | Mode::SelectParts => {
|
Mode::InstallDrivers
|
||||||
|
| Mode::SelectDisks
|
||||||
|
| Mode::SelectTableType
|
||||||
|
| Mode::SelectParts => {
|
||||||
// Menu selection sections
|
// Menu selection sections
|
||||||
let selection: Option<usize>;
|
let selection: Option<usize>;
|
||||||
match self.mode {
|
match self.mode {
|
||||||
Mode::InstallDrivers => selection = self.list_drivers.state.selected(),
|
Mode::InstallDrivers => selection = self.list_drivers.state.selected(),
|
||||||
Mode::SelectDisks => selection = self.list_disks.state.selected(),
|
Mode::SelectDisks => selection = self.list_disks.state.selected(),
|
||||||
|
Mode::SelectTableType => selection = self.list_table_types.state.selected(),
|
||||||
Mode::SelectParts => selection = self.list_parts.state.selected(),
|
Mode::SelectParts => selection = self.list_parts.state.selected(),
|
||||||
_ => panic!("This shouldn't happen!"),
|
_ => panic!("This shouldn't happen!"),
|
||||||
}
|
}
|
||||||
|
|
@ -122,6 +141,12 @@ impl Component for Left {
|
||||||
command_tx.send(Action::SelectDriver(driver.clone()))?;
|
command_tx.send(Action::SelectDriver(driver.clone()))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Mode::SelectTableType => {
|
||||||
|
// Only need to select one entry
|
||||||
|
if let Some(table_type) = self.list_table_types.pop_selected() {
|
||||||
|
command_tx.send(Action::SelectTableType(table_type))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
Mode::SelectDisks | Mode::SelectParts => {
|
Mode::SelectDisks | Mode::SelectParts => {
|
||||||
command_tx
|
command_tx
|
||||||
.send(Action::Select(selection_one, selection_two))?;
|
.send(Action::Select(selection_one, selection_two))?;
|
||||||
|
|
@ -142,8 +167,12 @@ impl Component for Left {
|
||||||
Action::SetMode(new_mode) => {
|
Action::SetMode(new_mode) => {
|
||||||
let prev_mode = self.mode;
|
let prev_mode = self.mode;
|
||||||
self.mode = new_mode;
|
self.mode = new_mode;
|
||||||
match new_mode {
|
match (prev_mode, new_mode) {
|
||||||
Mode::InstallDrivers => {
|
(_, Mode::ScanDisks) => {
|
||||||
|
self.list_disks.clear_items();
|
||||||
|
self.title_text = String::from("");
|
||||||
|
}
|
||||||
|
(_, Mode::InstallDrivers) => {
|
||||||
self.list_drivers.set_items(drivers::scan());
|
self.list_drivers.set_items(drivers::scan());
|
||||||
self.selections[0] = None;
|
self.selections[0] = None;
|
||||||
self.selections[1] = None;
|
self.selections[1] = None;
|
||||||
|
|
@ -157,11 +186,7 @@ impl Component for Left {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mode::ScanDisks => {
|
(_, Mode::SelectDisks) => {
|
||||||
self.list_disks.clear_items();
|
|
||||||
self.title_text = String::from("");
|
|
||||||
}
|
|
||||||
Mode::SelectDisks => {
|
|
||||||
self.selections[0] = None;
|
self.selections[0] = None;
|
||||||
self.selections[1] = None;
|
self.selections[1] = None;
|
||||||
self.title_text = String::from("Select Source and Destination Disks");
|
self.title_text = String::from("Select Source and Destination Disks");
|
||||||
|
|
@ -169,20 +194,31 @@ impl Component for Left {
|
||||||
command_tx.send(Action::DismissPopup)?;
|
command_tx.send(Action::DismissPopup)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mode::SelectParts => {
|
(_, 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) => {
|
||||||
|
// TODO: Get list of partitions
|
||||||
self.selections[0] = None;
|
self.selections[0] = None;
|
||||||
self.selections[1] = None;
|
self.selections[1] = None;
|
||||||
self.title_text = String::from("Select Boot and OS Partitions")
|
self.title_text = String::from("Select Boot and OS Partitions")
|
||||||
}
|
}
|
||||||
Mode::Confirm => match prev_mode {
|
(Mode::SelectDisks | Mode::SelectParts, Mode::Confirm) => {
|
||||||
Mode::SelectDisks => self.title_text = String::from("Confirm Selections"),
|
self.title_text = String::from("Confirm Selections")
|
||||||
Mode::SelectParts => {
|
}
|
||||||
self.title_text = String::from("Confirm Selections (Again)")
|
(Mode::SelectTableType, Mode::Confirm) => {
|
||||||
}
|
self.title_text = String::from("Confirm Selections (Again)")
|
||||||
_ => {}
|
}
|
||||||
},
|
(_, Mode::Done) => self.title_text = String::from("Done"),
|
||||||
|
// Invalid states
|
||||||
Mode::Done => self.title_text = String::from("Done"),
|
(_, Mode::Confirm) => panic!("This shouldn't happen."),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Action::UpdateDiskList(disks) => self.list_disks.set_items(disks),
|
Action::UpdateDiskList(disks) => self.list_disks.set_items(disks),
|
||||||
|
|
@ -203,82 +239,111 @@ impl Component for Left {
|
||||||
.block(Block::default().borders(Borders::NONE));
|
.block(Block::default().borders(Borders::NONE));
|
||||||
frame.render_widget(title, title_area);
|
frame.render_widget(title, title_area);
|
||||||
|
|
||||||
// Body (scan disks)
|
// Body
|
||||||
if self.list_disks.items.is_empty() {
|
match self.mode {
|
||||||
let paragraph = Paragraph::new(String::new()).block(
|
Mode::ScanDisks | Mode::PreClone | Mode::Clone | Mode::PostClone | Mode::Done => {
|
||||||
Block::default()
|
// Leave blank
|
||||||
.borders(Borders::ALL)
|
let paragraph = Paragraph::new(String::new()).block(
|
||||||
.padding(Padding::new(1, 1, 1, 1)),
|
|
||||||
);
|
|
||||||
frame.render_widget(paragraph, body_area);
|
|
||||||
|
|
||||||
// Bail early
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Body (confirm)
|
|
||||||
if self.mode == Mode::Confirm {
|
|
||||||
let paragraph = Paragraph::new(String::from("Are the listed selections correct?"))
|
|
||||||
.block(
|
|
||||||
Block::default()
|
Block::default()
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.padding(Padding::new(1, 1, 1, 1)),
|
.padding(Padding::new(1, 1, 1, 1)),
|
||||||
);
|
);
|
||||||
frame.render_widget(paragraph, body_area);
|
frame.render_widget(paragraph, body_area);
|
||||||
|
|
||||||
// Bail early
|
// Bail early
|
||||||
return Ok(());
|
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);
|
||||||
|
|
||||||
// Body (list)
|
// Bail early
|
||||||
let mut list_items = Vec::<ListItem>::new();
|
return Ok(());
|
||||||
let list_items_strings: Vec<String> = match self.mode {
|
}
|
||||||
Mode::InstallDrivers => self
|
Mode::InstallDrivers
|
||||||
.list_drivers
|
| Mode::SelectDisks
|
||||||
.items
|
| Mode::SelectTableType
|
||||||
.iter()
|
| Mode::SelectParts => {
|
||||||
.map(|i| format!("{i}"))
|
// List modes
|
||||||
.collect(),
|
let mut list_items = Vec::<ListItem>::new();
|
||||||
Mode::SelectDisks => self
|
let list_items_strings: Vec<String> = match self.mode {
|
||||||
.list_disks
|
Mode::InstallDrivers => self
|
||||||
.items
|
.list_drivers
|
||||||
.iter()
|
.items
|
||||||
.map(|i| format!("{i}"))
|
.iter()
|
||||||
.collect(),
|
.map(|i| format!("{i}"))
|
||||||
Mode::SelectParts => self
|
.collect(),
|
||||||
.list_parts
|
Mode::SelectDisks => self
|
||||||
.items
|
.list_disks
|
||||||
.iter()
|
.items
|
||||||
.map(|i| format!("{i}"))
|
.iter()
|
||||||
.collect(),
|
.map(|i| format!("{i}"))
|
||||||
_ => panic!("This shouldn't happen."),
|
.collect(),
|
||||||
};
|
Mode::SelectTableType => self
|
||||||
if !list_items_strings.is_empty() {
|
.list_table_types
|
||||||
for (index, item) in list_items_strings.iter().enumerate() {
|
.items
|
||||||
let mut item_style = Style::default();
|
.iter()
|
||||||
let mut item_text_tail = "";
|
.map(|i| format!("{i}"))
|
||||||
if let Some(selection_one) = self.selections[0] {
|
.collect(),
|
||||||
if selection_one == index {
|
Mode::SelectParts => self
|
||||||
item_style = Style::new().yellow();
|
.list_parts
|
||||||
item_text_tail = " ~already selected~";
|
.items
|
||||||
|
.iter()
|
||||||
|
.map(|i| format!("{i}"))
|
||||||
|
.collect(),
|
||||||
|
_ => panic!("This shouldn't happen."),
|
||||||
|
};
|
||||||
|
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 = " ~already selected~";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list_items.push(
|
||||||
|
ListItem::new(format!(" {item}\n{item_text_tail}\n\n"))
|
||||||
|
.style(item_style),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
list_items.push(
|
let list = List::new(list_items)
|
||||||
ListItem::new(format!(" {item}\n{item_text_tail}\n\n")).style(item_style),
|
.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."),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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_disks.state);
|
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue