Expand description
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.as_widget().draw(win, RenderingHints::default());
}
term.present();
}
}
Structs§
- Highlight
Info - Result of a highlighting operation (i.e., a call to Highlighter::highlight).
- Line
Number Decorator - Draw line numbers next to every line.
- NoDecorator
- Do not draw line decoration.
- Pager
- Main
Widget
, may (or may not) store content, but defines static types for content and decoration. - Pager
Content - A collection of
PagerLines
including information about the highlighting state and (if present) aLineDecorator
. - Syntax
Definition - The main data structure representing a syntax definition loaded from a
.sublime-syntax
file. You’ll probably only need these as references to be passed around to parsing code. - Syntax
Set - A syntax set holds a bunch of syntaxes and manages loading them and the crucial operation of linking.
- Syntect
Highlighter - A
Highlighter
using thesyntect
library as a backend. - Theme
- A theme parsed from a
.tmTheme
file. Contains fields useful for a theme list as well assettings
for styling your editor. - Theme
Set
Enums§
- Pager
Error - All errors that can occur when operating on a
Pager
or its contents.
Traits§
- Highlighter
- Interface for anything that highlights the content of Pagers.
- Line
Decorator - 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.
- Pager
Line - 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
Highlighter
.