Compare commits
6 commits
9d6fa954b2
...
528140b0e9
| Author | SHA1 | Date | |
|---|---|---|---|
| 528140b0e9 | |||
| a8597a22a6 | |||
| 843e46fc86 | |||
| 2abd6c6582 | |||
| 86b1f34330 | |||
| 353f2d5570 |
5 changed files with 349 additions and 308 deletions
|
|
@ -18,6 +18,7 @@ use strum::Display;
|
|||
|
||||
use crate::{
|
||||
components::popup::Type,
|
||||
line::DVLine,
|
||||
state::Mode,
|
||||
system::{
|
||||
disk::{Disk, PartitionTableType},
|
||||
|
|
@ -35,6 +36,8 @@ pub enum Action {
|
|||
SelectDriver(Driver),
|
||||
SelectTableType(PartitionTableType),
|
||||
UpdateDiskList(Vec<Disk>),
|
||||
UpdateLeft(usize, Vec<Vec<DVLine>>), // (start_index, lines) - lines before start are always shown
|
||||
UpdateRight(usize, Vec<Vec<DVLine>>), // Same as above
|
||||
// Screens
|
||||
DismissPopup,
|
||||
DisplayPopup(Type, String),
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ use crossterm::event::KeyEvent;
|
|||
use ratatui::{
|
||||
layout::{Constraint, Direction, Layout},
|
||||
prelude::Rect,
|
||||
style::Color,
|
||||
};
|
||||
use tokio::sync::mpsc;
|
||||
use tracing::{debug, info};
|
||||
|
|
@ -32,14 +33,15 @@ use tracing::{debug, info};
|
|||
use crate::{
|
||||
action::Action,
|
||||
components::{
|
||||
footer::Footer, fps::FpsCounter, left::Left, popup, right::Right, title::Title, Component,
|
||||
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,
|
||||
diskpart::build_dest_format_script,
|
||||
drivers::{self},
|
||||
boot, cpu::get_cpu_name, disk::PartitionTableType, diskpart::build_dest_format_script,
|
||||
drivers,
|
||||
},
|
||||
tasks::{Task, Tasks},
|
||||
tui::{Event, Tui},
|
||||
|
|
@ -59,6 +61,7 @@ pub struct App {
|
|||
// App
|
||||
clone: CloneSettings,
|
||||
cur_mode: Mode,
|
||||
list: StatefulList<usize>,
|
||||
prev_mode: Mode,
|
||||
selections: Vec<Option<usize>>,
|
||||
tasks: Tasks,
|
||||
|
|
@ -91,12 +94,71 @@ impl App {
|
|||
// App
|
||||
clone: CloneSettings::new(disk_list_arc),
|
||||
cur_mode: Mode::ScanDisks,
|
||||
list: StatefulList::default(),
|
||||
prev_mode: Mode::ScanDisks,
|
||||
selections: vec![None, None],
|
||||
tasks,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_boot_part_index(&self) -> usize {
|
||||
if let Some(index) = self.clone.part_index_boot {
|
||||
index
|
||||
} else if let Some(index) = self.selections[0] {
|
||||
index
|
||||
} else {
|
||||
self.list.selected().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_os_part_index(&self) -> Option<usize> {
|
||||
let mut os_part_index = None;
|
||||
if let Some(index) = self.clone.part_index_os {
|
||||
os_part_index = Some(index);
|
||||
} else if let Some(index) = self.selections[1] {
|
||||
os_part_index = Some(index);
|
||||
} else {
|
||||
// Highlighted entry
|
||||
if let Some(index) = self.list.selected() {
|
||||
if index != self.get_boot_part_index() {
|
||||
os_part_index = Some(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
os_part_index
|
||||
}
|
||||
|
||||
pub fn get_dest_index(&self) -> Option<usize> {
|
||||
let mut dest_index = None;
|
||||
if let Some(index) = self.clone.disk_index_dest {
|
||||
// Selected in prior mode
|
||||
dest_index = Some(index);
|
||||
} else if let Some(index) = self.selections[1] {
|
||||
// Selected in this mode
|
||||
dest_index = Some(index);
|
||||
} else if let Some(index) = self.list.selected() {
|
||||
// Highlighted entry
|
||||
if let Some(source_index) = self.get_source_index() {
|
||||
if index != source_index {
|
||||
dest_index = Some(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
dest_index
|
||||
}
|
||||
|
||||
pub fn get_source_index(&self) -> Option<usize> {
|
||||
if let Some(index) = self.clone.disk_index_source {
|
||||
// Selected in prior mode
|
||||
Some(index)
|
||||
} else if let Some(index) = self.selections[0] {
|
||||
// Selected in this mode
|
||||
Some(index)
|
||||
} else {
|
||||
self.list.selected()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn next_mode(&mut self) -> (Option<Mode>, Option<Mode>) {
|
||||
let new_mode = match (self.prev_mode, self.cur_mode) {
|
||||
(_, Mode::InstallDrivers) => Mode::ScanDisks,
|
||||
|
|
@ -240,7 +302,10 @@ impl App {
|
|||
String::from("COMPLETE\n\n\nThank you for using this tool!"),
|
||||
))?;
|
||||
}
|
||||
_ => {}
|
||||
_ => {
|
||||
//TODO
|
||||
//FIXME
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -344,6 +409,8 @@ impl App {
|
|||
Action::Suspend => self.should_suspend = true,
|
||||
Action::Resume => self.should_suspend = false,
|
||||
Action::ClearScreen => tui.terminal.clear()?,
|
||||
Action::KeyUp => self.list.previous(),
|
||||
Action::KeyDown => self.list.next(),
|
||||
Action::Error(ref msg) => {
|
||||
self.action_tx
|
||||
.send(Action::DisplayPopup(popup::Type::Error, msg.clone()))?;
|
||||
|
|
@ -396,7 +463,11 @@ impl App {
|
|||
self.selections[0] = one;
|
||||
self.selections[1] = two;
|
||||
}
|
||||
Action::SetMode(new_mode) => self.set_mode(new_mode)?,
|
||||
Action::SetMode(new_mode) => {
|
||||
self.set_mode(new_mode)?;
|
||||
let (start, lines) = get_right_selections(self, self.prev_mode, self.cur_mode);
|
||||
self.action_tx.send(Action::UpdateRight(start, lines))?;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
for component in &mut self.components {
|
||||
|
|
@ -488,3 +559,89 @@ fn get_chunks(r: Rect) -> Vec<Rect> {
|
|||
// Done
|
||||
chunks
|
||||
}
|
||||
|
||||
fn get_right_selections(app: &App, prev_mode: Mode, cur_mode: Mode) -> (usize, Vec<Vec<DVLine>>) {
|
||||
let mut selections = Vec::new();
|
||||
let mut start_index = 0;
|
||||
match (prev_mode, cur_mode) {
|
||||
(_, Mode::InstallDrivers) => {
|
||||
info!("get_right_selections: InstallDrivers");
|
||||
selections.push(vec![DVLine {
|
||||
line_parts: vec![String::from("CPU")],
|
||||
line_colors: vec![Color::Cyan],
|
||||
}]);
|
||||
selections.push(vec![DVLine {
|
||||
line_parts: vec![get_cpu_name()],
|
||||
line_colors: vec![Color::Reset],
|
||||
}]);
|
||||
start_index = 2;
|
||||
}
|
||||
(_, Mode::SelectDisks | Mode::SelectTableType)
|
||||
| (Mode::SelectDisks | Mode::SelectTableType, Mode::Confirm) => {
|
||||
info!("get_right_selections: SelectDisks");
|
||||
// Source Disk Details
|
||||
if let Some(index) = app.get_source_index() {
|
||||
info!("get_right_selections: Source Disk Index: {}", index);
|
||||
let disk_list = app.clone.disk_list.lock().unwrap();
|
||||
if let Some(disk) = disk_list.get(index) {
|
||||
selections.push(get_disk_description_right(&disk, "Source"));
|
||||
}
|
||||
}
|
||||
// Dest Disk Details
|
||||
if let Some(index) = app.get_dest_index() {
|
||||
let disk_list = app.clone.disk_list.lock().unwrap();
|
||||
if let Some(disk) = disk_list.get(index) {
|
||||
let mut disk_description = get_disk_description_right(&disk, "Dest");
|
||||
|
||||
// Add format warning
|
||||
disk_description[0] // i.e. "Dest:"
|
||||
.line_parts
|
||||
.push(" (WARNING: ALL DATA WILL BE DELETED!)".to_string());
|
||||
disk_description[0].line_colors.push(Color::Red);
|
||||
if let Some(table_type) = &app.clone.table_type {
|
||||
// Show table type
|
||||
let type_str = match table_type {
|
||||
PartitionTableType::Guid => "GPT",
|
||||
PartitionTableType::Legacy => "MBR",
|
||||
};
|
||||
disk_description.insert(
|
||||
1,
|
||||
DVLine {
|
||||
line_parts: vec![format!(" (Will be formatted {type_str}")],
|
||||
line_colors: vec![Color::Yellow],
|
||||
},
|
||||
);
|
||||
}
|
||||
selections.push(disk_description)
|
||||
}
|
||||
}
|
||||
}
|
||||
(_, Mode::SelectParts) | (Mode::SelectParts, Mode::Confirm) => {
|
||||
info!("get_right_selections: SelectParts");
|
||||
if let Some(index) = app.get_dest_index() {
|
||||
start_index = 1;
|
||||
let disk_list = app.clone.disk_list.lock().unwrap();
|
||||
if let Some(disk) = disk_list.get(index) {
|
||||
// Disk Details
|
||||
selections.push(get_disk_description_right(&disk, "Disk"));
|
||||
|
||||
// Boot Partition
|
||||
let index = app.get_boot_part_index();
|
||||
if let Some(part) = disk.parts.get(index) {
|
||||
selections.push(get_part_description(&part, "Boot"));
|
||||
}
|
||||
|
||||
// OS Partition
|
||||
if let Some(index) = app.get_os_part_index() {
|
||||
if let Some(part) = disk.parts.get(index) {
|
||||
selections.push(get_part_description(&part, "OS"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
info!("Right Selections: {:?}", &selections);
|
||||
(start_index, selections)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,37 +20,26 @@ use ratatui::{
|
|||
widgets::{Block, Borders, Padding, Paragraph, Wrap},
|
||||
};
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
use tracing::info;
|
||||
|
||||
use super::{state::StatefulList, Component};
|
||||
use crate::{
|
||||
action::Action,
|
||||
config::Config,
|
||||
state::Mode,
|
||||
system::{
|
||||
cpu::get_cpu_name,
|
||||
disk::{Disk, Partition, PartitionTableType},
|
||||
},
|
||||
};
|
||||
use crate::{action::Action, config::Config, line::DVLine, state::Mode};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Right {
|
||||
command_tx: Option<UnboundedSender<Action>>,
|
||||
config: Config,
|
||||
cur_mode: Mode,
|
||||
list_disks: StatefulList<Disk>,
|
||||
list_parts: StatefulList<Partition>,
|
||||
prev_mode: Mode,
|
||||
selected_disks: Vec<Option<usize>>,
|
||||
list_header: Vec<DVLine>,
|
||||
list: StatefulList<Vec<DVLine>>,
|
||||
selections: Vec<Option<usize>>,
|
||||
table_type: Option<PartitionTableType>,
|
||||
title: String,
|
||||
}
|
||||
|
||||
impl Right {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
selected_disks: vec![None, None],
|
||||
selections: vec![None, None],
|
||||
title: String::from("Info"),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
@ -74,80 +63,52 @@ impl Component for Right {
|
|||
|
||||
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::KeyUp => self.list.previous(),
|
||||
Action::KeyDown => self.list.next(),
|
||||
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;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
self.selections[0] = None;
|
||||
self.selections[1] = 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Action::UpdateDiskList(disks) => {
|
||||
// info!("Updating disk list");
|
||||
// self.list_disks.set_items(disks);
|
||||
// if self.cur_mode == Mode::Clone {
|
||||
// if let Some(index) = self.selected_disks[1] {
|
||||
// if let Some(disk) = self.list_disks.get(index) {
|
||||
// self.list_parts.set_items(disk.get_parts());
|
||||
// // Auto-select first partition and highlight likely OS partition
|
||||
// if let Some(index) = self.selected_disks[1] {
|
||||
// if let Some(disk) = self.list_disks.get(index) {
|
||||
// if let Some(table_type) = &self.table_type {
|
||||
// match table_type {
|
||||
// PartitionTableType::Guid => {
|
||||
// if disk.num_parts() >= 3 {
|
||||
// self.selections[0] = Some(0);
|
||||
// self.list_parts.select(2);
|
||||
// }
|
||||
// }
|
||||
// PartitionTableType::Legacy => {
|
||||
// if disk.num_parts() >= 2 {
|
||||
// self.selections[0] = Some(0);
|
||||
// self.list_parts.select(1);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Action::UpdateRight(start_index, list) => {
|
||||
self.list_header = list[..start_index].iter().flatten().cloned().collect();
|
||||
self.list.set_items(list[start_index..].to_vec());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
@ -161,230 +122,45 @@ impl Component for Right {
|
|||
.areas(area);
|
||||
|
||||
// Title
|
||||
let title_text = String::from("Info");
|
||||
let title = Paragraph::new(Line::from(title_text).centered())
|
||||
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::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 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.selections[0] {
|
||||
if let Some(first_desc) = self.list.get(first_index) {
|
||||
first_desc
|
||||
.iter()
|
||||
.for_each(|dv| body_text.push(dv.as_line()));
|
||||
}
|
||||
}
|
||||
|
||||
// Second selection
|
||||
if let Some(second_index) = self.selections[1] {
|
||||
if let Some(second_desc) = self.list.get(second_index) {
|
||||
// Divider
|
||||
body_text.push(Line::from(""));
|
||||
body_text.push(Line::from(str::repeat("─", (body_area.width - 4) as usize)));
|
||||
body_text.push(Line::from(""));
|
||||
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 })
|
||||
|
|
|
|||
104
deja_vu/src/line.rs
Normal file
104
deja_vu/src/line.rs
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
// 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, label: &str) -> Vec<DVLine> {
|
||||
let mut description: Vec<DVLine> = vec![
|
||||
DVLine {
|
||||
line_parts: vec![String::from(label)],
|
||||
line_colors: vec![Color::Cyan],
|
||||
},
|
||||
DVLine::blank(),
|
||||
DVLine {
|
||||
line_parts: vec![format!(
|
||||
"{:<8} {:>11} {:<4} {:<4} {}",
|
||||
"Disk ID", "Size", "Conn", "Type", "Model (Serial)"
|
||||
)],
|
||||
line_colors: vec![Color::Green],
|
||||
},
|
||||
DVLine {
|
||||
line_parts: vec![disk.description.clone()],
|
||||
line_colors: vec![Color::Reset],
|
||||
},
|
||||
DVLine::blank(),
|
||||
DVLine {
|
||||
line_parts: vec![format!(
|
||||
"{:<8} {:>11} {:<7} {}",
|
||||
"Part ID", "Size", "(FS)", "\"Label\""
|
||||
)],
|
||||
line_colors: vec![Color::Blue],
|
||||
},
|
||||
];
|
||||
for line in &disk.parts_description {
|
||||
description.push(DVLine {
|
||||
line_parts: vec![line.clone()],
|
||||
line_colors: vec![Color::Reset],
|
||||
});
|
||||
}
|
||||
description
|
||||
}
|
||||
|
||||
pub fn get_part_description(part: &Partition, label: &str) -> Vec<DVLine> {
|
||||
let description: Vec<DVLine> = vec![
|
||||
DVLine {
|
||||
line_parts: vec![String::from(label)],
|
||||
line_colors: vec![Color::Cyan],
|
||||
},
|
||||
DVLine::blank(),
|
||||
DVLine {
|
||||
line_parts: vec![format!(
|
||||
"{:<8} {:>11} {:<7} {}",
|
||||
"Part ID", "Size", "(FS)", "\"Label\""
|
||||
)],
|
||||
line_colors: vec![Color::Blue],
|
||||
},
|
||||
DVLine {
|
||||
line_parts: vec![format!("{part}")],
|
||||
line_colors: vec![Color::Reset],
|
||||
},
|
||||
];
|
||||
description
|
||||
}
|
||||
|
|
@ -25,6 +25,7 @@ mod cli;
|
|||
mod components;
|
||||
mod config;
|
||||
mod errors;
|
||||
mod line;
|
||||
mod logging;
|
||||
mod state;
|
||||
mod system;
|
||||
|
|
|
|||
Loading…
Reference in a new issue