From 91510f1f0f092617cf54791ffb1adc2adfcb6baf Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Sat, 14 Oct 2023 23:22:02 +0300 Subject: [PATCH 1/7] Specify defaults for more `TemplateOptions` ...on deserialization --- src/svg/mod.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/svg/mod.rs b/src/svg/mod.rs index f91c762..fe5b634 100644 --- a/src/svg/mod.rs +++ b/src/svg/mod.rs @@ -52,25 +52,30 @@ pub enum LineNumbers { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct TemplateOptions { /// Width of the rendered terminal window in pixels. The default value is `720`. + #[serde(default = "TemplateOptions::default_width")] pub width: usize, /// Palette of terminal colors. The default value of [`Palette`] is used by default. + #[serde(default)] pub palette: Palette, /// CSS instructions to add at the beginning of the SVG ` + + + + + + + + +
+
1
$ rainbow --long-lines
+
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Base colors:
+black black/italic blue blue/italic green green/italic red red/italic cyan cyan/italic magenta magen
ta/italic
yellow yellow/italic +black black/italic blue blue/italic green green/italic red red/italic cyan cyan/italic magenta magen
ta/italic
yellow yellow/italic +Base colors (bg): +black blue green red cyan magenta yellow +black blue green red cyan magenta yellow +ANSI color palette: +!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?
!
?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?
!
?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?
!
?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?
!
?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!? +ANSI grayscale palette: +!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!? +24-bit colors: +pink orange brown teal
+
+
+
+ + + + + + HTML embedding not supported. + Consult term-transcript docs for details. + + + diff --git a/examples/generate-snapshots.sh b/examples/generate-snapshots.sh index 56fd877..9b0042c 100755 --- a/examples/generate-snapshots.sh +++ b/examples/generate-snapshots.sh @@ -129,3 +129,8 @@ term-transcript exec $TT_ARGS --palette gjm8 --window \ --font 'Fira Mono, Consolas, Liberation Mono, Menlo' \ --styles '@import url(https://code.cdn.mozilla.net/fonts/fira.css);' rainbow \ > "$ROOT_DIR/examples/fira.$EXTENSION" + +echo "Creating snapshot with custom config..." +term-transcript exec $TT_ARGS --config-path "$ROOT_DIR/examples/config.toml" \ + 'rainbow --long-lines' \ + > "$ROOT_DIR/examples/custom-config.$EXTENSION" From 9698f14cb43b76dc71f5ae12c12e3e85f66b907a Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Sat, 14 Oct 2023 23:48:01 +0300 Subject: [PATCH 5/7] Remove obsolete skipped dependency tree --- deny.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/deny.toml b/deny.toml index 387e879..40f72bb 100644 --- a/deny.toml +++ b/deny.toml @@ -36,8 +36,6 @@ skip = [ skip-tree = [ # Used by `tracing-subscriber` together with the new version :( { name = "regex-automata", version = "^0.1" }, - # Used by `clap` via `terminal_size`; likely to get updated soon. - { name = "rustix", version = "^0.37" }, ] [sources] From d1c9ec942ef9ca065e83e1ac750635fee931283a Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Sun, 15 Oct 2023 10:20:48 +0300 Subject: [PATCH 6/7] Document `TemplateOptions` serialization --- Cargo.lock | 1 + Cargo.toml | 1 + cli/src/template.rs | 4 +++- src/svg/data.rs | 1 - src/svg/mod.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 53 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 81a076f..5303bab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -853,6 +853,7 @@ dependencies = [ "serde_json", "termcolor", "test-casing", + "toml 0.8.2", "tracing", "tracing-capture", "tracing-subscriber", diff --git a/Cargo.toml b/Cargo.toml index 9644941..1390c05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ anyhow = "1.0.40" assert_matches = "1.5.0" doc-comment = "0.3.3" test-casing = "0.1.1" +toml = "0.8.2" tracing-capture = "0.1.0" tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } version-sync = "0.9.2" diff --git a/cli/src/template.rs b/cli/src/template.rs index 637f18c..cf7929c 100644 --- a/cli/src/template.rs +++ b/cli/src/template.rs @@ -56,6 +56,8 @@ impl From for svg::LineNumbers { #[derive(Debug, Args)] pub(crate) struct TemplateArgs { /// Path to the configuration TOML file. + /// + /// See https://slowli.github.io/term-transcript/term_transcript/svg/ for the configuration format. #[arg( long, conflicts_with_all = [ @@ -112,7 +114,7 @@ pub(crate) struct TemplateArgs { /// Path to a custom Handlebars template to use. `-` means not to use a template at all, /// and instead output JSON data that would be fed to a template. /// - /// See https://slowli.github.io/term-transcript/term_transcript/ for docs on templating. + /// See https://slowli.github.io/term-transcript/term_transcript/svg/ for docs on templating. #[arg(long = "tpl")] template_path: Option, /// File to save the rendered SVG into. If omitted, the output will be printed to stdout. diff --git a/src/svg/data.rs b/src/svg/data.rs index 31a2fea..14f634b 100644 --- a/src/svg/data.rs +++ b/src/svg/data.rs @@ -51,7 +51,6 @@ use crate::{svg::TemplateOptions, write::SvgLine, UserInput}; /// "white": "#f7f7fb", /// }, /// }, -/// "additional_styles": "", /// "font_family": "Consolas, Menlo, monospace", /// "window_frame": false, /// "wrap": { diff --git a/src/svg/mod.rs b/src/svg/mod.rs index 2446ea8..e5eaf36 100644 --- a/src/svg/mod.rs +++ b/src/svg/mod.rs @@ -2,7 +2,8 @@ //! //! The included templating logic allows rendering SVG images. Templating is based on [Handlebars], //! and can be [customized](Template#customization) to support differing layout or even -//! data formats (e.g., HTML). +//! data formats (e.g., HTML). The default template supports [a variety of options](TemplateOptions) +//! controlling output aspects, e.g. image dimensions and scrolling animation. //! //! [Handlebars]: https://handlebarsjs.com/ //! @@ -49,6 +50,52 @@ pub enum LineNumbers { } /// Configurable options of a [`Template`]. +/// +/// # Serialization +/// +/// Options can be deserialized from `serde`-supported encoding formats, such as TOML. This is used +/// in the CLI app to read options from a file: +/// +/// ``` +/// # use assert_matches::assert_matches; +/// # use term_transcript::svg::{RgbColor, TemplateOptions, WrapOptions}; +/// let options_toml = r#" +/// width = 900 +/// window_frame = true +/// line_numbers = 'continuous' +/// wrap.hard_break_at = 100 +/// scroll = { max_height = 300, pixels_per_scroll = 18, interval = 1.5 } +/// +/// [palette.colors] +/// black = '#3c3836' +/// red = '#b85651' +/// green = '#8f9a52' +/// yellow = '#c18f41' +/// blue = '#68948a' +/// magenta = '#ab6c7d' +/// cyan = '#72966c' +/// white = '#a89984' +/// +/// [palette.intense_colors] +/// black = '#5a524c' +/// red = '#b85651' +/// green = '#a9b665' +/// yellow = '#d8a657' +/// blue = '#7daea3' +/// magenta = '#d3869b' +/// cyan = '#89b482' +/// white = '#ddc7a1' +/// "#; +/// +/// let options: TemplateOptions = toml::from_str(options_toml)?; +/// assert_eq!(options.width, 900); +/// assert_matches!(options.wrap, Some(WrapOptions::HardBreakAt(100))); +/// assert_eq!( +/// options.palette.colors.green, +/// RgbColor(0x8f, 0x9a, 0x52) +/// ); +/// # anyhow::Ok(()) +/// ``` #[derive(Debug, Clone, Serialize, Deserialize)] pub struct TemplateOptions { /// Width of the rendered terminal window in pixels. The default value is `720`. From d7407ffdcc3b354461b7e0fb1ef835dacc907206 Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Sun, 15 Oct 2023 10:24:19 +0300 Subject: [PATCH 7/7] Update changelogs --- CHANGELOG.md | 5 +++++ cli/CHANGELOG.md | 1 + 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74a274b..4e60abe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ The project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html) ## [Unreleased] +### Changed + +- Allow configuring pixels per scroll using new `ScrollOptions.pixels_per_scroll` field. +- Change some default values and set more default values during `TemplateOptions` deserialization. + ## 0.3.0 - 2023-06-03 *(No substantial changes compared to the [0.3.0-beta.2 release](#030-beta2---2023-04-29))* diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index a6c3a1e..35fc4cd 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -9,6 +9,7 @@ The project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html) - Allow specifying the snapshot width in pixels using `--width`. - Allow specifying at which char to hard-break lines using `--hard-wrap`. +- Allow reading template configuration using `--config-path`. ### Changed