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::*};
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,
footer_text: String,
}
impl Footer {
pub fn new() -> Self {
Self {
footer_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>> {
match action {
Action::Tick => {
// add any logic here that should run on every tick
}
Action::Render => {
// add any logic here that should run on every render
}
Action::SetMode(new_mode) => {
self.footer_text = match new_mode {
Mode::Confirm => {
String::from("(Enter) to confirm / (b) to go back / (q) to quit")
}
Mode::Done => String::from("(Enter) or (q) to quit"),
Mode::InstallDrivers => String::from("(Enter) to select / (q) to quit"),
Mode::ScanDisks => String::from("(q) to quit"),
Mode::SelectDisks => String::from(
"(Enter) to select / / (i) to install driver / (r) to rescan / (q) to quit",
),
_ => String::from("(Enter) to select / (b) to go back / (q) to quit"),
}
}
_ => {}
}
Ok(None)
}
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
let footer = Paragraph::new(
Line::from(Span::styled(
&self.footer_text,
Style::default().fg(Color::DarkGray),
))
.centered(),
)
.block(Block::default().borders(Borders::ALL));
frame.render_widget(footer, area);
Ok(())
}
}