Struct StatusBar

Source
pub struct StatusBar {
    pub line_layouts: Vec<StatusBarLayout>,
    pub title: String,
    pub theme: ContentStyle,
}
Expand description

StatusBar defination

Fields§

§line_layouts: Vec<StatusBarLayout>

Vec of StatusBarLayout for each StatusBar line.

§title: String

Title of StatusBar. It will be used as StatusBarLayoutItem::Title

§theme: ContentStyle

Theme for StatusBar.

See: 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)
2fn main() -> std::io::Result<()> {
3    let content = r#"fn main() {
4    println!("Hello World!");
5}"#
6    .to_string();
7
8    let status_bar = StatusBar::new("Hello World program in rust".to_string());
9
10    let mut state = State::new(content, status_bar, CommandList::default())?;
11
12    pager_rs::init()?;
13
14    pager_rs::run(&mut state)?;
15
16    pager_rs::finish()?;
17
18    Ok(())
19}
More examples
Hide additional examples
examples/read_file.rs (line 13)
3fn main() -> std::io::Result<()> {
4    let args: Vec<String> = env::args().collect();
5
6    if args.len() >= 2 {
7        let file_name = args[1].clone();
8
9        let mut file = File::open(file_name.clone())?;
10        let mut content = String::new();
11        file.read_to_string(&mut content)?;
12
13        let status_bar = StatusBar::new(file_name);
14
15        let mut state = State::new(content, status_bar, CommandList::default())?;
16
17        pager_rs::init()?;
18
19        pager_rs::run(&mut state)?;
20
21        pager_rs::finish()?;
22    } else {
23        eprintln!("Missing Filename");
24    }
25
26    Ok(())
27}
examples/custom_command.rs (line 19)
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 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)
3fn main() -> std::io::Result<()> {
4    let content = r#"fn main() {
5    println!("Hello World!");
6}"#
7    .to_string();
8
9    let theme = ContentStyle::new()
10        .with(Color::White)
11        .on(Color::Red)
12        .attribute(Attribute::Italic);
13    let status_bar = StatusBar::with_theme(
14        "Hello World program in rust with colored status bar".to_string(),
15        theme,
16    );
17
18    let mut state = State::new(content, status_bar, CommandList::default())?;
19
20    pager_rs::init()?;
21
22    pager_rs::run(&mut state)?;
23
24    pager_rs::finish()?;
25
26    Ok(())
27}
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 duplicate 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

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.