diff --git a/Cargo.lock b/Cargo.lock index 3d8e0f1..ec26b1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1985,7 +1985,7 @@ checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c" [[package]] name = "smd" -version = "0.2.8" +version = "0.2.10" dependencies = [ "crossterm 0.28.1", "dirs", diff --git a/Cargo.toml b/Cargo.toml index dd031dc..8bf4b90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "smd" -version = "0.2.8" +version = "0.2.10" edition = "2021" authors = ["Guilherme Prokisch "] homepage = "https://github.com/guilhermeprokisch/smd" diff --git a/README.md b/README.md index eb47643..58faefe 100644 --- a/README.md +++ b/README.md @@ -164,15 +164,33 @@ theme = "default" code_highlight_theme = "Solarized (dark)" max_image_width = 40 max_image_height = 13 -disable_images = false -disable_links = false +render_images = true +render_links = true +render_table_borders = false ``` - `theme`: Overall color scheme (default: "default") - `code_highlight_theme`: Theme for code syntax highlighting (default: "Solarized (dark)") - `max_image_width` and `max_image_height`: Maximum dimensions for rendered images -- `disable_images`: If true, images will not be rendered -- `disable_links`: If true, links will not be clickable +- `render_images`: If false, images will not be rendered +- `render_links`: If false, links will not be clickable +- `render_table_borders`: If true, tables will be rendered with ASCII borders (default: false) + +### Available Code Highlight Themes + +The `code_highlight_theme` option can be set to any of the following values: + +- "base16-ocean.dark" +- "base16-eighties.dark" +- "base16-mocha.dark" +- "base16-ocean.light" +- "InspiredGitHub" +- "Solarized (dark)" +- "Solarized (light)" + +These are the default themes provided by the syntect library. Choose the theme that best suits your terminal's color scheme and personal preferences. + +Note: The actual appearance of these themes may vary slightly depending on your terminal's color settings. ## Contributing diff --git a/src/main.rs b/src/main.rs index 1f40ee5..432fb0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,23 +36,23 @@ static DOCS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/docs"); #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Config { - pub theme: String, pub code_highlight_theme: String, pub max_image_width: Option, pub max_image_height: Option, pub render_images: bool, pub render_links: bool, + pub render_table_borders: bool, } impl Default for Config { fn default() -> Self { Config { - theme: "default".to_string(), code_highlight_theme: "Solarized (dark)".to_string(), max_image_width: Some(40), max_image_height: Some(13), render_images: true, render_links: true, + render_table_borders: false, } } } @@ -377,6 +377,7 @@ fn style_to_termcolor(style: &Style) -> Option { fn render_table(node: &Value) -> io::Result<()> { let mut stdout = StandardStream::stdout(ColorChoice::Always); + let config = get_config(); if let Some(children) = node["children"].as_array() { let mut column_widths = Vec::new(); @@ -398,7 +399,17 @@ fn render_table(node: &Value) -> io::Result<()> { // Render table for (i, row) in children.iter().enumerate() { if let Some(cells) = row["children"].as_array() { + // Top border for the first row + if i == 0 && config.render_table_borders { + print_horizontal_border(&column_widths, "┌", "┬", "┐")?; + } + print!("{}", get_indent()); + + if config.render_table_borders { + print!("│ "); + } + for (j, cell) in cells.iter().enumerate() { let content = cell["children"][0]["value"].as_str().unwrap_or(""); @@ -413,20 +424,59 @@ fn render_table(node: &Value) -> io::Result<()> { } print!("{: io::Result<()> { + print!("{}", get_indent()); + print!("{}", left); + for (i, width) in column_widths.iter().enumerate() { + print!("{}", "─".repeat(width + 2)); // +2 for the padding spaces + if i < column_widths.len() - 1 { + print!("{}", middle); + } + } + println!("{}", right); + Ok(()) +} + fn render_list(node: &Value) -> io::Result<()> { let is_ordered = node["ordered"].as_bool().unwrap_or(false); if let Ok(mut list_stack) = LIST_STACK.lock() {