Skip to content

Commit

Permalink
add more pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaoboy committed May 21, 2024
1 parent ea3ca36 commit 8d6878b
Show file tree
Hide file tree
Showing 20 changed files with 929 additions and 185 deletions.
197 changes: 194 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions ansi2-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,9 @@ edition = "2018"
[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["console_error_panic_hook"]

[dependencies]
wasm-bindgen = "0.2.84"
ansi2 = { path = "../ansi2" }
ansi2svg = { path = "../ansi2svg" }
ansi2html = { path = "../ansi2html" }

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.7", optional = true }

[dev-dependencies]
wasm-bindgen-test = "0.3.34"

# [profile.release]
# Tell `rustc` to optimize for small code size.
# opt-level = "s"
6 changes: 4 additions & 2 deletions ansi2-wasm/src-ts/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ async function main() {
program
.option("--format [type]", "output format", "svg")
.option("--theme [type]", "color theme", "vscode")
.option("--width [type]", "width", undefined)

program.parse();

const options = program.opts();
const theme = options.theme ?? "vscode";
const format = options.format ?? "svg";
const width = typeof options.width === 'undefined' ? undefined : +options.width;
switch (format) {
case "svg": {
console.log(to_svg(a, theme))
console.log(to_svg(a, theme, width))
break
}
case "html": {
console.log(to_html(a, theme))
console.log(to_html(a, theme, width))
break
}
}
Expand Down
6 changes: 4 additions & 2 deletions ansi2-wasm/src-ts/wasm/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
/**
* @param {string} s
* @param {string} theme
* @param {number | undefined} [width]
* @returns {string}
*/
export function to_svg(s: string, theme: string): string;
export function to_svg(s: string, theme: string, width?: number): string;
/**
* @param {string} s
* @param {string} theme
* @param {number | undefined} [width]
* @returns {string}
*/
export function to_html(s: string, theme: string): string;
export function to_html(s: string, theme: string, width?: number): string;

16 changes: 11 additions & 5 deletions ansi2-wasm/src-ts/wasm/index.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions ansi2-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use ansi2::theme::Theme;
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn to_svg(s: String, theme: String) -> String {
pub fn to_svg(s: String, theme: String, width: Option<usize>) -> String {
let theme: Theme = theme.as_str().into();
ansi2svg::to_svg(&s, theme)
ansi2::svg::to_svg(&s, theme, width)
}

#[wasm_bindgen]
pub fn to_html(s: String, theme: String) -> String {
pub fn to_html(s: String, theme: String, width: Option<usize>) -> String {
let theme: Theme = theme.as_str().into();
ansi2html::to_html(&s, theme)
ansi2::html::to_html(&s, theme, width)
}
2 changes: 2 additions & 0 deletions ansi2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ authors = ["ahaoboy"]

[dependencies]
nom = "7"
clap = { version = "4.5", features = ["derive"] }
html-escape= "0.2.13"
27 changes: 27 additions & 0 deletions ansi2/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Parse ansi strings and convert them to html and svg formats

```bash
neofetch | ansi2 --format=svg --theme=vscode > neofetch.svg

npm run bench:run | ansi2 --format=svg | resvg - -c > bench.png
```

## [ansi2](./ansi2)

```rs
use ansi2::{Canvas};

let canvas = Canvas::new(s);
for row in canvas.pixels.iter() {
for pixel in row.iter() {
// draw pixel
}
}
```

## 16colo
https://16colo.rs/pack/laz17/ll-darlaakacrystal.ans
```bash
cat ./ll-darlaakacrystal.ans | ansi2 --format=svg --width=80 > ll-darlaakacrystal.svg

```
Loading

0 comments on commit 8d6878b

Please sign in to comment.