Skip to content

Commit

Permalink
ansi-render:0.4.0 (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
8LWXpg committed Sep 13, 2023
1 parent 408c4c6 commit d691ac9
Show file tree
Hide file tree
Showing 5 changed files with 656 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/preview/ansi-render/0.4.0/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Changelog 📝

## [0.4.0] - 2023-09-13

### Added

* Added most options from [`block`]([https://](https://typst.app/docs/reference/layout/block/)) function
* 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.4.0/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.
111 changes: 111 additions & 0 deletions packages/preview/ansi-render/0.4.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# ANSI Escape Sequence Renderer

<a href="https://github.com/8LWXpg/typst-ansi-render/tags">
<img alt="GitHub manifest version (path)" src="https://img.shields.io/github/v/tag/8LWXpg/typst-ansi-render">
</a>
<a href="https://github.com/8LWXpg/typst-ansi-render">
<img src="https://img.shields.io/github/stars/8LWXpg/typst-ansi-render" alt="GitHub Repo stars">
</a>
<a href="https://github.com/8LWXpg/typst-ansi-render/blob/master/LICENSE">
<img alt="GitHub" src="https://img.shields.io/github/license/8LWXpg/typst-ansi-render">
</a>

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`.

contribution is welcomed!

## Usage

```typst
#import "@preview/ansi-render:0.4.0": *
#ansi-render(
string,
font: string,
size: length,
width: auto or relative length,
height: auto or relative length,
breakable: boolean,
radius: relative length or dictionary,
inset: relative length or dictionary,
outset: relative length or dictionary,
spacing: relative length or fraction,
above: relative length or fraction,
below: relative length or fraction,
clip: boolean,
theme: terminal-themes.theme,
)
```

### Parameters

most parameters comes from [`block`]([https://](https://typst.app/docs/reference/layout/block/)) function, adjust the layout outmost block.

- `string` - string with ANSI escape sequences
- `font` - font name, default is `Cascadia Code`
- `size` - font size, default is `10pt`
- `theme` - theme, default is `VSCode Light`
- parameters from [`block`]([https://](https://typst.app/docs/reference/layout/block/)) function with the same default value, change to adjust the outmost layout:
- `width`
- `height`
- `breakable`
- `radius`
- `inset`
- `outset`
- `spacing`
- `above`
- `below`
- `clip`

## Demo

see [demo.typ](https://github.com/8LWXpg/typst-ansi-render/blob/master/demo.typ) [demo.pdf](https://github.com/8LWXpg/typst-ansi-render/blob/master/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
",
theme: terminal-themes.vscode
)
```

![1.png](https://github.com/8LWXpg/typst-ansi-render/blob/master/img/1.png)

```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",
theme: terminal-themes.vscode
)
```

![2.png](https://github.com/8LWXpg/typst-ansi-render/blob/master/img/2.png)

```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",
theme: terminal-themes.vscode
)
```

![3.png](https://github.com/8LWXpg/typst-ansi-render/blob/master/img/3.png)

```typst
// uses the font that supports ligatures
#ansi-render(read("test.txt"), font: "CaskaydiaCove Nerd Font Mono", theme: terminal-themes.putty)
```

![4.png](https://github.com/8LWXpg/typst-ansi-render/blob/master/img/4.png)
Loading

0 comments on commit d691ac9

Please sign in to comment.