Struct pager_rs::StatusBar

source ·
pub struct StatusBar {
    pub line_layouts: Vec<StatusBarLayout>,
    pub title: String,
    pub theme: ContentStyle,
}

Fields§

§line_layouts: Vec<StatusBarLayout>§title: String§theme: ContentStyle

Implementations§

source§

impl StatusBar

source

pub fn new(title: String) -> Self

Create a StatusBar with title.

Examples found in repository?
examples/hello_world.rs (line 8)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fn main() -> std::io::Result<()> {
    let content = r#"fn main() {
    println!("Hello World!");
}"#
    .to_string();

    let status_bar = StatusBar::new("Hello World program in rust".to_string());

    let mut state = State::new(content, status_bar, CommandList::default())?;

    pager_rs::init()?;

    pager_rs::run(&mut state)?;

    pager_rs::finish()?;

    Ok(())
}
More examples
Hide additional examples
examples/read_file.rs (line 13)
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
fn main() -> std::io::Result<()> {
    let args: Vec<String> = env::args().collect();

    if args.len() >= 2 {
        let file_name = args[1].clone();

        let mut file = File::open(file_name.clone())?;
        let mut content = String::new();
        file.read_to_string(&mut content)?;

        let status_bar = StatusBar::new(file_name);

        let mut state = State::new(content, status_bar, CommandList::default())?;

        pager_rs::init()?;

        pager_rs::run(&mut state)?;

        pager_rs::finish()?;
    } else {
        eprintln!("Missing Filename");
    }

    Ok(())
}
examples/custom_command.rs (line 19)
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 with_theme(title: String, theme: ContentStyle) -> Self

Create a StatusBar with title and theme.

Examples found in repository?
examples/custom_bar_theme.rs (lines 13-16)
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
fn main() -> std::io::Result<()> {
    let content = r#"fn main() {
    println!("Hello World!");
}"#
    .to_string();

    let theme = ContentStyle::new()
        .with(Color::White)
        .on(Color::Red)
        .attribute(Attribute::Italic);
    let status_bar = StatusBar::with_theme(
        "Hello World program in rust with colored status bar".to_string(),
        theme,
    );

    let mut state = State::new(content, status_bar, CommandList::default())?;

    pager_rs::init()?;

    pager_rs::run(&mut state)?;

    pager_rs::finish()?;

    Ok(())
}
source

pub fn get_visible(&self, state: &State) -> StyledContent<String>

Get status bar text to be printed on terminal.

Trait Implementations§

source§

impl Clone for StatusBar

source§

fn clone(&self) -> StatusBar

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for StatusBar

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for StatusBar

source§

fn default() -> Self

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

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.