mirror of https://github.com/Aloxaf/silicon
Merge 95dc6970cf
into 7837ec85e4
This commit is contained in:
commit
da982b35c6
|
@ -105,7 +105,7 @@ EOF
|
|||
Highlight specified line
|
||||
|
||||
```bash
|
||||
silicon main.rs -o main.png --highlight-lines '1; 3-4'
|
||||
silicon main.rs -o main.png --highlight-lines '1;3-4'
|
||||
```
|
||||
|
||||
Custom the image
|
||||
|
|
|
@ -114,7 +114,7 @@ pub struct Config {
|
|||
#[structopt(long, short, value_name = "FONT", parse(from_str = parse_font_str))]
|
||||
pub font: Option<FontList>,
|
||||
|
||||
/// Lines to high light. rg. '1-3; 4'
|
||||
/// Lines to highlight. eg. '1-3;4'
|
||||
#[structopt(long, value_name = "LINES", parse(try_from_str = parse_line_range))]
|
||||
pub highlight_lines: Option<Lines>,
|
||||
|
||||
|
@ -126,6 +126,10 @@ pub struct Config {
|
|||
#[structopt(long, value_name = "PAD", default_value = "2")]
|
||||
pub line_pad: u32,
|
||||
|
||||
/// Add PAD padding to the right of the code.
|
||||
#[structopt(long, value_name = "PAD", default_value = "25")]
|
||||
pub code_pad_right: u32,
|
||||
|
||||
/// Line number offset
|
||||
#[structopt(long, value_name = "OFFSET", default_value = "1")]
|
||||
pub line_offset: u32,
|
||||
|
@ -281,7 +285,8 @@ impl Config {
|
|||
.shadow_adder(self.get_shadow_adder()?)
|
||||
.tab_width(self.tab_width)
|
||||
.highlight_lines(self.highlight_lines.clone().unwrap_or_default())
|
||||
.line_offset(self.line_offset);
|
||||
.line_offset(self.line_offset)
|
||||
.code_pad_right(self.code_pad_right);
|
||||
|
||||
Ok(formatter.build()?)
|
||||
}
|
||||
|
|
|
@ -15,6 +15,9 @@ pub struct ImageFormatter<T> {
|
|||
/// pad of top of the code area
|
||||
/// Default: 50
|
||||
code_pad_top: u32,
|
||||
/// pad of right of the code area
|
||||
/// Default: 25
|
||||
code_pad_right: u32,
|
||||
/// Title bar padding
|
||||
/// Default: 15
|
||||
title_bar_pad: u32,
|
||||
|
@ -57,6 +60,8 @@ pub struct ImageFormatter<T> {
|
|||
pub struct ImageFormatterBuilder<S> {
|
||||
/// Pad between lines
|
||||
line_pad: u32,
|
||||
/// Padding to the right of the code
|
||||
code_pad_right: u32,
|
||||
/// Show line number
|
||||
line_number: bool,
|
||||
/// Font of english character, should be mono space font
|
||||
|
@ -108,6 +113,12 @@ impl<S: AsRef<str> + Default> ImageFormatterBuilder<S> {
|
|||
self.line_pad = pad;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the pad on the right of the screen
|
||||
pub fn code_pad_right(mut self, pad: u32) -> Self {
|
||||
self.code_pad_right = pad;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the font
|
||||
pub fn font(mut self, fonts: Vec<(S, f32)>) -> Self {
|
||||
|
@ -164,6 +175,7 @@ impl<S: AsRef<str> + Default> ImageFormatterBuilder<S> {
|
|||
line_pad: self.line_pad,
|
||||
code_pad: 25,
|
||||
code_pad_top: if title_bar { 50 } else { 0 },
|
||||
code_pad_right: self.code_pad_right,
|
||||
title_bar_pad: 15,
|
||||
window_controls: self.window_controls,
|
||||
window_controls_width: 120,
|
||||
|
@ -205,7 +217,7 @@ impl<T: TextLineDrawer> ImageFormatter<T> {
|
|||
/// calculate the size of code area
|
||||
fn get_image_size(&mut self, max_width: u32, lineno: u32) -> (u32, u32) {
|
||||
(
|
||||
(max_width + self.code_pad).max(150),
|
||||
(max_width + self.code_pad_right).max(150),
|
||||
self.get_line_y(lineno + 1) + self.code_pad,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue