From 2ca85e208b6f2688c86f6d94ce445a3bb9ee3d43 Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Thu, 13 Apr 2023 12:27:08 +0300 Subject: [PATCH 01/11] Extract `svg` module tests to separate file --- src/svg/mod.rs | 472 +---------------------------------------------- src/svg/tests.rs | 468 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 470 insertions(+), 470 deletions(-) create mode 100644 src/svg/tests.rs diff --git a/src/svg/mod.rs b/src/svg/mod.rs index fcebd2c..97c5274 100644 --- a/src/svg/mod.rs +++ b/src/svg/mod.rs @@ -18,6 +18,8 @@ use std::{fmt, io::Write}; mod data; mod helpers; mod palette; +#[cfg(test)] +mod tests; pub use self::{ data::{CreatorData, HandlebarsData, SerializedInteraction}, @@ -409,473 +411,3 @@ impl Template { .render_to_write(MAIN_TEMPLATE_NAME, &data, destination) } } - -#[cfg(test)] -mod tests { - use super::*; - use crate::{ExitStatus, Interaction, UserInput}; - - #[test] - fn rendering_simple_transcript() { - let mut transcript = Transcript::new(); - transcript.add_interaction( - UserInput::command("test"), - "Hello, \u{1b}[32mworld\u{1b}[0m!", - ); - - let mut buffer = vec![]; - Template::new(TemplateOptions::default()) - .render(&transcript, &mut buffer) - .unwrap(); - let buffer = String::from_utf8(buffer).unwrap(); - - assert!(buffer.starts_with(" + + + + + + + 1234567891011121314151617181920212223 + Base colors: +black blue green red cyan magenta yellow  +black blue green red cyan magenta yellow  +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  +Base colors: +black blue green red cyan magenta yellow  +black blue green red cyan magenta yellow  +Base colors (bg): +█████ ████ █████ ███ ████ ███████ ██████black blue green red cyan magenta yellow  +█████ ████ █████ ███ ████ ███████ ██████black blue green red cyan magenta yellow  + + + + + + diff --git a/examples/no-inputs-numbers.svg b/examples/no-inputs-numbers.svg new file mode 100644 index 0000000..3fdada8 --- /dev/null +++ b/examples/no-inputs-numbers.svg @@ -0,0 +1,114 @@ + + + + + + + + + +
+
$ rainbow
+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Base colors:
+black blue green red cyan magenta yellow 
+black blue green red cyan magenta yellow 
+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 
+
$ rainbow --short
+
18
19
20
21
22
23
Base colors:
+black blue green red cyan magenta yellow 
+black blue green red cyan magenta yellow 
+Base colors (bg):
+black blue green red cyan magenta yellow 
+black blue green red cyan magenta yellow 
+
+
+
+ + + +
+ + HTML embedding not supported. + Consult term-transcript docs for details. + +
+
From 9c9e2769df3edf24854a5e1d325dfd6a16668c0b Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Thu, 13 Apr 2023 14:54:33 +0300 Subject: [PATCH 09/11] Fix doc and end-to-end tests --- examples/rainbow.svg | 9 +++++---- src/svg/data.rs | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/rainbow.svg b/examples/rainbow.svg index 23952cb..40d6e2b 100644 --- a/examples/rainbow.svg +++ b/examples/rainbow.svg @@ -14,13 +14,14 @@ font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace; line-height: inherit; } - .user-input { + .input { margin: 0 -10px 6px; color: #e5e5e5; background: rgba(255, 255, 255, 0.1); padding: 2px 10px; } - .term-output { margin-bottom: 6px; } + .input-hidden { display: none; } + .output { margin-bottom: 6px; } .bold,.prompt { font-weight: bold; } .italic { font-style: italic; } .underline { text-decoration: underline; } @@ -59,8 +60,8 @@
-
$ rainbow
-
Base colors:
+            
$ rainbow
+
Base colors:
 black blue green red cyan magenta yellow 
 black blue green red cyan magenta yellow 
 Base colors (bg):
diff --git a/src/svg/data.rs b/src/svg/data.rs
index 6d8861e..8e89307 100644
--- a/src/svg/data.rs
+++ b/src/svg/data.rs
@@ -63,6 +63,7 @@ use crate::{svg::TemplateOptions, write::SvgLine, UserInput};
 ///         "input": {
 ///             "text": "rainbow",
 ///             "prompt": "$",
+///             "hidden": false,
 ///         },
 ///         "output_html": "Hello, world!",
 /// #       "output_svg": [{

From 9b56e154ace7c5ce0eae057f8dfe4e2a1ff60e63 Mon Sep 17 00:00:00 2001
From: Alex Ostrovski 
Date: Thu, 13 Apr 2023 15:03:58 +0300
Subject: [PATCH 10/11] cli: Link to examples readme from CLI readme

---
 cli/README.md | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/cli/README.md b/cli/README.md
index 0d120a4..4d52999 100644
--- a/cli/README.md
+++ b/cli/README.md
@@ -133,6 +133,7 @@ on the terminal size.
 
 See also [a shell script][generate-snapshots] used in the "parent" `term-transcript`
 crate to render examples; it uses all major commands and options of the CLI app.
+The snapshots generated by the script are showcased [in a dedicated file][examples-readme].
 
 ## License
 
@@ -153,3 +154,4 @@ shall be dual licensed as above, without any additional terms or conditions.
 [help-snapshot-link]: https://github.com/slowli/term-transcript/raw/HEAD/cli/tests/snapshots/help.svg?sanitize=true
 [`isatty`]: https://man7.org/linux/man-pages/man3/isatty.3.html
 [generate-snapshots]: https://github.com/slowli/term-transcript/blob/HEAD/examples/generate-snapshots.sh
+[examples-readme]: https://github.com/slowli/term-transcript/blob/HEAD/examples/README.md

From 3785b22a7fa66beec9d90a75e82c171cacbcaaf8 Mon Sep 17 00:00:00 2001
From: Alex Ostrovski 
Date: Thu, 13 Apr 2023 16:39:57 +0300
Subject: [PATCH 11/11] Update changelogs

---
 CHANGELOG.md     | 2 ++
 cli/CHANGELOG.md | 1 +
 2 files changed, 3 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0a2658a..e2426d6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ The project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html)
 - Add a fallback error message to the default template if HTML-in-SVG embedding
   is not supported.
 - Add [FAQ](FAQ.md) with some tips and troubleshooting advice.
+- Allow hiding `UserInput`s during transcript rendering by calling the `hide()` method.
+  Hidden inputs are supported by the default and pure SVG templates.
 
 ### Changed
 
diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md
index 47e144a..bd11fcf 100644
--- a/cli/CHANGELOG.md
+++ b/cli/CHANGELOG.md
@@ -14,6 +14,7 @@ The project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html)
   As an example, this can be used to import fonts using `@import` or `@font-face`.
 - Support rendering pure SVG using `--pure-svg` option. See the library changelog and FAQ
   for more details.
+- Allow hiding all user inputs in a rendered transcript by specifying the `--no-inputs` flag.
 
 ## 0.3.0-beta.1 - 2023-01-19