pub struct Syntax {
pub code: String,
pub language: String,
pub theme: String,
pub start_line: usize,
pub line_numbers: bool,
pub highlight: bool,
pub background_color: Option<Color>,
pub tab_size: usize,
}Expand description
A syntax-highlighted source code renderable.
Fields§
§code: StringThe source code.
language: StringThe language name (e.g. “rust”, “python”, “javascript”).
theme: StringOptional theme name.
start_line: usizeStarting line number (for line numbers).
line_numbers: boolIf true, show line numbers.
highlight: boolIf true, highlight the code.
background_color: Option<Color>Optional background color.
tab_size: usizeTab size.
Implementations§
Source§impl Syntax
impl Syntax
Sourcepub fn new(code: impl Into<String>, language: impl Into<String>) -> Self
pub fn new(code: impl Into<String>, language: impl Into<String>) -> Self
Create a new Syntax renderable for the given code and language.
Sourcepub fn theme(self, theme: impl Into<String>) -> Self
pub fn theme(self, theme: impl Into<String>) -> Self
Builder: set the syntect theme name (e.g. "base16-ocean.dark", "monokai").
Sourcepub fn line_numbers(self) -> Self
pub fn line_numbers(self) -> Self
Builder: enable line numbers in the rendered output.
Sourcepub fn start_line(self, n: usize) -> Self
pub fn start_line(self, n: usize) -> Self
Builder: set the starting line number for display (default 1).
Sourcepub fn background(self, color: Color) -> Self
pub fn background(self, color: Color) -> Self
Builder: set a background color for the code block.
Trait Implementations§
Source§impl Renderable for Syntax
impl Renderable for Syntax
Source§fn render(&self, _options: &ConsoleOptions) -> RenderResult
fn render(&self, _options: &ConsoleOptions) -> RenderResult
Render this object into a
RenderResult using the provided options. Read moreSource§fn measure(&self, _options: &ConsoleOptions) -> Option<Measurement>
fn measure(&self, _options: &ConsoleOptions) -> Option<Measurement>
Optional width-measurement hook (equivalent to
__rich_measure__).
Override to provide min/max width constraints for layout.Auto Trait Implementations§
impl Freeze for Syntax
impl RefUnwindSafe for Syntax
impl Send for Syntax
impl Sync for Syntax
impl Unpin for Syntax
impl UnsafeUnpin for Syntax
impl UnwindSafe for Syntax
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