deja-vu/deja_vu/src/components/footer.rs

89 lines
2.9 KiB
Rust

// 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 ratatui::{
prelude::*,
widgets::{Block, Borders, Paragraph},
};
use tokio::sync::mpsc::UnboundedSender;
use super::Component;
use crate::{action::Action, app::Mode, config::Config};
#[derive(Default)]
pub struct Footer {
command_tx: Option<UnboundedSender<Action>>,
config: Config,
text: String,
}
impl Footer {
pub fn new() -> Self {
Self {
text: String::from("(q) to quit"),
..Default::default()
}
}
}
impl Component for Footer {
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>> {
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")
}
}
}
Ok(None)
}
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
let footer = Paragraph::new(
Line::from(Span::styled(
&self.text,
Style::default().fg(Color::DarkGray),
))
.centered(),
)
.block(Block::default().borders(Borders::ALL));
frame.render_widget(footer, area);
Ok(())
}
}