Compare commits
15 commits
f6d01068a3
...
6b2eb8155f
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b2eb8155f | |||
| e26a83299c | |||
| 14a8ea7429 | |||
| 6ea2df892f | |||
| 5343912699 | |||
| e029e02cc2 | |||
| a77bf0c9c6 | |||
| 3c0c12fa7a | |||
| 9d6fa954b2 | |||
| 253385c2a7 | |||
| fc0b82418b | |||
| 608f07d445 | |||
| 828a2736be | |||
| 81aa7a8984 | |||
| da1892710f |
40 changed files with 1827 additions and 1556 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
||||||
/target
|
/target
|
||||||
|
/*/target
|
||||||
.data/*.log
|
.data/*.log
|
||||||
|
|
|
||||||
1331
Cargo.lock
generated
1331
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -14,6 +14,6 @@
|
||||||
# along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
# along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["deja_vu", "pe_menu"]
|
members = ["core", "deja_vu", "pe_menu"]
|
||||||
description = "Clone/Install Windows, create/edit boot files, and troubleshoot boot issues."
|
default-members = ["deja_vu", "pe_menu"]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
|
"app_title": "Deja-vu: Clone Tool",
|
||||||
"clone_app_path": "C:/Program Files/Some Clone Tool/app.exe",
|
"clone_app_path": "C:/Program Files/Some Clone Tool/app.exe",
|
||||||
"keybindings": {
|
"keybindings": {
|
||||||
"ScanDisks": {
|
"ScanDisks": {
|
||||||
63
core/Cargo.toml
Normal file
63
core/Cargo.toml
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
# This file is part of Deja-vu.
|
||||||
|
#
|
||||||
|
# Deja-vu is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Deja-vu is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
# See the GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "core"
|
||||||
|
authors = ["2Shirt <2xShirt@gmail.com>"]
|
||||||
|
edition = "2021"
|
||||||
|
license = "GPL"
|
||||||
|
version = "0.2.0"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
better-panic = "0.3.0"
|
||||||
|
clap = { version = "4.4.5", features = [
|
||||||
|
"derive",
|
||||||
|
"cargo",
|
||||||
|
"wrap_help",
|
||||||
|
"unicode",
|
||||||
|
"string",
|
||||||
|
"unstable-styles",
|
||||||
|
] }
|
||||||
|
color-eyre = "0.6.3"
|
||||||
|
config = "0.15.6"
|
||||||
|
crossterm = { version = "0.28.1", features = ["serde", "event-stream"] }
|
||||||
|
derive_deref = "1.1.1"
|
||||||
|
directories = "6.0.0"
|
||||||
|
futures = "0.3.30"
|
||||||
|
human-panic = "2.0.1"
|
||||||
|
json5 = "0.4.1"
|
||||||
|
lazy_static = "1.5.0"
|
||||||
|
libc = "0.2.158"
|
||||||
|
once_cell = "1.20.2"
|
||||||
|
pretty_assertions = "1.4.0"
|
||||||
|
ratatui = { version = "0.29.0", features = ["serde", "macros"] }
|
||||||
|
raw-cpuid = "11.2.0"
|
||||||
|
regex = "1.11.1"
|
||||||
|
serde = { version = "1.0.217", features = ["derive"] }
|
||||||
|
serde_json = "1.0.125"
|
||||||
|
signal-hook = "0.3.17"
|
||||||
|
strip-ansi-escapes = "0.2.0"
|
||||||
|
strum = { version = "0.26.3", features = ["derive"] }
|
||||||
|
tempfile = "3.13.0"
|
||||||
|
tokio = { version = "1.43.0", features = ["full"] }
|
||||||
|
tokio-util = "0.7.11"
|
||||||
|
tracing = "0.1.41"
|
||||||
|
tracing-error = "0.2.0"
|
||||||
|
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "serde"] }
|
||||||
|
walkdir = "2.5.0"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
anyhow = "1.0.86"
|
||||||
|
vergen-gix = { version = "1.0.0", features = ["build", "cargo"] }
|
||||||
28
core/build.rs
Normal file
28
core/build.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
// This file is part of Deja-vu.
|
||||||
|
//
|
||||||
|
// Deja-vu is free software: you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Deja-vu is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
// See the GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
use anyhow::Result;
|
||||||
|
use vergen_gix::{BuildBuilder, CargoBuilder, Emitter, GixBuilder};
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
let build = BuildBuilder::all_build()?;
|
||||||
|
let gix = GixBuilder::all_git()?;
|
||||||
|
let cargo = CargoBuilder::all_cargo()?;
|
||||||
|
Emitter::default()
|
||||||
|
.add_instructions(&build)?
|
||||||
|
.add_instructions(&gix)?
|
||||||
|
.add_instructions(&cargo)?
|
||||||
|
.emit()
|
||||||
|
}
|
||||||
|
|
@ -16,25 +16,21 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum::Display;
|
use strum::Display;
|
||||||
|
|
||||||
use crate::{
|
use crate::{components::popup::Type, line::DVLine, state::Mode, system::disk::Disk};
|
||||||
app::Mode,
|
|
||||||
components::popup::Type,
|
|
||||||
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 {
|
||||||
// App
|
// App
|
||||||
|
Highlight(usize),
|
||||||
InstallDriver,
|
InstallDriver,
|
||||||
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) etc
|
||||||
SelectDriver(Driver),
|
SelectRight(Option<usize>, Option<usize>), // indicies for right info pane
|
||||||
SelectTableType(PartitionTableType),
|
|
||||||
UpdateDiskList(Vec<Disk>),
|
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
|
||||||
// Screens
|
// Screens
|
||||||
DismissPopup,
|
DismissPopup,
|
||||||
DisplayPopup(Type, String),
|
DisplayPopup(Type, String),
|
||||||
|
|
@ -21,7 +21,7 @@ use ratatui::{
|
||||||
use tokio::sync::mpsc::UnboundedSender;
|
use tokio::sync::mpsc::UnboundedSender;
|
||||||
|
|
||||||
use super::Component;
|
use super::Component;
|
||||||
use crate::{action::Action, app::Mode, config::Config};
|
use crate::{action::Action, config::Config};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Footer {
|
pub struct Footer {
|
||||||
|
|
@ -51,25 +51,9 @@ impl Component for Footer {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||||
if let Action::SetMode(new_mode) = action {
|
match action {
|
||||||
self.text = match new_mode {
|
Action::UpdateFooter(text) => self.text = text,
|
||||||
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)
|
Ok(None)
|
||||||
}
|
}
|
||||||
206
core/src/components/left.rs
Normal file
206
core/src/components/left.rs
Normal file
|
|
@ -0,0 +1,206 @@
|
||||||
|
// This file is part of Deja-vu.
|
||||||
|
//
|
||||||
|
// Deja-vu is free software: you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Deja-vu is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
// See the GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
use color_eyre::Result;
|
||||||
|
use crossterm::event::KeyEvent;
|
||||||
|
use ratatui::{
|
||||||
|
prelude::*,
|
||||||
|
widgets::{Block, Borders, HighlightSpacing, List, ListItem, Padding, Paragraph},
|
||||||
|
};
|
||||||
|
use tokio::sync::mpsc::UnboundedSender;
|
||||||
|
|
||||||
|
use super::{state::StatefulList, Component};
|
||||||
|
use crate::{action::Action, config::Config};
|
||||||
|
|
||||||
|
#[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>>,
|
||||||
|
title_text: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
fn handle_key_event(&mut self, key: KeyEvent) -> Result<Option<Action>> {
|
||||||
|
let _ = key; // to appease clippy
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn register_action_handler(&mut self, tx: UnboundedSender<Action>) -> Result<()> {
|
||||||
|
self.command_tx = Some(tx);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
||||||
|
self.config = config;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
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)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(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)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
||||||
|
let [title_area, body_area] = Layout::default()
|
||||||
|
.direction(Direction::Vertical)
|
||||||
|
.constraints([Constraint::Length(1), Constraint::Min(1)])
|
||||||
|
.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())
|
||||||
|
.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 {
|
||||||
|
""
|
||||||
|
};
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Done
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -23,7 +23,7 @@ use strum::Display;
|
||||||
use tokio::sync::mpsc::UnboundedSender;
|
use tokio::sync::mpsc::UnboundedSender;
|
||||||
|
|
||||||
use super::Component;
|
use super::Component;
|
||||||
use crate::{action::Action, app::Mode, config::Config};
|
use crate::{action::Action, config::Config};
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)]
|
#[derive(Default, Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)]
|
||||||
pub enum Type {
|
pub enum Type {
|
||||||
|
|
@ -37,7 +37,6 @@ pub enum Type {
|
||||||
pub struct Popup {
|
pub struct Popup {
|
||||||
command_tx: Option<UnboundedSender<Action>>,
|
command_tx: Option<UnboundedSender<Action>>,
|
||||||
config: Config,
|
config: Config,
|
||||||
mode: Mode,
|
|
||||||
popup_type: Type,
|
popup_type: Type,
|
||||||
popup_text: String,
|
popup_text: String,
|
||||||
}
|
}
|
||||||
|
|
@ -69,12 +68,6 @@ impl Component for Popup {
|
||||||
self.popup_type = new_type;
|
self.popup_type = new_type;
|
||||||
self.popup_text = new_text;
|
self.popup_text = new_text;
|
||||||
}
|
}
|
||||||
Action::SetMode(mode) => {
|
|
||||||
if mode == Mode::ScanDisks {
|
|
||||||
self.popup_text = String::from("Scanning Disks...");
|
|
||||||
}
|
|
||||||
self.mode = mode;
|
|
||||||
}
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
198
core/src/components/right.rs
Normal file
198
core/src/components/right.rs
Normal file
|
|
@ -0,0 +1,198 @@
|
||||||
|
// This file is part of Deja-vu.
|
||||||
|
//
|
||||||
|
// Deja-vu is free software: you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Deja-vu is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
// See the GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
use color_eyre::Result;
|
||||||
|
use crossterm::event::KeyEvent;
|
||||||
|
use ratatui::{
|
||||||
|
prelude::*,
|
||||||
|
widgets::{Block, Borders, Padding, Paragraph, Wrap},
|
||||||
|
};
|
||||||
|
use tokio::sync::mpsc::UnboundedSender;
|
||||||
|
|
||||||
|
use super::{state::StatefulList, Component};
|
||||||
|
use crate::{action::Action, config::Config, line::DVLine};
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct Right {
|
||||||
|
command_tx: Option<UnboundedSender<Action>>,
|
||||||
|
config: Config,
|
||||||
|
list_header: Vec<DVLine>,
|
||||||
|
list_labels: Vec<Vec<DVLine>>,
|
||||||
|
list: StatefulList<Vec<DVLine>>,
|
||||||
|
selections: Vec<Option<usize>>,
|
||||||
|
selections_saved: Vec<Option<usize>>,
|
||||||
|
title: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
fn handle_key_event(&mut self, key: KeyEvent) -> Result<Option<Action>> {
|
||||||
|
let _ = key; // to appease clippy
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn register_action_handler(&mut self, tx: UnboundedSender<Action>) -> Result<()> {
|
||||||
|
self.command_tx = Some(tx);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
||||||
|
self.config = config;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
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(_) => {
|
||||||
|
self.selections[0] = None;
|
||||||
|
self.selections[1] = None;
|
||||||
|
self.selections_saved[0] = None;
|
||||||
|
self.selections_saved[1] = None;
|
||||||
|
}
|
||||||
|
Action::UpdateRight(labels, 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());
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
||||||
|
let [title_area, body_area] = Layout::default()
|
||||||
|
.direction(Direction::Vertical)
|
||||||
|
.constraints([Constraint::Length(1), Constraint::Min(1)])
|
||||||
|
.areas(area);
|
||||||
|
|
||||||
|
// Title
|
||||||
|
let title = Paragraph::new(Line::from(self.title.as_str()).centered())
|
||||||
|
.block(Block::default().borders(Borders::NONE));
|
||||||
|
frame.render_widget(title, title_area);
|
||||||
|
|
||||||
|
// Body
|
||||||
|
let mut body_text: Vec<Line> = Vec::new();
|
||||||
|
if !self.list_header.is_empty() {
|
||||||
|
// Static Header
|
||||||
|
self.list_header
|
||||||
|
.iter()
|
||||||
|
.for_each(|dv| body_text.push(dv.as_line()));
|
||||||
|
body_text.push(Line::from(""));
|
||||||
|
body_text.push(Line::from(str::repeat("─", (body_area.width - 4) as usize)));
|
||||||
|
body_text.push(Line::from(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
// First selection
|
||||||
|
if let Some(first_index) = self.get_first() {
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second selection
|
||||||
|
if let Some(second_index) = self.get_second() {
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build Paragraph
|
||||||
|
let body = Paragraph::new(body_text)
|
||||||
|
.style(Style::default().fg(Color::Gray))
|
||||||
|
.wrap(Wrap { trim: false })
|
||||||
|
.block(
|
||||||
|
Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.padding(Padding::new(1, 1, 1, 1)),
|
||||||
|
);
|
||||||
|
frame.render_widget(body, body_area);
|
||||||
|
|
||||||
|
// Done
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -56,7 +56,7 @@ impl Component for Title {
|
||||||
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
||||||
// Title Block
|
// Title Block
|
||||||
let title_text = Span::styled(
|
let title_text = Span::styled(
|
||||||
"WizardKit: Clone Tool",
|
self.config.app_title.as_str(),
|
||||||
Style::default().fg(Color::LightCyan),
|
Style::default().fg(Color::LightCyan),
|
||||||
);
|
);
|
||||||
let title = Paragraph::new(Line::from(title_text).centered())
|
let title = Paragraph::new(Line::from(title_text).centered())
|
||||||
|
|
@ -26,9 +26,9 @@ use ratatui::style::{Color, Modifier, Style};
|
||||||
use serde::{de::Deserializer, Deserialize};
|
use serde::{de::Deserializer, Deserialize};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
use crate::{action::Action, app::Mode};
|
use crate::{action::Action, state::Mode};
|
||||||
|
|
||||||
const CONFIG: &str = include_str!("../config/config.json5");
|
const CONFIG: &str = include_str!("../../config/config.json5");
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Default)]
|
#[derive(Clone, Debug, Deserialize, Default)]
|
||||||
pub struct AppConfig {
|
pub struct AppConfig {
|
||||||
|
|
@ -40,6 +40,8 @@ pub struct AppConfig {
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize)]
|
#[derive(Clone, Debug, Default, Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
#[serde(default)]
|
||||||
|
pub app_title: String,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub clone_app_path: PathBuf,
|
pub clone_app_path: PathBuf,
|
||||||
#[serde(default, flatten)]
|
#[serde(default, flatten)]
|
||||||
|
|
@ -50,14 +52,15 @@ pub struct Config {
|
||||||
pub styles: Styles,
|
pub styles: Styles,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub static PROJECT_NAME: &'static str = "DEJA-VU";
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref PROJECT_NAME: String = env!("CARGO_CRATE_NAME").to_uppercase().to_string();
|
//pub static ref PROJECT_NAME: String = env!("CARGO_PKG_NAME").to_uppercase().to_string();
|
||||||
pub static ref DATA_FOLDER: Option<PathBuf> =
|
pub static ref DATA_FOLDER: Option<PathBuf> =
|
||||||
env::var(format!("{}_DATA", PROJECT_NAME.clone()))
|
env::var(format!("{}_DATA", PROJECT_NAME))
|
||||||
.ok()
|
.ok()
|
||||||
.map(PathBuf::from);
|
.map(PathBuf::from);
|
||||||
pub static ref CONFIG_FOLDER: Option<PathBuf> =
|
pub static ref CONFIG_FOLDER: Option<PathBuf> =
|
||||||
env::var(format!("{}_CONFIG", PROJECT_NAME.clone()))
|
env::var(format!("{}_CONFIG", PROJECT_NAME))
|
||||||
.ok()
|
.ok()
|
||||||
.map(PathBuf::from);
|
.map(PathBuf::from);
|
||||||
}
|
}
|
||||||
|
|
@ -68,12 +71,13 @@ impl Config {
|
||||||
let data_dir = get_data_dir();
|
let data_dir = get_data_dir();
|
||||||
let config_dir = get_config_dir();
|
let config_dir = get_config_dir();
|
||||||
let mut builder = config::Config::builder()
|
let mut builder = config::Config::builder()
|
||||||
.set_default("data_dir", data_dir.to_str().unwrap())?
|
.set_default("app_title", default_config.app_title.as_str())?
|
||||||
.set_default("config_dir", config_dir.to_str().unwrap())?
|
|
||||||
.set_default(
|
.set_default(
|
||||||
"clone_app_path",
|
"clone_app_path",
|
||||||
String::from("C:\\Program Files\\Some Clone Tool\\app.exe"),
|
String::from("C:\\Program Files\\Some Clone Tool\\app.exe"),
|
||||||
)?;
|
)?
|
||||||
|
.set_default("config_dir", config_dir.to_str().unwrap())?
|
||||||
|
.set_default("data_dir", data_dir.to_str().unwrap())?;
|
||||||
|
|
||||||
let config_files = [
|
let config_files = [
|
||||||
("config.json5", config::FileFormat::Json5),
|
("config.json5", config::FileFormat::Json5),
|
||||||
|
|
@ -95,7 +99,6 @@ impl Config {
|
||||||
if !found_config {
|
if !found_config {
|
||||||
error!("No configuration file found. Application may not behave as expected");
|
error!("No configuration file found. Application may not behave as expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cfg: Self = builder.build()?.try_deserialize()?;
|
let mut cfg: Self = builder.build()?.try_deserialize()?;
|
||||||
|
|
||||||
for (mode, default_bindings) in default_config.keybindings.iter() {
|
for (mode, default_bindings) in default_config.keybindings.iter() {
|
||||||
|
|
@ -140,7 +143,8 @@ pub fn get_config_dir() -> PathBuf {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn project_directory() -> Option<ProjectDirs> {
|
fn project_directory() -> Option<ProjectDirs> {
|
||||||
ProjectDirs::from("com", "WizardKit", env!("CARGO_PKG_NAME"))
|
ProjectDirs::from("com", "Deja-vu", "deja-vu")
|
||||||
|
//ProjectDirs::from("com", "Deja-vu", env!("CARGO_PKG_NAME"))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deref, DerefMut)]
|
#[derive(Clone, Debug, Default, Deref, DerefMut)]
|
||||||
26
core/src/lib.rs
Normal file
26
core/src/lib.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
// This file is part of Deja-vu.
|
||||||
|
//
|
||||||
|
// Deja-vu is free software: you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Deja-vu is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
// See the GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
pub mod action;
|
||||||
|
pub mod cli;
|
||||||
|
pub mod components;
|
||||||
|
pub mod config;
|
||||||
|
pub mod errors;
|
||||||
|
pub mod line;
|
||||||
|
pub mod logging;
|
||||||
|
pub mod state;
|
||||||
|
pub mod system;
|
||||||
|
pub mod tasks;
|
||||||
|
pub mod tui;
|
||||||
94
core/src/line.rs
Normal file
94
core/src/line.rs
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
// This file is part of Deja-vu.
|
||||||
|
//
|
||||||
|
// Deja-vu is free software: you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Deja-vu is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
// See the GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
use ratatui::{
|
||||||
|
style::{Color, Style},
|
||||||
|
text::{Line, Span},
|
||||||
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::iter::zip;
|
||||||
|
|
||||||
|
use crate::system::disk::{Disk, Partition};
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
pub struct DVLine {
|
||||||
|
pub line_parts: Vec<String>,
|
||||||
|
pub line_colors: Vec<Color>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DVLine {
|
||||||
|
/// Convert to Line with colored span(s)
|
||||||
|
pub fn as_line(&self) -> Line {
|
||||||
|
let mut spans = Vec::new();
|
||||||
|
zip(self.line_parts.clone(), self.line_colors.clone())
|
||||||
|
.for_each(|(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) -> Vec<DVLine> {
|
||||||
|
let mut description: Vec<DVLine> = vec![
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_part_description(part: &Partition) -> Vec<DVLine> {
|
||||||
|
let description: Vec<DVLine> = vec![
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
@ -20,8 +20,9 @@ use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
||||||
use crate::config;
|
use crate::config;
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
pub static ref LOG_ENV: String = format!("{}_LOG_LEVEL", config::PROJECT_NAME.clone());
|
pub static ref LOG_ENV: String = format!("{}_LOG_LEVEL", config::PROJECT_NAME);
|
||||||
pub static ref LOG_FILE: String = format!("{}.log", env!("CARGO_PKG_NAME"));
|
pub static ref LOG_FILE: String = format!("{}.log", config::PROJECT_NAME);
|
||||||
|
//pub static ref LOG_FILE: String = format!("{}.log", env!("CARGO_PKG_NAME"));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init() -> Result<()> {
|
pub fn init() -> Result<()> {
|
||||||
65
core/src/state.rs
Normal file
65
core/src/state.rs
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
// This file is part of Deja-vu.
|
||||||
|
//
|
||||||
|
// Deja-vu is free software: you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Deja-vu is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
// See the GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::system::{
|
||||||
|
disk::{Disk, PartitionTableType},
|
||||||
|
drivers,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||||
|
pub enum Mode {
|
||||||
|
#[default]
|
||||||
|
ScanDisks,
|
||||||
|
InstallDrivers,
|
||||||
|
SelectDisks,
|
||||||
|
SelectTableType,
|
||||||
|
Confirm,
|
||||||
|
PreClone,
|
||||||
|
Clone,
|
||||||
|
SelectParts,
|
||||||
|
PostClone,
|
||||||
|
Done,
|
||||||
|
Failed,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
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 table_type: Option<PartitionTableType>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CloneSettings {
|
||||||
|
pub fn new(disk_list: Arc<Mutex<Vec<Disk>>>) -> Self {
|
||||||
|
CloneSettings {
|
||||||
|
disk_list,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn scan_drivers(&mut self) {
|
||||||
|
self.driver_list = drivers::scan();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
export DEJA_VU_CONFIG=`pwd`/config
|
|
||||||
export DEJA_VU_DATA=`pwd`/data
|
|
||||||
export DEJA_VU_LOG_LEVEL=debug
|
|
||||||
|
|
@ -16,51 +16,31 @@
|
||||||
[package]
|
[package]
|
||||||
name = "deja-vu"
|
name = "deja-vu"
|
||||||
authors = ["2Shirt <2xShirt@gmail.com>"]
|
authors = ["2Shirt <2xShirt@gmail.com>"]
|
||||||
description = "Clone Windows."
|
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "GPL"
|
license = "GPL"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
better-panic = "0.3.0"
|
core = { path = "../core" }
|
||||||
clap = { version = "4.4.5", features = [
|
|
||||||
"derive",
|
|
||||||
"cargo",
|
|
||||||
"wrap_help",
|
|
||||||
"unicode",
|
|
||||||
"string",
|
|
||||||
"unstable-styles",
|
|
||||||
] }
|
|
||||||
color-eyre = "0.6.3"
|
color-eyre = "0.6.3"
|
||||||
config = "0.14.0"
|
clap = { version = "4.4.5", features = [
|
||||||
crossterm = { version = "0.28.1", features = ["serde", "event-stream"] }
|
"derive",
|
||||||
derive_deref = "1.1.1"
|
"cargo",
|
||||||
directories = "5.0.1"
|
"wrap_help",
|
||||||
futures = "0.3.30"
|
"unicode",
|
||||||
human-panic = "2.0.1"
|
"string",
|
||||||
json5 = "0.4.1"
|
"unstable-styles",
|
||||||
lazy_static = "1.5.0"
|
] }
|
||||||
libc = "0.2.158"
|
ratatui = { version = "0.29.0", features = ["serde", "macros"] }
|
||||||
once_cell = "1.20.2"
|
serde = { version = "1.0.217", features = ["derive"] }
|
||||||
pretty_assertions = "1.4.0"
|
|
||||||
ratatui = { version = "0.28.1", features = ["serde", "macros"] }
|
|
||||||
raw-cpuid = "11.2.0"
|
|
||||||
regex = "1.11.1"
|
|
||||||
serde = { version = "1.0.208", features = ["derive"] }
|
|
||||||
serde_json = "1.0.125"
|
serde_json = "1.0.125"
|
||||||
signal-hook = "0.3.17"
|
tokio = { version = "1.43.0", features = ["full"] }
|
||||||
strip-ansi-escapes = "0.2.0"
|
|
||||||
strum = { version = "0.26.3", features = ["derive"] }
|
|
||||||
tempfile = "3.13.0"
|
|
||||||
tokio = { version = "1.39.3", features = ["full"] }
|
|
||||||
tokio-util = "0.7.11"
|
tokio-util = "0.7.11"
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.41"
|
||||||
tracing-error = "0.2.0"
|
tracing-error = "0.2.0"
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "serde"] }
|
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "serde"] }
|
||||||
walkdir = "2.5.0"
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
anyhow = "1.0.86"
|
anyhow = "1.0.86"
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,23 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
use core::{
|
||||||
|
action::Action,
|
||||||
|
components::{
|
||||||
|
footer::Footer, fps::FpsCounter, left::Left, popup, right::Right, state::StatefulList,
|
||||||
|
title::Title, Component,
|
||||||
|
},
|
||||||
|
config::Config,
|
||||||
|
line::{get_disk_description_right, get_part_description, DVLine},
|
||||||
|
state::{CloneSettings, Mode},
|
||||||
|
system::{
|
||||||
|
boot, cpu::get_cpu_name, disk::PartitionTableType, diskpart::build_dest_format_script,
|
||||||
|
drivers,
|
||||||
|
},
|
||||||
|
tasks::{Task, Tasks},
|
||||||
|
tui::{Event, Tui},
|
||||||
|
};
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
env,
|
||||||
iter::zip,
|
iter::zip,
|
||||||
|
|
@ -20,31 +37,15 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use crossterm::event::KeyEvent;
|
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
|
crossterm::event::KeyEvent,
|
||||||
layout::{Constraint, Direction, Layout},
|
layout::{Constraint, Direction, Layout},
|
||||||
prelude::Rect,
|
prelude::Rect,
|
||||||
|
style::Color,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
|
|
||||||
use crate::{
|
|
||||||
action::Action,
|
|
||||||
components::{
|
|
||||||
footer::Footer, fps::FpsCounter, left::Left, popup, right::Right, title::Title, Component,
|
|
||||||
},
|
|
||||||
config::Config,
|
|
||||||
system::{
|
|
||||||
boot,
|
|
||||||
disk::{Disk, PartitionTableType},
|
|
||||||
diskpart::build_dest_format_script,
|
|
||||||
drivers::{self, Driver},
|
|
||||||
},
|
|
||||||
tasks::{Task, Tasks},
|
|
||||||
tui::{Event, Tui},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
// TUI
|
// TUI
|
||||||
action_rx: mpsc::UnboundedReceiver<Action>,
|
action_rx: mpsc::UnboundedReceiver<Action>,
|
||||||
|
|
@ -57,35 +58,14 @@ pub struct App {
|
||||||
should_suspend: bool,
|
should_suspend: bool,
|
||||||
tick_rate: f64,
|
tick_rate: f64,
|
||||||
// App
|
// App
|
||||||
|
clone: CloneSettings,
|
||||||
cur_mode: Mode,
|
cur_mode: Mode,
|
||||||
disk_index_dest: Option<usize>,
|
list: StatefulList<usize>,
|
||||||
disk_index_source: Option<usize>,
|
|
||||||
disk_list: Arc<Mutex<Vec<Disk>>>,
|
|
||||||
part_index_boot: Option<usize>,
|
|
||||||
part_index_os: Option<usize>,
|
|
||||||
driver: Option<Driver>,
|
|
||||||
prev_mode: Mode,
|
prev_mode: Mode,
|
||||||
selections: Vec<Option<usize>>,
|
selections: Vec<Option<usize>>,
|
||||||
table_type: Option<PartitionTableType>,
|
|
||||||
tasks: Tasks,
|
tasks: Tasks,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
||||||
pub enum Mode {
|
|
||||||
#[default]
|
|
||||||
ScanDisks,
|
|
||||||
InstallDrivers,
|
|
||||||
SelectDisks,
|
|
||||||
SelectTableType,
|
|
||||||
Confirm,
|
|
||||||
PreClone,
|
|
||||||
Clone,
|
|
||||||
SelectParts,
|
|
||||||
PostClone,
|
|
||||||
Done,
|
|
||||||
Failed,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl App {
|
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();
|
||||||
|
|
@ -111,54 +91,51 @@ impl App {
|
||||||
should_suspend: false,
|
should_suspend: false,
|
||||||
tick_rate,
|
tick_rate,
|
||||||
// App
|
// App
|
||||||
|
clone: CloneSettings::new(disk_list_arc),
|
||||||
cur_mode: Mode::ScanDisks,
|
cur_mode: Mode::ScanDisks,
|
||||||
disk_index_dest: None,
|
list: StatefulList::default(),
|
||||||
disk_index_source: None,
|
|
||||||
disk_list: disk_list_arc,
|
|
||||||
driver: None,
|
|
||||||
part_index_boot: None,
|
|
||||||
part_index_os: None,
|
|
||||||
prev_mode: Mode::ScanDisks,
|
prev_mode: Mode::ScanDisks,
|
||||||
selections: vec![None, None],
|
selections: vec![None, None],
|
||||||
table_type: None,
|
|
||||||
tasks,
|
tasks,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 next_mode(&mut self) -> Option<Mode> {
|
pub fn next_mode(&mut self) -> Option<Mode> {
|
||||||
let new_mode = match (self.prev_mode, self.cur_mode) {
|
let new_mode = match self.cur_mode {
|
||||||
(_, Mode::InstallDrivers) => Mode::ScanDisks,
|
Mode::InstallDrivers => Mode::ScanDisks,
|
||||||
(_, Mode::ScanDisks) => Mode::SelectDisks,
|
Mode::ScanDisks => Mode::SelectDisks,
|
||||||
(_, Mode::SelectDisks | Mode::SelectTableType | Mode::SelectParts) => {
|
Mode::SelectDisks => Mode::SelectTableType,
|
||||||
if self.selections[1].is_some() {
|
Mode::SelectTableType => Mode::Confirm,
|
||||||
Mode::Confirm
|
Mode::Confirm => Mode::PreClone,
|
||||||
} else {
|
Mode::PreClone => Mode::Clone,
|
||||||
self.cur_mode
|
Mode::Clone => Mode::SelectParts,
|
||||||
}
|
Mode::SelectParts => Mode::PostClone,
|
||||||
}
|
Mode::PostClone | Mode::Done => Mode::Done,
|
||||||
(Mode::SelectDisks, Mode::Confirm) => Mode::SelectTableType,
|
Mode::Failed => Mode::Failed,
|
||||||
(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."),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if new_mode == self.cur_mode {
|
if new_mode == self.cur_mode {
|
||||||
|
// No mode change needed
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
match 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -167,11 +144,16 @@ impl App {
|
||||||
info!("Setting mode to {new_mode:?}");
|
info!("Setting mode to {new_mode:?}");
|
||||||
self.cur_mode = new_mode;
|
self.cur_mode = new_mode;
|
||||||
match new_mode {
|
match new_mode {
|
||||||
|
Mode::InstallDrivers => self.clone.scan_drivers(),
|
||||||
Mode::ScanDisks => {
|
Mode::ScanDisks => {
|
||||||
self.prev_mode = self.cur_mode;
|
self.prev_mode = self.cur_mode;
|
||||||
if self.tasks.idle() {
|
if self.tasks.idle() {
|
||||||
self.tasks.add(Task::ScanDisks);
|
self.tasks.add(Task::ScanDisks);
|
||||||
}
|
}
|
||||||
|
self.action_tx.send(Action::DisplayPopup(
|
||||||
|
popup::Type::Info,
|
||||||
|
String::from("Scanning Disks..."),
|
||||||
|
))?;
|
||||||
}
|
}
|
||||||
Mode::PreClone => {
|
Mode::PreClone => {
|
||||||
self.action_tx.send(Action::DisplayPopup(
|
self.action_tx.send(Action::DisplayPopup(
|
||||||
|
|
@ -180,10 +162,10 @@ impl App {
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
// Build Diskpart script to format destination disk
|
// Build Diskpart script to format destination disk
|
||||||
let disk_list = self.disk_list.lock().unwrap();
|
let disk_list = self.clone.disk_list.lock().unwrap();
|
||||||
if let Some(disk_index) = self.disk_index_dest {
|
if let Some(disk_index) = self.clone.disk_index_dest {
|
||||||
if let Some(disk) = disk_list.get(disk_index) {
|
if let Some(disk) = disk_list.get(disk_index) {
|
||||||
let table_type = self.table_type.clone().unwrap();
|
let table_type = self.clone.table_type.clone().unwrap();
|
||||||
let diskpart_script = build_dest_format_script(disk.id, &table_type);
|
let diskpart_script = build_dest_format_script(disk.id, &table_type);
|
||||||
self.tasks.add(Task::Diskpart(diskpart_script));
|
self.tasks.add(Task::Diskpart(diskpart_script));
|
||||||
}
|
}
|
||||||
|
|
@ -198,7 +180,7 @@ impl App {
|
||||||
self.config.clone_app_path.clone(),
|
self.config.clone_app_path.clone(),
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
));
|
));
|
||||||
if let Some(dest_index) = self.disk_index_dest {
|
if let Some(dest_index) = self.clone.disk_index_dest {
|
||||||
self.tasks.add(Task::UpdateDestDisk(dest_index));
|
self.tasks.add(Task::UpdateDestDisk(dest_index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -223,12 +205,12 @@ impl App {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add actions
|
// Add actions
|
||||||
let disk_list = self.disk_list.lock().unwrap();
|
let disk_list = self.clone.disk_list.lock().unwrap();
|
||||||
if let Some(disk_index) = self.disk_index_dest {
|
if let Some(disk_index) = self.clone.disk_index_dest {
|
||||||
if let Some(disk) = disk_list.get(disk_index) {
|
if let Some(disk) = disk_list.get(disk_index) {
|
||||||
let table_type = self.table_type.clone().unwrap();
|
let table_type = self.clone.table_type.clone().unwrap();
|
||||||
let letter_boot = disk.get_part_letter(self.part_index_boot.unwrap());
|
let letter_boot = disk.get_part_letter(self.clone.part_index_boot.unwrap());
|
||||||
let letter_os = disk.get_part_letter(self.part_index_os.unwrap());
|
let letter_os = disk.get_part_letter(self.clone.part_index_os.unwrap());
|
||||||
|
|
||||||
// Safety check
|
// Safety check
|
||||||
if letter_boot.is_empty() || letter_os.is_empty() {
|
if letter_boot.is_empty() || letter_os.is_empty() {
|
||||||
|
|
@ -246,8 +228,8 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject driver(s) (if selected)
|
// Inject driver(s) (if selected)
|
||||||
if let Some(driver) = &self.driver {
|
if let Some(driver) = &self.clone.driver {
|
||||||
if let Ok(task) = boot::inject_driver(&driver, &letter_os, &system32) {
|
if let Ok(task) = boot::inject_driver(driver, &letter_os, &system32) {
|
||||||
self.tasks.add(task);
|
self.tasks.add(task);
|
||||||
} else {
|
} else {
|
||||||
self.action_tx.send(Action::Error(format!(
|
self.action_tx.send(Action::Error(format!(
|
||||||
|
|
@ -369,6 +351,8 @@ impl App {
|
||||||
Action::Suspend => self.should_suspend = true,
|
Action::Suspend => self.should_suspend = true,
|
||||||
Action::Resume => self.should_suspend = false,
|
Action::Resume => self.should_suspend = false,
|
||||||
Action::ClearScreen => tui.terminal.clear()?,
|
Action::ClearScreen => tui.terminal.clear()?,
|
||||||
|
Action::KeyUp => self.list.previous(),
|
||||||
|
Action::KeyDown => self.list.next(),
|
||||||
Action::Error(ref msg) => {
|
Action::Error(ref msg) => {
|
||||||
self.action_tx
|
self.action_tx
|
||||||
.send(Action::DisplayPopup(popup::Type::Error, msg.clone()))?;
|
.send(Action::DisplayPopup(popup::Type::Error, msg.clone()))?;
|
||||||
|
|
@ -377,47 +361,108 @@ impl App {
|
||||||
Action::InstallDriver => {
|
Action::InstallDriver => {
|
||||||
self.action_tx.send(Action::SetMode(Mode::InstallDrivers))?;
|
self.action_tx.send(Action::SetMode(Mode::InstallDrivers))?;
|
||||||
}
|
}
|
||||||
Action::SelectDriver(ref driver) => {
|
Action::Process => match self.cur_mode {
|
||||||
self.driver = Some(driver.clone());
|
Mode::Confirm => {
|
||||||
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 => {
|
||||||
let new_mode = match (self.prev_mode, self.cur_mode) {
|
if let Some(new_mode) = self.prev_mode() {
|
||||||
(Mode::SelectTableType, Mode::SelectTableType) => Mode::SelectDisks,
|
self.prev_mode = new_mode;
|
||||||
(_, _) => self.prev_mode,
|
self.cur_mode = new_mode;
|
||||||
};
|
self.action_tx.send(Action::SetMode(new_mode))?;
|
||||||
self.action_tx.send(Action::SetMode(new_mode))?;
|
|
||||||
}
|
|
||||||
Action::NextScreen => {
|
|
||||||
if let Some(mode) = self.next_mode() {
|
|
||||||
self.action_tx.send(Action::DismissPopup)?;
|
|
||||||
self.action_tx.send(Action::SetMode(mode))?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Action::NextScreen => match self.next_mode() {
|
||||||
|
None => {}
|
||||||
|
Some(next) => {
|
||||||
|
self.prev_mode = self.cur_mode;
|
||||||
|
self.cur_mode = next;
|
||||||
|
self.action_tx.send(Action::DismissPopup)?;
|
||||||
|
self.action_tx.send(Action::SetMode(next))?;
|
||||||
|
}
|
||||||
|
},
|
||||||
Action::ScanDisks => self.action_tx.send(Action::SetMode(Mode::ScanDisks))?,
|
Action::ScanDisks => self.action_tx.send(Action::SetMode(Mode::ScanDisks))?,
|
||||||
Action::Select(one, two) => {
|
Action::Select(one, two) => {
|
||||||
match self.cur_mode {
|
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 => {
|
Mode::SelectDisks => {
|
||||||
self.disk_index_source = one;
|
self.clone.disk_index_source = one;
|
||||||
self.disk_index_dest = two;
|
self.clone.disk_index_dest = two;
|
||||||
}
|
}
|
||||||
Mode::SelectParts => {
|
Mode::SelectParts => {
|
||||||
self.part_index_boot = one;
|
self.clone.part_index_boot = one;
|
||||||
self.part_index_os = two;
|
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;
|
self.selections[0] = one;
|
||||||
self.selections[1] = two;
|
self.selections[1] = two;
|
||||||
}
|
}
|
||||||
Action::SetMode(new_mode) => self.set_mode(new_mode)?,
|
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))?;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
for component in &mut self.components {
|
for component in &mut self.components {
|
||||||
|
|
@ -509,3 +554,146 @@ fn get_chunks(r: Rect) -> Vec<Rect> {
|
||||||
// Done
|
// Done
|
||||||
chunks
|
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();
|
||||||
|
let mut start_index = 0;
|
||||||
|
match cur_mode {
|
||||||
|
Mode::InstallDrivers => {
|
||||||
|
items.push(vec![DVLine {
|
||||||
|
line_parts: vec![String::from("CPU")],
|
||||||
|
line_colors: vec![Color::Cyan],
|
||||||
|
}]);
|
||||||
|
items.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]);
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
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));
|
||||||
|
|
||||||
|
// Partition Details
|
||||||
|
disk.parts
|
||||||
|
.iter()
|
||||||
|
.for_each(|part| items.push(get_part_description(&part)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
(labels, start_index, items)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,389 +0,0 @@
|
||||||
// This file is part of Deja-vu.
|
|
||||||
//
|
|
||||||
// Deja-vu is free software: you can redistribute it and/or modify it
|
|
||||||
// under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// Deja-vu is distributed in the hope that it will be useful, but
|
|
||||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
// See the GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
use color_eyre::Result;
|
|
||||||
use crossterm::event::KeyEvent;
|
|
||||||
use ratatui::{
|
|
||||||
prelude::*,
|
|
||||||
widgets::{Block, Borders, HighlightSpacing, List, ListItem, Padding, Paragraph},
|
|
||||||
};
|
|
||||||
use tokio::sync::mpsc::UnboundedSender;
|
|
||||||
use tracing::info;
|
|
||||||
|
|
||||||
use super::{popup, state::StatefulList, Component};
|
|
||||||
use crate::{
|
|
||||||
action::Action,
|
|
||||||
app::Mode,
|
|
||||||
config::Config,
|
|
||||||
system::{
|
|
||||||
disk::{Disk, Partition, PartitionTableType},
|
|
||||||
drivers::{self, Driver},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct Left {
|
|
||||||
command_tx: Option<UnboundedSender<Action>>,
|
|
||||||
config: Config,
|
|
||||||
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 {
|
|
||||||
selections: vec![None, None],
|
|
||||||
title_text: String::from("Home"),
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for Left {
|
|
||||||
fn handle_key_event(&mut self, key: KeyEvent) -> Result<Option<Action>> {
|
|
||||||
let _ = key; // to appease clippy
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_action_handler(&mut self, tx: UnboundedSender<Action>) -> Result<()> {
|
|
||||||
self.command_tx = Some(tx);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
|
||||||
self.config = config;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
|
||||||
match action {
|
|
||||||
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"),
|
|
||||||
))?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(_, 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
|
||||||
let [title_area, body_area] = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.constraints([Constraint::Length(1), Constraint::Min(1)])
|
|
||||||
.areas(area);
|
|
||||||
|
|
||||||
// Title
|
|
||||||
let title =
|
|
||||||
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
|
|
||||||
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."),
|
|
||||||
};
|
|
||||||
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(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,401 +0,0 @@
|
||||||
// This file is part of Deja-vu.
|
|
||||||
//
|
|
||||||
// Deja-vu is free software: you can redistribute it and/or modify it
|
|
||||||
// under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// Deja-vu is distributed in the hope that it will be useful, but
|
|
||||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
// See the GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
use color_eyre::Result;
|
|
||||||
use crossterm::event::KeyEvent;
|
|
||||||
use ratatui::{
|
|
||||||
prelude::*,
|
|
||||||
widgets::{Block, Borders, Padding, Paragraph, Wrap},
|
|
||||||
};
|
|
||||||
use tokio::sync::mpsc::UnboundedSender;
|
|
||||||
use tracing::info;
|
|
||||||
|
|
||||||
use super::{state::StatefulList, Component};
|
|
||||||
use crate::{
|
|
||||||
action::Action,
|
|
||||||
app::Mode,
|
|
||||||
config::Config,
|
|
||||||
system::{
|
|
||||||
cpu::get_cpu_name,
|
|
||||||
disk::{Disk, Partition, PartitionTableType},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct Right {
|
|
||||||
command_tx: Option<UnboundedSender<Action>>,
|
|
||||||
config: Config,
|
|
||||||
cur_mode: Mode,
|
|
||||||
list_disks: StatefulList<Disk>,
|
|
||||||
list_parts: StatefulList<Partition>,
|
|
||||||
prev_mode: Mode,
|
|
||||||
selected_disks: Vec<Option<usize>>,
|
|
||||||
selections: Vec<Option<usize>>,
|
|
||||||
table_type: Option<PartitionTableType>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Right {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
selected_disks: vec![None, None],
|
|
||||||
selections: vec![None, None],
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for Right {
|
|
||||||
fn handle_key_event(&mut self, key: KeyEvent) -> Result<Option<Action>> {
|
|
||||||
let _ = key; // to appease clippy
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_action_handler(&mut self, tx: UnboundedSender<Action>) -> Result<()> {
|
|
||||||
self.command_tx = Some(tx);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
|
||||||
self.config = config;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
|
||||||
match action {
|
|
||||||
Action::KeyUp => match self.cur_mode {
|
|
||||||
Mode::SelectDisks => self.list_disks.previous(),
|
|
||||||
Mode::SelectParts => self.list_parts.previous(),
|
|
||||||
_ => {}
|
|
||||||
},
|
|
||||||
Action::KeyDown => match self.cur_mode {
|
|
||||||
Mode::SelectDisks => self.list_disks.next(),
|
|
||||||
Mode::SelectParts => self.list_parts.next(),
|
|
||||||
_ => {}
|
|
||||||
},
|
|
||||||
Action::Process => {
|
|
||||||
if self.prev_mode == Mode::SelectDisks && self.cur_mode == Mode::Confirm {
|
|
||||||
self.selected_disks = self.selections.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Action::Select(one, two) => {
|
|
||||||
self.selections[0] = one;
|
|
||||||
self.selections[1] = two;
|
|
||||||
}
|
|
||||||
Action::SelectTableType(table_type) => self.table_type = Some(table_type),
|
|
||||||
Action::SetMode(new_mode) => {
|
|
||||||
self.prev_mode = self.cur_mode;
|
|
||||||
self.cur_mode = new_mode;
|
|
||||||
match self.cur_mode {
|
|
||||||
Mode::SelectDisks => {
|
|
||||||
self.selections[0] = None;
|
|
||||||
self.selections[1] = None;
|
|
||||||
self.selected_disks[0] = None;
|
|
||||||
self.selected_disks[1] = None;
|
|
||||||
}
|
|
||||||
Mode::SelectParts => {
|
|
||||||
self.selections[0] = None;
|
|
||||||
self.selections[1] = None;
|
|
||||||
}
|
|
||||||
Mode::SelectTableType => {
|
|
||||||
self.selections[0] = None;
|
|
||||||
self.selections[1] = None;
|
|
||||||
self.table_type = None;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
|
||||||
let [title_area, body_area] = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.constraints([Constraint::Length(1), Constraint::Min(1)])
|
|
||||||
.areas(area);
|
|
||||||
|
|
||||||
// Title
|
|
||||||
let title_text = String::from("Info");
|
|
||||||
let title = Paragraph::new(Line::from(title_text).centered())
|
|
||||||
.block(Block::default().borders(Borders::NONE));
|
|
||||||
frame.render_widget(title, title_area);
|
|
||||||
|
|
||||||
// Body
|
|
||||||
let mut body_text = Vec::new();
|
|
||||||
match (self.prev_mode, self.cur_mode) {
|
|
||||||
(_, Mode::InstallDrivers) => {
|
|
||||||
body_text.push(Line::from(Span::raw(format!("CPU: {}", get_cpu_name()))));
|
|
||||||
}
|
|
||||||
(_, Mode::SelectDisks | Mode::SelectTableType)
|
|
||||||
| (Mode::SelectDisks | Mode::SelectTableType, Mode::Confirm) => {
|
|
||||||
// Source Disk
|
|
||||||
body_text.push(Line::from(Span::styled(
|
|
||||||
"Source:",
|
|
||||||
Style::default().cyan().bold(),
|
|
||||||
)));
|
|
||||||
body_text.push(Line::from(""));
|
|
||||||
body_text.push(Line::from(Span::styled(
|
|
||||||
format!(
|
|
||||||
"{:<8} {:>11} {:<4} {:<4} {}",
|
|
||||||
"Disk ID", "Size", "Conn", "Type", "Model (Serial)"
|
|
||||||
),
|
|
||||||
Style::new().green().bold(),
|
|
||||||
)));
|
|
||||||
let index = if self.selected_disks[0].is_some() {
|
|
||||||
// Selected in prior mode
|
|
||||||
self.selected_disks[0]
|
|
||||||
} else if self.selections[0].is_some() {
|
|
||||||
// Selected in this mode
|
|
||||||
self.selections[0]
|
|
||||||
} else {
|
|
||||||
// Highlighted entry
|
|
||||||
self.list_disks.selected()
|
|
||||||
};
|
|
||||||
if let Some(i) = index {
|
|
||||||
if let Some(disk) = self.list_disks.get(i) {
|
|
||||||
body_text.push(Line::from(Span::raw(&disk.description)));
|
|
||||||
|
|
||||||
// Source parts
|
|
||||||
body_text.push(Line::from(""));
|
|
||||||
body_text.push(Line::from(Span::styled(
|
|
||||||
format!(
|
|
||||||
"{:<8} {:>11} {:<7} {}",
|
|
||||||
"Part ID", "Size", "(FS)", "\"Label\""
|
|
||||||
),
|
|
||||||
Style::new().blue().bold(),
|
|
||||||
)));
|
|
||||||
for line in &disk.parts_description {
|
|
||||||
body_text.push(Line::from(Span::raw(line)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destination Disk
|
|
||||||
let index = if self.selected_disks[1].is_some() {
|
|
||||||
// Selected in prior mode
|
|
||||||
self.selected_disks[1]
|
|
||||||
} else {
|
|
||||||
// Select(ed) in this mode
|
|
||||||
match (self.selections[0], self.selections[1]) {
|
|
||||||
(Some(one), None) => {
|
|
||||||
// First selected
|
|
||||||
if let Some(two) = self.selections[1] {
|
|
||||||
if one == two {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
self.selections[1]
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
self.list_disks.selected()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(Some(_), Some(_)) => {
|
|
||||||
// Both selected
|
|
||||||
self.selections[1]
|
|
||||||
}
|
|
||||||
(_, _) => None,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if let Some(i) = 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(""));
|
|
||||||
|
|
||||||
// Disk
|
|
||||||
if let Some(disk) = self.list_disks.get(i) {
|
|
||||||
body_text.push(Line::from(vec![
|
|
||||||
Span::styled("Dest:", Style::default().cyan().bold()),
|
|
||||||
Span::styled(
|
|
||||||
" (WARNING: ALL DATA WILL BE DELETED!)",
|
|
||||||
Style::default().red().bold(),
|
|
||||||
),
|
|
||||||
]));
|
|
||||||
if let Some(table_type) = &self.table_type {
|
|
||||||
body_text.push(Line::from(Span::styled(
|
|
||||||
format!(" (Will be formatted {table_type})"),
|
|
||||||
Style::default().yellow().bold(),
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
body_text.push(Line::from(""));
|
|
||||||
body_text.push(Line::from(Span::styled(
|
|
||||||
format!(
|
|
||||||
"{:<8} {:>11} {:<4} {:<4} {}",
|
|
||||||
"Disk ID", "Size", "Conn", "Type", "Model (Serial)"
|
|
||||||
),
|
|
||||||
Style::new().green().bold(),
|
|
||||||
)));
|
|
||||||
body_text.push(Line::from(Span::raw(&disk.description)));
|
|
||||||
|
|
||||||
// Destination parts
|
|
||||||
body_text.push(Line::from(""));
|
|
||||||
body_text.push(Line::from(Span::styled(
|
|
||||||
format!(
|
|
||||||
"{:<8} {:>11} {:<7} {}",
|
|
||||||
"Part ID", "Size", "(FS)", "\"Label\""
|
|
||||||
),
|
|
||||||
Style::new().blue().bold(),
|
|
||||||
)));
|
|
||||||
for line in &disk.parts_description {
|
|
||||||
body_text.push(Line::from(Span::raw(line)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(_, Mode::SelectParts) | (Mode::SelectParts, Mode::Confirm) => {
|
|
||||||
// Disk
|
|
||||||
if let Some(index) = self.selected_disks[1] {
|
|
||||||
if let Some(disk) = self.list_disks.get(index) {
|
|
||||||
body_text.push(Line::from(Span::styled(
|
|
||||||
"Dest:",
|
|
||||||
Style::default().cyan().bold(),
|
|
||||||
)));
|
|
||||||
body_text.push(Line::from(""));
|
|
||||||
body_text.push(Line::from(Span::styled(
|
|
||||||
format!(
|
|
||||||
"{:<8} {:>11} {:<4} {:<4} {}",
|
|
||||||
"Disk ID", "Size", "Conn", "Type", "Model (Serial)"
|
|
||||||
),
|
|
||||||
Style::new().green().bold(),
|
|
||||||
)));
|
|
||||||
body_text.push(Line::from(Span::raw(&disk.description)));
|
|
||||||
|
|
||||||
// Destination parts
|
|
||||||
body_text.push(Line::from(""));
|
|
||||||
body_text.push(Line::from(Span::styled(
|
|
||||||
format!(
|
|
||||||
"{:<8} {:>11} {:<7} {}",
|
|
||||||
"Part ID", "Size", "(FS)", "\"Label\""
|
|
||||||
),
|
|
||||||
Style::new().blue().bold(),
|
|
||||||
)));
|
|
||||||
for line in &disk.parts_description {
|
|
||||||
body_text.push(Line::from(Span::raw(line)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Divider
|
|
||||||
body_text.push(Line::from(""));
|
|
||||||
body_text.push(Line::from(str::repeat("─", (body_area.width - 4) as usize)));
|
|
||||||
body_text.push(Line::from(""));
|
|
||||||
|
|
||||||
// Boot Partition
|
|
||||||
// i.e. either the previously selected part or the highlighted one (if possible)
|
|
||||||
let mut boot_index = self.selections[0];
|
|
||||||
if boot_index.is_none() {
|
|
||||||
if let Some(i) = self.list_parts.selected() {
|
|
||||||
boot_index = Some(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(i) = boot_index {
|
|
||||||
if let Some(part) = self.list_parts.get(i) {
|
|
||||||
body_text.push(Line::from(Span::styled(
|
|
||||||
"Boot:",
|
|
||||||
Style::default().cyan().bold(),
|
|
||||||
)));
|
|
||||||
body_text.push(Line::from(""));
|
|
||||||
body_text.push(Line::from(Span::styled(
|
|
||||||
format!(
|
|
||||||
"{:<8} {:>11} {:<7} {}",
|
|
||||||
"Part ID", "Size", "(FS)", "\"Label\""
|
|
||||||
),
|
|
||||||
Style::new().blue().bold(),
|
|
||||||
)));
|
|
||||||
body_text.push(Line::from(Span::raw(format!("{part}"))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// OS Partition
|
|
||||||
// i.e. either the previously selected part or the highlighted one (if needed)
|
|
||||||
let mut os_index = self.selections[1];
|
|
||||||
if os_index.is_none() {
|
|
||||||
if let Some(boot_index) = self.selections[0] {
|
|
||||||
if let Some(i) = self.list_parts.selected() {
|
|
||||||
if boot_index != i {
|
|
||||||
os_index = Some(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(i) = os_index {
|
|
||||||
if let Some(part) = self.list_parts.get(i) {
|
|
||||||
body_text.push(Line::from(""));
|
|
||||||
body_text.push(Line::from(Span::styled(
|
|
||||||
"OS:",
|
|
||||||
Style::default().cyan().bold(),
|
|
||||||
)));
|
|
||||||
body_text.push(Line::from(""));
|
|
||||||
body_text.push(Line::from(Span::styled(
|
|
||||||
format!(
|
|
||||||
"{:<8} {:>11} {:<7} {}",
|
|
||||||
"Part ID", "Size", "(FS)", "\"Label\""
|
|
||||||
),
|
|
||||||
Style::new().blue().bold(),
|
|
||||||
)));
|
|
||||||
body_text.push(Line::from(Span::raw(format!("{part}"))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
let body = Paragraph::new(body_text)
|
|
||||||
.style(Style::default().fg(Color::Gray))
|
|
||||||
.wrap(Wrap { trim: false })
|
|
||||||
.block(
|
|
||||||
Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.padding(Padding::new(1, 1, 1, 1)),
|
|
||||||
);
|
|
||||||
frame.render_widget(body, body_area);
|
|
||||||
|
|
||||||
// Done
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -14,29 +14,19 @@
|
||||||
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
||||||
//
|
//
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use cli::Cli;
|
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
|
use core;
|
||||||
|
|
||||||
use crate::app::App;
|
use crate::app::App;
|
||||||
|
|
||||||
mod action;
|
|
||||||
mod app;
|
mod app;
|
||||||
mod cli;
|
|
||||||
mod components;
|
|
||||||
mod config;
|
|
||||||
mod errors;
|
|
||||||
mod logging;
|
|
||||||
mod system;
|
|
||||||
mod tasks;
|
|
||||||
mod tests;
|
|
||||||
mod tui;
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
crate::errors::init()?;
|
core::errors::init()?;
|
||||||
crate::logging::init()?;
|
core::logging::init()?;
|
||||||
|
|
||||||
let args = Cli::parse();
|
let args = core::cli::Cli::parse();
|
||||||
let mut app = App::new(args.tick_rate, args.frame_rate)?;
|
let mut app = App::new(args.tick_rate, args.frame_rate)?;
|
||||||
app.run().await?;
|
app.run().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -16,15 +16,14 @@
|
||||||
[package]
|
[package]
|
||||||
name = "pe-menu"
|
name = "pe-menu"
|
||||||
authors = ["2Shirt <2xShirt@gmail.com>"]
|
authors = ["2Shirt <2xShirt@gmail.com>"]
|
||||||
description = "Menu for WinPE."
|
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "GPL"
|
license = "GPL"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
crossterm = { version = "0.27.0", features = ["event-stream"] }
|
crossterm = { version = "0.28.1", features = ["event-stream"] }
|
||||||
futures = "0.3.30"
|
futures = "0.3.30"
|
||||||
ratatui = "0.26.0"
|
ratatui = "0.29.0"
|
||||||
serde = { version = "1.0.202", features = ["derive"] }
|
serde = { version = "1.0.217", features = ["derive"] }
|
||||||
tokio = { version = "1.35.1", features = ["full"] }
|
tokio = { version = "1.43.0", features = ["full"] }
|
||||||
toml = "0.8.13"
|
toml = "0.8.13"
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,10 @@ pub fn render(app: &mut App, frame: &mut Frame) {
|
||||||
Constraint::Min(1),
|
Constraint::Min(1),
|
||||||
Constraint::Length(3),
|
Constraint::Length(3),
|
||||||
])
|
])
|
||||||
.split(frame.size());
|
.split(frame.area());
|
||||||
|
|
||||||
// Title Block
|
// Title Block
|
||||||
let title_text = Span::styled("WizardKit: PE Menu", Style::default().fg(Color::LightCyan));
|
let title_text = Span::styled("Deja-vu: PE Menu", Style::default().fg(Color::LightCyan));
|
||||||
let title = Paragraph::new(Line::from(title_text).centered())
|
let title = Paragraph::new(Line::from(title_text).centered())
|
||||||
.block(Block::default().borders(Borders::ALL));
|
.block(Block::default().borders(Borders::ALL));
|
||||||
frame.render_widget(title, chunks[0]);
|
frame.render_widget(title, chunks[0]);
|
||||||
|
|
@ -120,7 +120,7 @@ fn render_popup_pane(frame: &mut Frame, app: &mut App) {
|
||||||
.block(popup_block)
|
.block(popup_block)
|
||||||
.centered()
|
.centered()
|
||||||
.wrap(Wrap { trim: false });
|
.wrap(Wrap { trim: false });
|
||||||
let area = centered_rect(60, 25, frame.size());
|
let area = centered_rect(60, 25, frame.area());
|
||||||
frame.render_widget(Clear, area);
|
frame.render_widget(Clear, area);
|
||||||
frame.render_widget(scan_paragraph, area);
|
frame.render_widget(scan_paragraph, area);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue