Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions packages/preview/ansi-render/0.9.2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Changelog

## [0.9.2] - 2026-07-18

* Same behavior as `0` for empty control code.

## [0.9.1] - 2026-05-11

### Fixed

* Fixed `bold-is-bright` option rendering logic
* Removed workaround for under/overline with trailing whitespace

## [0.9.0] - 2026-05-06

### Added

* Added support for `CSI 22`

## [0.8.0] - 2024-12-29

### Added

* Added `rose-pine` theme

## [0.7.0] - 2024-12-12

### Changed

* Changed default entry point to `lib.typ`
* Added package details

## [0.6.1] - 2023-12-26

### Changed

* Changed default foreground color name to `default-fg`
* Slightly reduce pdf size by removing default box fill

## [0.6.0] - 2023-12-06

### Fixed

* Removed workaround for a bug in `raw` that fixed in Typst 0.10.0

## [0.5.1] - 2023-10-21

### Fixed

* Fixed height with empty newline

## [0.5.0] - 2023-09-29

### Added

* Added `bold-is-bright` option #2

### Changed

* Allow setting font to none #3
* Changed default font size to `1em`
* Use `raw` to render content now

### Fixed

* Fixed 8-bit colors 8-15 use the wrong colors #4

## [0.4.2] - 2023-09-24

### Added

* Added gruvbox themes #1

## [0.4.1] - 2023-09-22

### Changed

* Changed default font size to `9pt`
* Prevent `set` affects box layout from outside of the function

## [0.4.0] - 2023-09-13

### Added

* Added most options from [`block`]([https://](https://typst.app/docs/reference/layout/block/)) function with the same names and default values
* Added `vscode-light` theme

### Changed

* Changed outmost layout from `rect` to `block`
* Changed default theme to `vscode-light`

## [0.3.0] - 2023-09-09

### Added

* Added `radius` option, default is `3pt`

### Changed

* Changed default font size to `10pt`
* Changed default font to `Cascadia Code`
* Changed default theme to `solarized-light`

## [0.2.0] 2023-08-05

### Changed

* Changed coding style to kebab-case and two spaces

## [0.1.0] 2023-07-02

first release
21 changes: 21 additions & 0 deletions packages/preview/ansi-render/0.9.2/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 8LWXpg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
133 changes: 133 additions & 0 deletions packages/preview/ansi-render/0.9.2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# ANSI Escape Sequence Renderer

[![Tagged version](https://img.shields.io/github/v/tag/8LWXpg/typst-ansi-render)](https://github.com/8LWXpg/typst-ansi-render/tags)
[![GitHub Repo stars](https://img.shields.io/github/stars/8LWXpg/typst-ansi-render?style=flat)](https://github.com/8LWXpg/typst-ansi-render)
[![License on GitHub](https://img.shields.io/github/license/8LWXpg/typst-ansi-render)](https://github.com/8LWXpg/typst-ansi-render/blob/v0.9.2/LICENSE)
[![typst package](https://img.shields.io/badge/typst-package-239dad)](https://typst.app/universe/package/ansi-render)

This script provides a simple way to render text with ANSI escape sequences. Package `ansi-render` provides a function `ansi-render`, and a dictionary of themes `terminal-themes`.

## Usage

```typst
#import "@preview/ansi-render:0.9.2": *

#ansi-render(
string,
font: string or none,
size: length,
width: auto or relative length,

Check warning on line 19 in packages/preview/ansi-render/0.9.2/README.md

View check run for this annotation

Typst package check / @preview/ansi-render:0.9.2

packages/preview/ansi-render/0.9.2/README.md#L19

Syntax error in README. expected comma If this code block is not supposed to be parsed as a Typst source, please explicitely specify another language.
height: auto or relative length,

Check warning on line 20 in packages/preview/ansi-render/0.9.2/README.md

View check run for this annotation

Typst package check / @preview/ansi-render:0.9.2

packages/preview/ansi-render/0.9.2/README.md#L20

Syntax error in README. expected comma If this code block is not supposed to be parsed as a Typst source, please explicitely specify another language.
breakable: boolean,
radius: relative length or dictionary,

Check warning on line 22 in packages/preview/ansi-render/0.9.2/README.md

View check run for this annotation

Typst package check / @preview/ansi-render:0.9.2

packages/preview/ansi-render/0.9.2/README.md#L22

Syntax error in README. expected comma If this code block is not supposed to be parsed as a Typst source, please explicitely specify another language.
inset: relative length or dictionary,

Check warning on line 23 in packages/preview/ansi-render/0.9.2/README.md

View check run for this annotation

Typst package check / @preview/ansi-render:0.9.2

packages/preview/ansi-render/0.9.2/README.md#L23

Syntax error in README. expected comma If this code block is not supposed to be parsed as a Typst source, please explicitely specify another language.
outset: relative length or dictionary,

Check warning on line 24 in packages/preview/ansi-render/0.9.2/README.md

View check run for this annotation

Typst package check / @preview/ansi-render:0.9.2

packages/preview/ansi-render/0.9.2/README.md#L24

Syntax error in README. expected comma If this code block is not supposed to be parsed as a Typst source, please explicitely specify another language.
spacing: relative length or fraction,

Check warning on line 25 in packages/preview/ansi-render/0.9.2/README.md

View check run for this annotation

Typst package check / @preview/ansi-render:0.9.2

packages/preview/ansi-render/0.9.2/README.md#L25

Syntax error in README. expected comma If this code block is not supposed to be parsed as a Typst source, please explicitely specify another language.
above: relative length or fraction,

Check warning on line 26 in packages/preview/ansi-render/0.9.2/README.md

View check run for this annotation

Typst package check / @preview/ansi-render:0.9.2

packages/preview/ansi-render/0.9.2/README.md#L26

Syntax error in README. expected comma If this code block is not supposed to be parsed as a Typst source, please explicitely specify another language.
below: relative length or fraction,

Check warning on line 27 in packages/preview/ansi-render/0.9.2/README.md

View check run for this annotation

Typst package check / @preview/ansi-render:0.9.2

packages/preview/ansi-render/0.9.2/README.md#L27

Syntax error in README. expected comma If this code block is not supposed to be parsed as a Typst source, please explicitely specify another language.
clip: boolean,
bold-is-bright: boolean,
theme: terminal-themes.theme,
)
```

### Parameters

- `string` - string with ANSI escape sequences
- `font` - font name or none, default is `Cascadia Code`, set to `none` to use the same font as `raw`
- `size` - font size, default is `1em`
- `bold-is-bright` - boolean, whether bold text is rendered with bright colors, default is `false`
- `theme` - theme, default is `vscode-light`
- parameters from [`block`](https://typst.app/docs/reference/layout/block/) function with the same default value, only affects outmost block layout:
- `width`
- `height`
- `breakable`
- `radius`
- `inset`
- `outset`
- `spacing`
- `above`
- `below`
- `clip`

## Themes

see [themes](https://github.com/8LWXpg/typst-ansi-render/blob/v0.9.2/test/themes.pdf)

## Demo

see [demo.typ](https://github.com/8LWXpg/typst-ansi-render/blob/v0.9.2/test/demo.typ) [demo.pdf](https://github.com/8LWXpg/typst-ansi-render/blob/v0.9.2/test/demo.pdf)

```typst
#ansi-render(
"\u{1b}[38;2;255;0;0mThis text is red.\u{1b}[0m
\u{1b}[48;2;0;255;0mThis background is green.\u{1b}[0m
\u{1b}[38;2;255;255;255m\u{1b}[48;2;0;0;255mThis text is white on a blue background.\u{1b}[0m
\u{1b}[1mThis text is bold.\u{1b}[0m
\u{1b}[4mThis text is underlined.\u{1b}[0m
\u{1b}[38;2;255;165;0m\u{1b}[48;2;255;255;0mThis text is orange on a yellow background.\u{1b}[0m",
inset: 5pt, radius: 3pt,
theme: terminal-themes.vscode
)
```

![RGB color with bold and underlined text](https://github.com/8LWXpg/typst-ansi-render/blob/v0.9.2/img/1.png?raw=true)

```typst
#ansi-render(
"\u{1b}[38;5;196mRed text\u{1b}[0m
\u{1b}[48;5;27mBlue background\u{1b}[0m
\u{1b}[38;5;226;48;5;18mYellow text on blue background\u{1b}[0m
\u{1b}[7mInverted text\u{1b}[0m
\u{1b}[38;5;208;48;5;237mOrange text on gray background\u{1b}[0m
\u{1b}[38;5;39;48;5;208mBlue text on orange background\u{1b}[0m
\u{1b}[38;5;255;48;5;0mWhite text on black background\u{1b}[0m",
inset: 5pt, radius: 3pt,
theme: terminal-themes.vscode
)
```

![256 color](https://github.com/8LWXpg/typst-ansi-render/blob/v0.9.2/img/2.png?raw=true)

```typst
#ansi-render(
"\u{1b}[31;1mHello \u{1b}[7mWorld\u{1b}[0m

\u{1b}[53;4;36mOver and \u{1b}[35m Under!
\u{1b}[7;90mreverse\u{1b}[101m and \u{1b}[94;27mreverse",
inset: 5pt, radius: 3pt,
theme: terminal-themes.vscode
)
```

![16 color with overline and underline and reverse](https://github.com/8LWXpg/typst-ansi-render/blob/v0.9.2/img/3.png?raw=true)

```typst
// uses the font that supports ligatures
#ansi-render(read("./test/test.txt"), inset: 5pt, radius: 3pt, font: "Cascadia Code", theme: terminal-themes.putty)
```

![render file output](https://github.com/8LWXpg/typst-ansi-render/blob/v0.9.2/img/4.png?raw=true)

## Capturing ANSI Output

### Output to File

The most straight forward way is writing to a file then read that in Typst.

```bash
command > out.txt
```

### Other Method

If writing to a file doesn't work, that means the program will detect the output and trim ANSI sequence accordingly, which means we need a pty interface to execute the script, the following should work in Linux:

```bash
script "command" out.txt
exit
```

## About Default Font

Typst's default font for `raw` is `Dejavu Sans Mono`, but it has [incorrect top-edge](https://github.com/typst/typst/issues/2231), so the default is set to `Cascadia Code`, which is included in web editor.
Loading
Loading