#![forbid(unsafe_code)]
use std::fs;
use ratatui::{
Frame,
layout::{Alignment, Rect},
style::Stylize,
text::Line,
widgets::{Block, Paragraph, Wrap},
};
use crate::App;
pub struct EvergreenMode {
pub line_offset: u16,
}
pub fn render(
app: &mut App,
frame: &mut Frame,
mut info_block: Block,
mut main_block: Block,
top_right: Rect,
left: Rect,
controls_content: &mut Vec<Line<'_>>,
) {
let text = match fs::read_to_string(&app.config.evergreen_file) {
Ok(v) => v,
Err(e) => format!("Error opening evergreen file: {e}"),
};
main_block = main_block
.title(" Evergreen ".bold())
.title_alignment(Alignment::Center);
frame.render_widget(
Paragraph::new(text)
.wrap(Wrap { trim: false })
.scroll((app.evergreenmode.line_offset, 0))
.block(main_block),
left,
);
info_block = info_block.title_top(Line::from(" Info ").centered());
frame.render_widget(
Paragraph::new(vec![Line::from(
"This mode allows you to have a particular file accessible at the touch of a keystroke.",
)])
.wrap(Wrap { trim: false })
.block(info_block),
top_right,
);
controls_content.push(Line::from(""));
controls_content.push(Line::from("Navigation".blue().bold().underlined()));
controls_content.push(
vec![
"↑".blue(),
" or ".into(),
"k".blue(),
" Scroll up 1 line".into(),
]
.into(),
);
controls_content.push(
vec![
"↓".blue(),
" or ".into(),
"j".blue(),
" Scroll down 1 line".into(),
]
.into(),
);
controls_content.push(
vec![
"PgDn".blue(),
" or ".into(),
"CTRL+d".blue(),
" Scroll down 20 lines".into(),
]
.into(),
);
controls_content.push(
vec![
"PgUp".blue(),
" or ".into(),
"CTRL+u".blue(),
" Scroll up 20 lines".into(),
]
.into(),
);
controls_content.push(vec!["Enter".blue(), " Edit file".into()].into());
}