[−][src]Struct syntect::easy::HighlightLines
Simple way to go directly from lines of text to colored tokens.
Depending on how you load the syntaxes (see the SyntaxSet
docs)
you can either pass this strings with trailing \n
s or without.
Examples
Prints colored lines of a string to the terminal
use syntect::easy::HighlightLines; use syntect::parsing::SyntaxSet; use syntect::highlighting::{ThemeSet, Style}; use syntect::util::{as_24_bit_terminal_escaped, LinesWithEndings}; // Load these once at the start of your program let ps = SyntaxSet::load_defaults_newlines(); let ts = ThemeSet::load_defaults(); let syntax = ps.find_syntax_by_extension("rs").unwrap(); let mut h = HighlightLines::new(syntax, &ts.themes["base16-ocean.dark"]); let s = "pub struct Wow { hi: u64 }\nfn blah() -> u64 {}"; for line in LinesWithEndings::from(s) { // LinesWithEndings enables use of newlines mode let ranges: Vec<(Style, &str)> = h.highlight(line, &ps); let escaped = as_24_bit_terminal_escaped(&ranges[..], true); println!("{}", escaped); }
Methods
impl<'a> HighlightLines<'a>
[src]
pub fn new(syntax: &SyntaxReference, theme: &'a Theme) -> HighlightLines<'a>
[src]
pub fn highlight<'b>(
&mut self,
line: &'b str,
syntax_set: &SyntaxSet
) -> Vec<(Style, &'b str)>
[src]
&mut self,
line: &'b str,
syntax_set: &SyntaxSet
) -> Vec<(Style, &'b str)>
Highlights a line of a file
Auto Trait Implementations
impl<'a> !Send for HighlightLines<'a>
impl<'a> Unpin for HighlightLines<'a>
impl<'a> !Sync for HighlightLines<'a>
impl<'a> UnwindSafe for HighlightLines<'a>
impl<'a> RefUnwindSafe for HighlightLines<'a>
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,