Skip to content

Commit

Permalink
Merge branch 'feat/basic_functions'
Browse files Browse the repository at this point in the history
  • Loading branch information
littletof committed Oct 20, 2021
2 parents 8d1c694 + 1c76070 commit 54dbe0b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Snapper 📷

> Snapper allows you to generate images of ANSI formatted text.
> 🚧 Project is WIP, expect breaking changes
# Usage

#### Set up puppeteer
> In the background the module uses [deno Puppeteer](https://deno.land/x/puppeteer@9.0.2), which is a wrapper around [Puppeteer](https://github.com/puppeteer/puppeteer).
Follow the [current setup steps](https://github.com/lucacasonato/deno-puppeteer#installation), the basic setups should be something like:

```bash
PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/puppeteer@9.0.2/install.ts

#windows
$env:PUPPETEER_PRODUCT='chrome'; deno run -A --unstable https://deno.land/x/puppeteer@9.0.2/install.ts
```

## Module

```ts
import { snap } from "https://deno.land/x/snapper/mod.ts";

await snap([
{content: `\x1b[42m \x1b[1m\x1b[37mSnapper\x1b[39m\x1b[22m 📷 \x1b[49m`, imageSavePath: 'snapper.png', viewport: {width: 145, height: 35}},
]);
```

> To run it, you will need `--allow-env`, `--allow-net`, `--allow-write`, `--allow-read`, `--unstable`.
The result should be a png file placed into `cwd+imageSavePath`:
![result](./docs/snapper.png)

When creating multiple images, provide your inputs to `snap` in bulk, otherwise, calling the function one-by-one will take a lot of time to finish.

To get whole image for the output, simply leave out the `viewport` property from the parameters.

> `height` cuts the image, while a small `width` will result in the content wrapping
# TODO

- [ ] Try polyfill DOM+canvas, use xterm without puppeteer
- [ ] Improve server, so it can be hosted as a standalone site
Binary file added docs/snapper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 2 additions & 11 deletions example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,5 @@ export async function runPrompt(): Promise<string> {
const res = await runPrompt();

await snap([
{content: res, imageSavePath: 'docs/kopo.png', viewport: {width: 700, height: 170}},
{content: res+res+`alm
alma
lmalma
lma
lm
asd
asf
dg
dfg`, imageSavePath: 'docs/kopo2.png'}
])
{content: `\x1b[42m \x1b[1m\x1b[37mSnapper\x1b[39m\x1b[22m 📷 \x1b[49m`, imageSavePath: 'snapper.png', viewport: {width: 145, height: 35}},
]);
2 changes: 1 addition & 1 deletion terminal_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<script src="./static/xterm/fitAddon.js"></script>
<style>
.terminal {
padding: 10px 10px 0;;
padding: 10px 10px 0; /* TODO allow to remove padding */
}
</style>
</head>
Expand Down

0 comments on commit 54dbe0b

Please sign in to comment.