use crate::{
app::{App, AsyncState},
view::prelude::*,
};
pub struct CreditsView;
impl View for CreditsView {
fn draw_content(
&self,
app: &App,
_state: &AsyncState,
frame: &mut Frame,
area: ratatui::prelude::Rect,
_is_focused: bool,
) -> Result<()> {
macro_rules! add_credits {
(&mut $list:path, $source:literal) => {
$list.push("".into());
$list.push(concat!($source, ":").into());
$list.extend(
textwrap::wrap(
include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
concat!("/resource/credits/", $source, ".txt")
)),
area.width as usize,
)
.iter()
.cloned()
.map(Line::from)
.map(|line| line.blue().into()),
);
};
}
let mut credits_list = vec![Line::from(
"The following open-source projects were used to create this app.",
)];
add_credits!(&mut credits_list, "color-eyre");
add_credits!(&mut credits_list, "crossterm");
add_credits!(&mut credits_list, "plist");
add_credits!(&mut credits_list, "ratatui");
add_credits!(&mut credits_list, "serde");
add_credits!(&mut credits_list, "strum");
add_credits!(&mut credits_list, "strum_macros");
add_credits!(&mut credits_list, "textwrap");
add_credits!(&mut credits_list, "tokio");
let credits_paragraph = Paragraph::new(credits_list.clone());
let scrollbar = Scrollbar::new(ScrollbarOrientation::VerticalRight);
let mut scrollbar_state = ScrollbarState::new(credits_list.len())
.position(app.interaction_state());
frame.render_widget(
credits_paragraph.scroll((app.interaction_state() as u16, 0)),
area,
);
frame.render_stateful_widget(
scrollbar,
area.inner(Margin {
vertical: 1,
horizontal: 0,
}),
&mut scrollbar_state,
);
Ok(())
}
fn interactivity(
&self,
_app: &App,
_state: &AsyncState,
) -> Result<ViewInteractivity> {
Ok(ViewInteractivity::Scrollable)
}
}