diff --git a/README.md b/README.md index dd7eb5e..0538589 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/bin/silicon/config.rs b/src/bin/silicon/config.rs index 13e40d0..eb4311f 100644 --- a/src/bin/silicon/config.rs +++ b/src/bin/silicon/config.rs @@ -114,7 +114,7 @@ pub struct Config { #[structopt(long, short, value_name = "FONT", parse(from_str = parse_font_str))] pub font: Option, - /// 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, @@ -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()?) } diff --git a/src/formatter.rs b/src/formatter.rs index 72f7597..7a39798 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -15,6 +15,9 @@ pub struct ImageFormatter { /// 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 { pub struct ImageFormatterBuilder { /// 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 + Default> ImageFormatterBuilder { 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 + Default> ImageFormatterBuilder { 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 ImageFormatter { /// 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, ) }