Skip to content

Commit

Permalink
feat: optimize image to terminal for WASM
Browse files Browse the repository at this point in the history
  • Loading branch information
BigJk committed Dec 25, 2023
1 parent e99307d commit 6c80dbe
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions system/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ func Fetch(name string, options ...Option) (string, error) {
return "", err
}

// If we are running in the browser, we reduce the color pair count to 2
// as the algorithm is very slow running in WASM.
if runtime.GOOS == "js" {
imejiOptions = append(imejiOptions, imeji.WithColorPairMax(2))
}

if res, err := getCache(hash); err == nil {
return string(res.([]byte)), nil
}
Expand Down Expand Up @@ -127,6 +133,12 @@ func FetchAnimation(name string, options ...Option) ([]string, error) {
return nil, err
}

// If we are running in the browser, we reduce the color pair count to 2
// as the algorithm is very slow running in WASM.
if runtime.GOOS == "js" {
imejiOptions = append(imejiOptions, imeji.WithColorPairMax(2))
}

if res, err := getCache(hash); err == nil {
return res.([]string), nil
}
Expand Down

0 comments on commit 6c80dbe

Please sign in to comment.