Skip to content

Commit

Permalink
only compress svg
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaoboy committed Oct 18, 2024
1 parent ece3f02 commit fad6d0b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
12 changes: 7 additions & 5 deletions ansi2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ fn main() {

let s = String::from_utf8_lossy(&buf);
let mut output = match format {

Check warning on line 73 in ansi2/src/main.rs

View workflow job for this annotation

GitHub Actions / upload-assets (x86_64-apple-darwin, macos-latest)

variable does not need to be mutable

Check warning on line 73 in ansi2/src/main.rs

View workflow job for this annotation

GitHub Actions / upload-assets (aarch64-apple-darwin, macos-latest)

variable does not need to be mutable

Check warning on line 73 in ansi2/src/main.rs

View workflow job for this annotation

GitHub Actions / upload-assets (x86_64-pc-windows-msvc, windows-latest, -C target-feature=+crt-static)

variable does not need to be mutable

Check warning on line 73 in ansi2/src/main.rs

View workflow job for this annotation

GitHub Actions / upload-assets (x86_64-pc-windows-gnu, windows-latest)

variable does not need to be mutable

Check warning on line 73 in ansi2/src/main.rs

View workflow job for this annotation

GitHub Actions / upload-assets (arm64ec-pc-windows-msvc, windows-latest)

variable does not need to be mutable

Check warning on line 73 in ansi2/src/main.rs

View workflow job for this annotation

GitHub Actions / upload-assets (aarch64-unknown-linux-musl, ubuntu-latest)

variable does not need to be mutable

Check warning on line 73 in ansi2/src/main.rs

View workflow job for this annotation

GitHub Actions / upload-assets (x86_64-unknown-linux-musl, ubuntu-latest)

variable does not need to be mutable

Check warning on line 73 in ansi2/src/main.rs

View workflow job for this annotation

GitHub Actions / upload-assets (x86_64-unknown-linux-gnu, ubuntu-latest)

variable does not need to be mutable
Format::Svg => to_svg(s, theme, width, base64, mode, args.light_bg, args.dark_bg),
Format::Svg => {
let mut svg = to_svg(s, theme, width, base64, mode, args.light_bg, args.dark_bg);
if args.compress {
svg = osvg::osvg(&svg).expect("compress error");
}
svg
}
Format::Html => to_html(&s, theme, width, base64, mode, args.light_bg, args.dark_bg),
Format::Text => to_text(&s, width),
};

if args.compress {
output = osvg::osvg(&output).expect("compress error");
}

println!("{}", output);
}
2 changes: 1 addition & 1 deletion assets/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

for i in win11 vitest 8bit-color 24bit-color nu-ls
do
cat "$i.ans" | node ../ansi2-wasm/bin/cli.js -c > "$i.svg"
cat "$i.ans" | node ../ansi2-wasm/bin/cli.js > "$i.svg"
cat "$i.ans" | node ../ansi2-wasm/bin/cli.js --mode=light -c > "$i-light.svg"
cat "$i.ans" | node ../ansi2-wasm/bin/cli.js --mode=dark -c > "$i-dark.svg"
echo "$i done"
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ neofetch | ansi2 --format=svg --light-bg=#FFFFFF --dark-bg=#181818 > neofetch.sv

Compressing using [osvg](https://github.com/ahaoboy/osvg) and [svgo](https://github.com/svg/svgo), this will increase the running time by several seconds, but can save half of the storage space.

Note: Since svgo removes media queries and css variables, it is only recommended to use it in a specific mode.

```bash
neofetch | ansi2 --format=svg --compress > neofetch.svg
neofetch | ansi2 --format=svg -c > neofetch.svg
Expand Down

0 comments on commit fad6d0b

Please sign in to comment.