Refactor footer text

This commit is contained in:
2Shirt 2025-01-19 14:07:34 -08:00
parent a77bf0c9c6
commit e029e02cc2
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
3 changed files with 20 additions and 19 deletions

View file

@ -28,6 +28,7 @@ pub enum Action {
Select(Option<usize>, Option<usize>), // indicies for (source, dest) etc
SelectRight(Option<usize>, Option<usize>), // indicies for right info pane
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

View file

@ -423,6 +423,8 @@ impl App {
}
Action::SetMode(new_mode) => {
self.set_mode(new_mode)?;
self.action_tx
.send(Action::UpdateFooter(build_footer_string(self.cur_mode)))?;
let (title, labels, items, select_one) = build_left_items(self, self.cur_mode);
self.action_tx
.send(Action::UpdateLeft(title, labels, items, select_one))?;
@ -550,6 +552,20 @@ fn get_chunks(r: Rect) -> Vec<Rect> {
chunks
}
fn build_footer_string(cur_mode: Mode) -> String {
match cur_mode {
Mode::ScanDisks | Mode::PreClone | Mode::Clone | Mode::PostClone => {
String::from("(q) to quit")
}
Mode::SelectParts => String::from("(Enter) to select / (s) to start over / (q) to quit"),
Mode::SelectDisks => String::from(
"(Enter) to select / / (i) to install driver / (r) to rescan / (q) to quit",
),
Mode::SelectTableType => String::from("(Enter) to select / (b) to go back / (q) to quit"),
Mode::Confirm => String::from("(Enter) to confirm / (b) to go back / (q) to quit"),
Mode::Done | Mode::Failed | Mode::InstallDrivers => String::from("(Enter) or (q) to quit"),
}
}
fn build_left_items(app: &App, cur_mode: Mode) -> (String, Vec<String>, Vec<String>, bool) {
let title: String;
let mut items = Vec::new();

View file

@ -51,25 +51,9 @@ impl Component for Footer {
}
fn update(&mut self, action: Action) -> Result<Option<Action>> {
if let Action::SetMode(new_mode) = action {
self.text = match new_mode {
Mode::ScanDisks | Mode::PreClone | Mode::Clone | Mode::PostClone => {
String::from("(q) to quit")
}
Mode::SelectParts => {
String::from("(Enter) to select / (s) to start over / (q) to quit")
}
Mode::SelectDisks => String::from(
"(Enter) to select / / (i) to install driver / (r) to rescan / (q) to quit",
),
Mode::SelectTableType => {
String::from("(Enter) to select / (b) to go back / (q) to quit")
}
Mode::Confirm => String::from("(Enter) to confirm / (b) to go back / (q) to quit"),
Mode::Done | Mode::Failed | Mode::InstallDrivers => {
String::from("(Enter) or (q) to quit")
}
}
match action {
Action::UpdateFooter(text) => self.text = text,
_ => {}
}
Ok(None)
}