pager/
pager.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crossterm::style::Stylize;
use oma_console::{
    pager::{OmaPager, Pager, PagerUIText},
    print::OmaColorFormat,
};
use std::{io, time::Duration};

struct OmaPagerUIText;

impl PagerUIText for OmaPagerUIText {
    fn normal_tips(&self) -> String {
        "QAQ".to_string()
    }

    fn search_tips_with_result(&self) -> String {
        "Press Esc to exit search, press N or n to jump to the prev or next match.".to_string()
    }

    fn searct_tips_with_query(&self, query: &str) -> String {
        format!("Search: {}", query)
    }

    fn search_tips_with_empty(&self) -> String {
        "Search pattern cannot be empty (Press /)".to_string()
    }

    fn search_tips_not_found(&self) -> String {
        "Pattern not found (Press /)".to_string()
    }
}

fn main() -> io::Result<()> {
    let cf = OmaColorFormat::new(true, Duration::from_millis(100));
    let pager = OmaPager::new(Some("QAQ".to_string()), &cf, &OmaPagerUIText);
    let mut p = Pager::External(Box::new(pager));
    let mut w = p.get_writer()?;
    w.write_all("QAQ\n".cyan().to_string().as_bytes()).ok();
    w.write_all(b"PAP").ok();

    drop(w);
    p.wait_for_exit()?;

    Ok(())
}