pub struct State {
pub pos: (usize, usize),
pub size: (u16, u16),
pub content: String,
pub status_bar: StatusBar,
pub commands: CommandList,
pub show_line_numbers: bool,
/* private fields */
}
Fields§
§pos: (usize, usize)
Cursor position in content.
(x, y)
size: (u16, u16)
Size of terminal screen.
(width, height)
content: String
Content to show.
status_bar: StatusBar
status bar at the bottom.
commands: CommandList
§show_line_numbers: bool
Implementations§
source§impl State
impl State
sourcepub fn new(
content: String,
status_bar: StatusBar,
commands: CommandList
) -> Result<Self>
pub fn new( content: String, status_bar: StatusBar, commands: CommandList ) -> Result<Self>
Create new State
Examples found in repository?
examples/hello_world.rs (line 10)
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
examples/custom_bar_theme.rs (line 18)
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(())
}
examples/read_file.rs (line 15)
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 (lines 21-47)
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(())
}
pub fn is_running(&self) -> bool
sourcepub fn get_help_text(&self) -> String
pub fn get_help_text(&self) -> String
Default help text formatter
source§impl State
impl State
sourcepub fn get_visible(&self) -> String
pub fn get_visible(&self) -> String
Get text to be printed on terminal except for the StatusBar
.
Auto Trait Implementations§
impl Freeze for State
impl !RefUnwindSafe for State
impl !Send for State
impl !Sync for State
impl Unpin for State
impl !UnwindSafe for State
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more