taskfinder 2.15.0

A terminal user interface that extracts and displays tasks from plain text files, hooking into your default terminal-based editor for editing.
#![forbid(unsafe_code)]
//! View help, version, and changelog.

use ratatui::{
    Frame,
    layout::{Alignment, Rect},
    style::Stylize,
    text::Line,
    widgets::{Block, Paragraph, Wrap},
};

use crate::App;

pub const USAGE: &str = include_str!("../../USAGE.md");
pub const EXAMPLE1: &str = include_str!("../../test_files/01_basics.txt");
pub const EXAMPLE2: &str = include_str!("../../test_files/02_tags.txt");
pub const EXAMPLE3: &str = include_str!("../../test_files/03_dates.txt");
pub const EXAMPLE4: &str = include_str!("../../test_files/04_priorities.txt");
pub const EXAMPLE5: &str = include_str!("../../test_files/05_ordering.txt");
pub const EXAMPLE6: &str = include_str!("../../test_files/06_misc.txt");
pub const CHANGELOG: &str = include_str!("../../CHANGELOG.md");

#[derive(Clone, PartialEq)]
pub enum Examples {
    Example1,
    Example2,
    Example3,
    Example4,
    Example5,
    Example6,
}

pub struct HelpMode {
    pub line_offset: u16,
    pub help_text: String,
}

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<'_>>,
) {
    main_block = main_block
        .title(" Help ".bold())
        .title_alignment(Alignment::Center);

    frame.render_widget(
        Paragraph::new(app.helpmode.help_text.clone())
            .wrap(Wrap { trim: false })
            .scroll((app.helpmode.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(
                    "Developed by Kris Warner and licensed under the AGPL 3.0 or later. See <https://kdwarn.net>.",
                )])
                .wrap(Wrap { trim: false })
                .block(info_block),
                top_right,
            );

    // Controls specific to this mode.
    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(Line::from(""));
    controls_content.push(Line::from("Toggles".blue().bold().underlined()));
    controls_content.push(vec!["v".blue(), " Version and changelog".into()].into());
    controls_content.push(vec!["1".blue(), " Example file - basics".into()].into());
    controls_content.push(vec!["2".blue(), " Example file - tags".into()].into());
    controls_content.push(vec!["3".blue(), " Example file - dates".into()].into());
    controls_content.push(vec!["4".blue(), " Example file - priorities".into()].into());
    controls_content.push(vec!["5".blue(), " Example file - ordering".into()].into());
    controls_content.push(vec!["6".blue(), " Example file - misc".into()].into());
}