Struct pager_rs::CommandList

source ·
pub struct CommandList(pub Vec<Command>);
Expand description

Container of list of commands.

Tuple Fields§

§0: Vec<Command>

Implementations§

source§

impl CommandList

source

pub fn combine<T>(list: Vec<T>) -> Self
where T: Into<Vec<Command>>,

Combine CommandList’s into one.

Examples found in repository?
examples/custom_command.rs (lines 24-46)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
fn main() -> std::io::Result<()> {
    let content = r#"Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Pellentesque neque nulla, viverra ac sapien
et, ultricies convallis lectus. Suspendisse mattis
in urna quis efficitur. Quisque mollis vulputate ipsum,
ut auctor risus luctus eu. Donec sagittis convallis erat
eget imperdiet. Aliquam massa erat, venenatis eu massa at,
dignissim tempus massa. Donec blandit augue et malesuada
fermentum. In vehicula, nisl ut scelerisque sagittis,
sapien elit gravida enim, eu feugiat magna arcu sed enim.
Fusce accumsan sodales ipsum lobortis feugiat. Pellentesque
quam lectus, molestie vitae nisi a, tempor mollis mauris.
Maecenas in magna tempus, porta augue bibendum, feugiat nulla."#
        .to_string();

    let status_bar =
        StatusBar::new("Press 'p' to open selected line on seperate instance".to_string());

    let mut state = State::new(
        content,
        status_bar,
        CommandList::combine(vec![
            CommandList(vec![Command {
                cmd: vec![CommandType::Key(KeyCode::Char('p'))],
                desc: "Open selected line on seperate instance".to_string(),
                func: &|state| {
                    let commands =
                        CommandList::combine(vec![CommandList::quit(), CommandList::navigation()]);

                    let mut modal = State::new(
                        state.content.lines().nth(state.pos.1).unwrap().to_string(),
                        StatusBar::new("Quit (q)".to_string()),
                        commands,
                    )
                    .unwrap();
                    modal.show_line_numbers = false;
                    run(&mut modal).unwrap();
                    true
                },
            }]),
            CommandList::quit(),
            CommandList::navigation(),
            CommandList::help(),
        ]),
    )?;
    state.show_line_numbers = false;

    pager_rs::init()?;

    pager_rs::run(&mut state)?;

    pager_rs::finish()?;

    Ok(())
}
source

pub fn quit() -> Self

Default ‘quit’ command

Examples found in repository?
examples/custom_command.rs (line 30)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
fn main() -> std::io::Result<()> {
    let content = r#"Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Pellentesque neque nulla, viverra ac sapien
et, ultricies convallis lectus. Suspendisse mattis
in urna quis efficitur. Quisque mollis vulputate ipsum,
ut auctor risus luctus eu. Donec sagittis convallis erat
eget imperdiet. Aliquam massa erat, venenatis eu massa at,
dignissim tempus massa. Donec blandit augue et malesuada
fermentum. In vehicula, nisl ut scelerisque sagittis,
sapien elit gravida enim, eu feugiat magna arcu sed enim.
Fusce accumsan sodales ipsum lobortis feugiat. Pellentesque
quam lectus, molestie vitae nisi a, tempor mollis mauris.
Maecenas in magna tempus, porta augue bibendum, feugiat nulla."#
        .to_string();

    let status_bar =
        StatusBar::new("Press 'p' to open selected line on seperate instance".to_string());

    let mut state = State::new(
        content,
        status_bar,
        CommandList::combine(vec![
            CommandList(vec![Command {
                cmd: vec![CommandType::Key(KeyCode::Char('p'))],
                desc: "Open selected line on seperate instance".to_string(),
                func: &|state| {
                    let commands =
                        CommandList::combine(vec![CommandList::quit(), CommandList::navigation()]);

                    let mut modal = State::new(
                        state.content.lines().nth(state.pos.1).unwrap().to_string(),
                        StatusBar::new("Quit (q)".to_string()),
                        commands,
                    )
                    .unwrap();
                    modal.show_line_numbers = false;
                    run(&mut modal).unwrap();
                    true
                },
            }]),
            CommandList::quit(),
            CommandList::navigation(),
            CommandList::help(),
        ]),
    )?;
    state.show_line_numbers = false;

    pager_rs::init()?;

    pager_rs::run(&mut state)?;

    pager_rs::finish()?;

    Ok(())
}
source

pub fn navigation() -> Self

Default bundle of ‘navigation’ commands.

Includes: Arrow, Home/End, PageUp/PageDown keys

Examples found in repository?
examples/custom_command.rs (line 30)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
fn main() -> std::io::Result<()> {
    let content = r#"Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Pellentesque neque nulla, viverra ac sapien
et, ultricies convallis lectus. Suspendisse mattis
in urna quis efficitur. Quisque mollis vulputate ipsum,
ut auctor risus luctus eu. Donec sagittis convallis erat
eget imperdiet. Aliquam massa erat, venenatis eu massa at,
dignissim tempus massa. Donec blandit augue et malesuada
fermentum. In vehicula, nisl ut scelerisque sagittis,
sapien elit gravida enim, eu feugiat magna arcu sed enim.
Fusce accumsan sodales ipsum lobortis feugiat. Pellentesque
quam lectus, molestie vitae nisi a, tempor mollis mauris.
Maecenas in magna tempus, porta augue bibendum, feugiat nulla."#
        .to_string();

    let status_bar =
        StatusBar::new("Press 'p' to open selected line on seperate instance".to_string());

    let mut state = State::new(
        content,
        status_bar,
        CommandList::combine(vec![
            CommandList(vec![Command {
                cmd: vec![CommandType::Key(KeyCode::Char('p'))],
                desc: "Open selected line on seperate instance".to_string(),
                func: &|state| {
                    let commands =
                        CommandList::combine(vec![CommandList::quit(), CommandList::navigation()]);

                    let mut modal = State::new(
                        state.content.lines().nth(state.pos.1).unwrap().to_string(),
                        StatusBar::new("Quit (q)".to_string()),
                        commands,
                    )
                    .unwrap();
                    modal.show_line_numbers = false;
                    run(&mut modal).unwrap();
                    true
                },
            }]),
            CommandList::quit(),
            CommandList::navigation(),
            CommandList::help(),
        ]),
    )?;
    state.show_line_numbers = false;

    pager_rs::init()?;

    pager_rs::run(&mut state)?;

    pager_rs::finish()?;

    Ok(())
}
source

pub fn help() -> Self

Default ‘help’ command

Examples found in repository?
examples/custom_command.rs (line 45)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
fn main() -> std::io::Result<()> {
    let content = r#"Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Pellentesque neque nulla, viverra ac sapien
et, ultricies convallis lectus. Suspendisse mattis
in urna quis efficitur. Quisque mollis vulputate ipsum,
ut auctor risus luctus eu. Donec sagittis convallis erat
eget imperdiet. Aliquam massa erat, venenatis eu massa at,
dignissim tempus massa. Donec blandit augue et malesuada
fermentum. In vehicula, nisl ut scelerisque sagittis,
sapien elit gravida enim, eu feugiat magna arcu sed enim.
Fusce accumsan sodales ipsum lobortis feugiat. Pellentesque
quam lectus, molestie vitae nisi a, tempor mollis mauris.
Maecenas in magna tempus, porta augue bibendum, feugiat nulla."#
        .to_string();

    let status_bar =
        StatusBar::new("Press 'p' to open selected line on seperate instance".to_string());

    let mut state = State::new(
        content,
        status_bar,
        CommandList::combine(vec![
            CommandList(vec![Command {
                cmd: vec![CommandType::Key(KeyCode::Char('p'))],
                desc: "Open selected line on seperate instance".to_string(),
                func: &|state| {
                    let commands =
                        CommandList::combine(vec![CommandList::quit(), CommandList::navigation()]);

                    let mut modal = State::new(
                        state.content.lines().nth(state.pos.1).unwrap().to_string(),
                        StatusBar::new("Quit (q)".to_string()),
                        commands,
                    )
                    .unwrap();
                    modal.show_line_numbers = false;
                    run(&mut modal).unwrap();
                    true
                },
            }]),
            CommandList::quit(),
            CommandList::navigation(),
            CommandList::help(),
        ]),
    )?;
    state.show_line_numbers = false;

    pager_rs::init()?;

    pager_rs::run(&mut state)?;

    pager_rs::finish()?;

    Ok(())
}
source

pub fn toggle_line_numbers() -> Self

Default ‘toggle line numbers’ command

Trait Implementations§

source§

impl Default for CommandList

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<CommandList> for Vec<Command>

source§

fn from(val: CommandList) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.