[−][src]Crate unsegen_pager
An unsegen
widget for viewing files with additional features.
Examples:
extern crate unsegen; use std::io::{stdin, stdout}; use unsegen::base::Terminal; use unsegen::input::{Input, Key, ScrollBehavior}; use unsegen::widget::{RenderingHints, Widget}; use unsegen_pager::{Pager, PagerContent, SyntaxSet, SyntectHighlighter, ThemeSet}; fn main() { let stdout = stdout(); let stdin = stdin(); let stdin = stdin.lock(); let file = "path/to/some/file"; let syntax_set = SyntaxSet::load_defaults_nonewlines(); let syntax = syntax_set .find_syntax_for_file(&file) .unwrap() .unwrap_or(syntax_set.find_syntax_plain_text()); let theme_set = ThemeSet::load_defaults(); let theme = &theme_set.themes["base16-ocean.dark"]; let highlighter = SyntectHighlighter::new(syntax, theme); let mut pager = Pager::new(); pager.load( PagerContent::from_file(&file) .unwrap() .with_highlighter(&highlighter), ); let mut term = Terminal::new(stdout.lock()).unwrap(); for input in Input::read_all(stdin) { let input = input.unwrap(); input.chain( ScrollBehavior::new(&mut pager) .forwards_on(Key::Down) .forwards_on(Key::Char('j')) .backwards_on(Key::Up) .backwards_on(Key::Char('k')) .to_beginning_on(Key::Home) .to_end_on(Key::End), ); // Put more application logic here... { let win = term.create_root_window(); pager.draw(win, RenderingHints::default()); } term.present(); } }
Structs
HighlightInfo | Result of a highlighting operation (i.e., a call to Highlighter::highlight). |
LineNumberDecorator | Draw line numbers next to every line. |
NoDecorator | Do not draw line decoration. |
Pager | Main |
PagerContent | A collection of |
SyntaxDefinition | The main data structure representing a syntax definition loaded from a
|
SyntaxSet | A syntax set holds a bunch of syntaxes and manages loading them and the crucial operation of linking. |
SyntectHighlighter | A |
Theme | A theme parsed from a |
ThemeSet |
Enums
PagerError | All errors that can occur when operating on a |
Traits
Highlighter | Interface for anything that highlights the content of Pagers. |
LineDecorator | Interface for anything that is able to decorate lines, i.e., to draw something next to the left of a pager line, given some information about the line. |
PagerLine | Anything that represents a single line in a pager. Other than the main content (something
string-like) it may also store additional information that can be used by a |