Revert "Add support for getting Modes by name"

This moves a compile-time check to runtime.  It's worth the "bloat" to
keep things compile-time IMO

This reverts commit 828a2736be.
This commit is contained in:
2Shirt 2025-01-12 00:21:11 -08:00
parent 828a2736be
commit 608f07d445
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
7 changed files with 17 additions and 39 deletions

2
Cargo.lock generated
View file

@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
version = 3
[[package]]
name = "addr2line"

View file

@ -17,6 +17,7 @@ use serde::{Deserialize, Serialize};
use strum::Display;
use crate::{
app::Mode,
components::popup::Type,
system::{
disk::{Disk, PartitionTableType},
@ -39,7 +40,7 @@ pub enum Action {
DisplayPopup(Type, String),
NextScreen,
PrevScreen,
SetMode(String),
SetMode(Mode),
// TUI
ClearScreen,
Error(String),

View file

@ -17,7 +17,6 @@
use std::{
env,
iter::zip,
str::FromStr,
sync::{Arc, Mutex},
};
@ -28,7 +27,6 @@ use ratatui::{
prelude::Rect,
};
use serde::{Deserialize, Serialize};
use strum::{Display, EnumString};
use tokio::sync::mpsc;
use tracing::{debug, info};
@ -73,9 +71,7 @@ pub struct App {
tasks: Tasks,
}
#[derive(
Default, Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, EnumString, Display,
)]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Mode {
#[default]
ScanDisks,
@ -91,13 +87,6 @@ pub enum Mode {
Failed,
}
impl Mode {
pub fn get_mode(mode_str: &str) -> Self {
let error_msg = format!("Failed to get app Mode: '{}'", mode_str);
Self::from_str(mode_str).expect(&error_msg)
}
}
impl App {
pub fn new(tick_rate: f64, frame_rate: f64) -> Result<Self> {
let (action_tx, action_rx) = mpsc::unbounded_channel();
@ -384,12 +373,10 @@ impl App {
Action::Error(ref msg) => {
self.action_tx
.send(Action::DisplayPopup(popup::Type::Error, msg.clone()))?;
self.action_tx
.send(Action::SetMode(String::from("Failed")))?;
self.action_tx.send(Action::SetMode(Mode::Failed))?;
}
Action::InstallDriver => {
self.action_tx
.send(Action::SetMode(String::from("InstallDrivers")))?;
self.action_tx.send(Action::SetMode(Mode::InstallDrivers))?;
}
Action::SelectDriver(ref driver) => {
self.driver = Some(driver.clone());
@ -407,17 +394,15 @@ impl App {
(Mode::SelectTableType, Mode::SelectTableType) => Mode::SelectDisks,
(_, _) => self.prev_mode,
};
self.action_tx.send(Action::SetMode(new_mode.to_string()))?;
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.to_string()))?;
self.action_tx.send(Action::SetMode(mode))?;
}
}
Action::ScanDisks => self
.action_tx
.send(Action::SetMode(String::from("ScanDisks")))?,
Action::ScanDisks => self.action_tx.send(Action::SetMode(Mode::ScanDisks))?,
Action::Select(one, two) => {
match self.cur_mode {
Mode::SelectDisks => {
@ -433,9 +418,7 @@ impl App {
self.selections[0] = one;
self.selections[1] = two;
}
Action::SetMode(ref new_mode_string) => {
self.set_mode(Mode::get_mode(&new_mode_string))?
}
Action::SetMode(new_mode) => self.set_mode(new_mode)?,
_ => {}
}
for component in &mut self.components {

View file

@ -18,7 +18,6 @@ use ratatui::{
prelude::*,
widgets::{Block, Borders, Paragraph},
};
use std::str::FromStr;
use tokio::sync::mpsc::UnboundedSender;
use super::Component;
@ -53,7 +52,6 @@ impl Component for Footer {
fn update(&mut self, action: Action) -> Result<Option<Action>> {
if let Action::SetMode(new_mode) = action {
let new_mode = Mode::from_str(&new_mode)?;
self.text = match new_mode {
Mode::ScanDisks | Mode::PreClone | Mode::Clone | Mode::PostClone => {
String::from("(q) to quit")

View file

@ -19,7 +19,6 @@ use ratatui::{
prelude::*,
widgets::{Block, Borders, HighlightSpacing, List, ListItem, Padding, Paragraph},
};
use std::str::FromStr;
use tokio::sync::mpsc::UnboundedSender;
use tracing::info;
@ -174,8 +173,8 @@ impl Component for Left {
}
Action::SetMode(new_mode) => {
let prev_mode = self.mode;
self.mode = Mode::from_str(&new_mode)?;
match (prev_mode, Mode::from_str(&new_mode)?) {
self.mode = new_mode;
match (prev_mode, new_mode) {
(_, Mode::ScanDisks) => {
self.list_disks.clear_items();
self.title_text = String::new();

View file

@ -19,7 +19,6 @@ use ratatui::{
widgets::{Block, Borders, Clear, Paragraph, Wrap},
};
use serde::{Deserialize, Serialize};
use std::str::FromStr;
use strum::Display;
use tokio::sync::mpsc::UnboundedSender;
@ -70,12 +69,11 @@ impl Component for Popup {
self.popup_type = new_type;
self.popup_text = new_text;
}
Action::SetMode(mode_string) => {
let new_mode = Mode::get_mode(&mode_string);
if new_mode == Mode::ScanDisks {
Action::SetMode(mode) => {
if mode == Mode::ScanDisks {
self.popup_text = String::from("Scanning Disks...");
}
self.mode = new_mode;
self.mode = mode;
}
_ => {}
}

View file

@ -19,7 +19,6 @@ use ratatui::{
prelude::*,
widgets::{Block, Borders, Padding, Paragraph, Wrap},
};
use std::str::FromStr;
use tokio::sync::mpsc::UnboundedSender;
use tracing::info;
@ -95,9 +94,9 @@ impl Component for Right {
self.selections[1] = two;
}
Action::SelectTableType(table_type) => self.table_type = Some(table_type),
Action::SetMode(new_mode_string) => {
Action::SetMode(new_mode) => {
self.prev_mode = self.cur_mode;
self.cur_mode = Mode::from_str(&new_mode_string)?;
self.cur_mode = new_mode;
match self.cur_mode {
Mode::SelectDisks => {
self.selections[0] = None;