Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow skipping inputs in rendered transcripts #54

Merged
merged 11 commits into from
Apr 13, 2023
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
6 changes: 3 additions & 3 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{
use term_transcript::{
test::{MatchKind, TestConfig, TestOutputConfig, TestStats},
traits::SpawnShell,
Transcript, UserInput,
Transcript,
};

mod shell;
Expand Down Expand Up @@ -98,7 +98,7 @@ impl Command {
term_output.pop();
}

transcript.add_interaction(UserInput::command(command), term_output);
transcript.add_interaction(template.create_input(command), term_output);
template.render(&transcript)?;
}

Expand All @@ -107,7 +107,7 @@ impl Command {
inputs,
template,
} => {
let inputs = inputs.into_iter().map(UserInput::command);
let inputs = inputs.into_iter().map(|input| template.create_input(input));
let transcript = shell.create_transcript(inputs)?;
template.render(&transcript)?;
}
Expand Down
14 changes: 13 additions & 1 deletion cli/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{

use term_transcript::{
svg::{self, ScrollOptions, Template, TemplateOptions, WrapOptions},
Transcript,
Transcript, UserInput,
};

#[derive(Debug, Clone, ValueEnum)]
Expand Down Expand Up @@ -85,6 +85,9 @@ pub(crate) struct TemplateArgs {
/// by more viewers, but there may be rendering artifacts.
#[arg(long = "pure-svg", conflicts_with = "template_path")]
pure_svg: bool,
/// Hides all user inputs; only outputs will be rendered.
#[arg(long = "no-inputs")]
no_inputs: bool,
/// 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.
///
Expand Down Expand Up @@ -125,6 +128,15 @@ impl From<TemplateArgs> for TemplateOptions {
}

impl TemplateArgs {
pub fn create_input(&self, command: String) -> UserInput {
let input = UserInput::command(command);
if self.no_inputs {
input.hide()
} else {
input
}
}

pub fn render(mut self, transcript: &Transcript) -> anyhow::Result<()> {
let pure_svg = self.pure_svg;
let out_path = mem::take(&mut self.out);
Expand Down
21 changes: 20 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,26 @@ term-transcript exec -T 250ms --palette gjm8 \
Same snapshot generated using the pure SVG template (i.e., with the additional
`--pure-svg` flag):

![Numbering with line breaks](numbers-long-pure.svg)
![Numbering with line breaks, pure SVG](numbers-long-pure.svg)

## Hiding user inputs

Combined with line numbering and scrolling to test more features.

![Hidden user inputs](no-inputs-numbers.svg)

Generating command:

```shell
term-transcript exec -T 250ms --scroll --palette xterm \
--no-inputs --line-numbers continuous \
rainbow 'rainbow --short'
```

Same snapshot generated using the pure SVG template (i.e., with the additional
`--pure-svg` flag):

![Hidden user inputs, pure SVG](no-inputs-numbers-pure.svg)

## Custom fonts

Expand Down
12 changes: 12 additions & 0 deletions examples/generate-snapshots.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ term-transcript exec $TT_ARGS --scroll --palette xterm --line-numbers each-outpu
rainbow 'rainbow --short' \
> "$ROOT_DIR/examples/numbers-each-output.$EXTENSION"

echo "Creating snapshot with no inputs, --line-numbers continuous"
term-transcript exec $TT_ARGS --scroll --palette xterm \
--no-inputs --line-numbers continuous \
rainbow 'rainbow --short' \
> "$ROOT_DIR/examples/no-inputs-numbers.$EXTENSION"

echo "Creating snapshot with no inputs, --line-numbers continuous (pure SVG)"
term-transcript exec $TT_ARGS --scroll --palette xterm --pure-svg \
--no-inputs --line-numbers continuous \
rainbow 'rainbow --short' \
> "$ROOT_DIR/examples/no-inputs-numbers-pure.$EXTENSION"

echo "Creating snapshot with --line-numbers continuous-outputs"
term-transcript exec $TT_ARGS --scroll --palette powershell --line-numbers continuous-outputs \
rainbow 'rainbow --short' \
Expand Down
Loading