Struct 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)
3fn main() -> std::io::Result<()> {
4    let content = r#"Lorem ipsum dolor sit amet, consectetur adipiscing
5elit. Pellentesque neque nulla, viverra ac sapien
6et, ultricies convallis lectus. Suspendisse mattis
7in urna quis efficitur. Quisque mollis vulputate ipsum,
8ut auctor risus luctus eu. Donec sagittis convallis erat
9eget imperdiet. Aliquam massa erat, venenatis eu massa at,
10dignissim tempus massa. Donec blandit augue et malesuada
11fermentum. In vehicula, nisl ut scelerisque sagittis,
12sapien elit gravida enim, eu feugiat magna arcu sed enim.
13Fusce accumsan sodales ipsum lobortis feugiat. Pellentesque
14quam lectus, molestie vitae nisi a, tempor mollis mauris.
15Maecenas in magna tempus, porta augue bibendum, feugiat nulla."#
16        .to_string();
17
18    let status_bar =
19        StatusBar::new("Press 'p' to open selected line on seperate instance".to_string());
20
21    let mut state = State::new(
22        content,
23        status_bar,
24        CommandList::combine(vec![
25            CommandList(vec![Command {
26                cmd: vec![CommandType::Key(KeyCode::Char('p'))],
27                desc: "Open selected line on seperate instance".to_string(),
28                func: &|state| {
29                    let commands =
30                        CommandList::combine(vec![CommandList::quit(), CommandList::navigation()]);
31
32                    let mut modal = State::new(
33                        state.content.lines().nth(state.pos.1).unwrap().to_string(),
34                        StatusBar::new("Quit (q)".to_string()),
35                        commands,
36                    )
37                    .unwrap();
38                    modal.show_line_numbers = false;
39                    run(&mut modal).unwrap();
40                    true
41                },
42            }]),
43            CommandList::quit(),
44            CommandList::navigation(),
45            CommandList::help(),
46        ]),
47    )?;
48    state.show_line_numbers = false;
49
50    pager_rs::init()?;
51
52    pager_rs::run(&mut state)?;
53
54    pager_rs::finish()?;
55
56    Ok(())
57}
Source

pub fn quit() -> Self

Default ‘quit’ command

Examples found in repository?
examples/custom_command.rs (line 30)
3fn main() -> std::io::Result<()> {
4    let content = r#"Lorem ipsum dolor sit amet, consectetur adipiscing
5elit. Pellentesque neque nulla, viverra ac sapien
6et, ultricies convallis lectus. Suspendisse mattis
7in urna quis efficitur. Quisque mollis vulputate ipsum,
8ut auctor risus luctus eu. Donec sagittis convallis erat
9eget imperdiet. Aliquam massa erat, venenatis eu massa at,
10dignissim tempus massa. Donec blandit augue et malesuada
11fermentum. In vehicula, nisl ut scelerisque sagittis,
12sapien elit gravida enim, eu feugiat magna arcu sed enim.
13Fusce accumsan sodales ipsum lobortis feugiat. Pellentesque
14quam lectus, molestie vitae nisi a, tempor mollis mauris.
15Maecenas in magna tempus, porta augue bibendum, feugiat nulla."#
16        .to_string();
17
18    let status_bar =
19        StatusBar::new("Press 'p' to open selected line on seperate instance".to_string());
20
21    let mut state = State::new(
22        content,
23        status_bar,
24        CommandList::combine(vec![
25            CommandList(vec![Command {
26                cmd: vec![CommandType::Key(KeyCode::Char('p'))],
27                desc: "Open selected line on seperate instance".to_string(),
28                func: &|state| {
29                    let commands =
30                        CommandList::combine(vec![CommandList::quit(), CommandList::navigation()]);
31
32                    let mut modal = State::new(
33                        state.content.lines().nth(state.pos.1).unwrap().to_string(),
34                        StatusBar::new("Quit (q)".to_string()),
35                        commands,
36                    )
37                    .unwrap();
38                    modal.show_line_numbers = false;
39                    run(&mut modal).unwrap();
40                    true
41                },
42            }]),
43            CommandList::quit(),
44            CommandList::navigation(),
45            CommandList::help(),
46        ]),
47    )?;
48    state.show_line_numbers = false;
49
50    pager_rs::init()?;
51
52    pager_rs::run(&mut state)?;
53
54    pager_rs::finish()?;
55
56    Ok(())
57}
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)
3fn main() -> std::io::Result<()> {
4    let content = r#"Lorem ipsum dolor sit amet, consectetur adipiscing
5elit. Pellentesque neque nulla, viverra ac sapien
6et, ultricies convallis lectus. Suspendisse mattis
7in urna quis efficitur. Quisque mollis vulputate ipsum,
8ut auctor risus luctus eu. Donec sagittis convallis erat
9eget imperdiet. Aliquam massa erat, venenatis eu massa at,
10dignissim tempus massa. Donec blandit augue et malesuada
11fermentum. In vehicula, nisl ut scelerisque sagittis,
12sapien elit gravida enim, eu feugiat magna arcu sed enim.
13Fusce accumsan sodales ipsum lobortis feugiat. Pellentesque
14quam lectus, molestie vitae nisi a, tempor mollis mauris.
15Maecenas in magna tempus, porta augue bibendum, feugiat nulla."#
16        .to_string();
17
18    let status_bar =
19        StatusBar::new("Press 'p' to open selected line on seperate instance".to_string());
20
21    let mut state = State::new(
22        content,
23        status_bar,
24        CommandList::combine(vec![
25            CommandList(vec![Command {
26                cmd: vec![CommandType::Key(KeyCode::Char('p'))],
27                desc: "Open selected line on seperate instance".to_string(),
28                func: &|state| {
29                    let commands =
30                        CommandList::combine(vec![CommandList::quit(), CommandList::navigation()]);
31
32                    let mut modal = State::new(
33                        state.content.lines().nth(state.pos.1).unwrap().to_string(),
34                        StatusBar::new("Quit (q)".to_string()),
35                        commands,
36                    )
37                    .unwrap();
38                    modal.show_line_numbers = false;
39                    run(&mut modal).unwrap();
40                    true
41                },
42            }]),
43            CommandList::quit(),
44            CommandList::navigation(),
45            CommandList::help(),
46        ]),
47    )?;
48    state.show_line_numbers = false;
49
50    pager_rs::init()?;
51
52    pager_rs::run(&mut state)?;
53
54    pager_rs::finish()?;
55
56    Ok(())
57}
Source

pub fn help() -> Self

Default ‘help’ command

Examples found in repository?
examples/custom_command.rs (line 45)
3fn main() -> std::io::Result<()> {
4    let content = r#"Lorem ipsum dolor sit amet, consectetur adipiscing
5elit. Pellentesque neque nulla, viverra ac sapien
6et, ultricies convallis lectus. Suspendisse mattis
7in urna quis efficitur. Quisque mollis vulputate ipsum,
8ut auctor risus luctus eu. Donec sagittis convallis erat
9eget imperdiet. Aliquam massa erat, venenatis eu massa at,
10dignissim tempus massa. Donec blandit augue et malesuada
11fermentum. In vehicula, nisl ut scelerisque sagittis,
12sapien elit gravida enim, eu feugiat magna arcu sed enim.
13Fusce accumsan sodales ipsum lobortis feugiat. Pellentesque
14quam lectus, molestie vitae nisi a, tempor mollis mauris.
15Maecenas in magna tempus, porta augue bibendum, feugiat nulla."#
16        .to_string();
17
18    let status_bar =
19        StatusBar::new("Press 'p' to open selected line on seperate instance".to_string());
20
21    let mut state = State::new(
22        content,
23        status_bar,
24        CommandList::combine(vec![
25            CommandList(vec![Command {
26                cmd: vec![CommandType::Key(KeyCode::Char('p'))],
27                desc: "Open selected line on seperate instance".to_string(),
28                func: &|state| {
29                    let commands =
30                        CommandList::combine(vec![CommandList::quit(), CommandList::navigation()]);
31
32                    let mut modal = State::new(
33                        state.content.lines().nth(state.pos.1).unwrap().to_string(),
34                        StatusBar::new("Quit (q)".to_string()),
35                        commands,
36                    )
37                    .unwrap();
38                    modal.show_line_numbers = false;
39                    run(&mut modal).unwrap();
40                    true
41                },
42            }]),
43            CommandList::quit(),
44            CommandList::navigation(),
45            CommandList::help(),
46        ]),
47    )?;
48    state.show_line_numbers = false;
49
50    pager_rs::init()?;
51
52    pager_rs::run(&mut state)?;
53
54    pager_rs::finish()?;
55
56    Ok(())
57}
Source

pub fn toggle_line_numbers() -> Self

Default ‘toggle line numbers’ command

Source

pub fn toggle_word_wrap() -> Self

Default ‘toggle word wrap’ 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>,

Source§

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>,

Source§

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.