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

feat: add more pattern to support 16colo #2

Merged
merged 3 commits into from
May 21, 2024
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
205 changes: 198 additions & 7 deletions Cargo.lock

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

17 changes: 1 addition & 16 deletions ansi2-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
[package]
name = "ansi2-wasm"
version = "0.1.0"
version = "0.1.1"
authors = ["ahaoboy <[email protected]>"]
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"
2 changes: 1 addition & 1 deletion ansi2-wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ansi2",
"version": "0.1.4",
"version": "0.1.5",
"description": "ansi2",
"main": "dist/index.js",
"bin": "./bin/cli.js",
Expand Down
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)
}
4 changes: 3 additions & 1 deletion ansi2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ansi2"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
license = "MIT"
description = "ansi2"
Expand All @@ -10,3 +10,5 @@ authors = ["ahaoboy"]

[dependencies]
nom = "7"
clap = { version = "4.5", features = ["derive"] }
html-escape= "0.2.13"
Loading