Skip to content
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
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"imports": {
"playwright-core": "npm:playwright-core@^1.55.0",
"@std/assert": "jsr:@std/assert@^1.0.13",
"@std/cli": "jsr:@std/cli@1.0.17",
"@std/cli": "jsr:@std/cli@^1.0.17",
"@std/fmt": "jsr:@std/fmt@^1.0.7",
"@std/front-matter": "jsr:@std/front-matter@^1.0.9",
"@std/path": "jsr:@std/path@^1.0.9",
Expand Down
8 changes: 4 additions & 4 deletions deno.lock

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

60 changes: 60 additions & 0 deletions src/animation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { brightCyan, brightWhite, cyan } from "@std/fmt/colors";

export function createWaveAnimation(
text: string,
filePath: string,
): { start: () => void; stop: () => void } {
const DEFAULT_SPINNER = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
const fullText = ` ${text} ${filePath}`;
let intervalId: number | null = null;
let frame = 0;

const animate = () => {
const spinnerChar = DEFAULT_SPINNER[frame % DEFAULT_SPINNER.length];
const waveWidth = 4;
const wavePosition = (frame * 0.8) % (fullText.length + waveWidth);

// Spinner with cyan color, bright cyan in wave range
const spinnerDistance = Math.abs(0 - wavePosition);
let coloredText = "";
if (spinnerDistance < waveWidth) {
coloredText = brightCyan(spinnerChar);
} else {
coloredText = cyan(spinnerChar);
}

for (let i = 0; i < fullText.length; i++) {
const distance = Math.abs(i - wavePosition);

if (distance < waveWidth) {
// highlight with bright white
coloredText += brightWhite(fullText[i]);
} else {
// default white color
coloredText += fullText[i];
}
}

const encoder = new TextEncoder();
Deno.stdout.writeSync(encoder.encode(`\r${coloredText}`));
frame++;
};

return {
start: () => {
if (!intervalId) {
intervalId = setInterval(animate, 40);
}
},
stop: () => {
if (intervalId) {
clearInterval(intervalId);
intervalId = null;
const encoder = new TextEncoder();
Deno.stdout.writeSync(
encoder.encode(`\r${" ".repeat(fullText.length + 2)}\r`),
);
}
},
};
}
16 changes: 5 additions & 11 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* @module
*/

import { Spinner } from "@std/cli/unstable-spinner";
import { parseArgs } from "@std/cli/parse-args";
import {
bgBlue,
Expand All @@ -23,6 +22,7 @@ import {
} from "@std/fmt/colors";
import { mdToPdf } from "./md-to-pdf.ts";
import { getFilename } from "./utils/filename.ts";
import { createWaveAnimation } from "./animation.ts";
import type { MdToPdfOptions } from "./types.ts";

function printHelp(): void {
Expand All @@ -42,16 +42,16 @@ ${yellow("Options:")}
async function generatePdfFromMarkdown(path: string, options?: MdToPdfOptions) {
const pdfName = getFilename(path) + ".pdf";

spinner.message = " generating PDF from " + underline(path);
spinner.start();
const waveAnimation = createWaveAnimation("generating PDF from", path);
waveAnimation.start();
await mdToPdf(path, options).then(
(pdf) => {
Deno.writeFileSync(
pdfName,
pdf,
);
spinner.stop();
console.log("✅ generated " + underline(pdfName));
waveAnimation.stop();
console.log(green("✓") + " generated " + underline(pdfName));
},
);
}
Expand All @@ -68,12 +68,6 @@ if (args.h || args.help) {
Deno.exit(0);
}

const spinner = new Spinner({
message: "Loading...",
color: "yellow",
interval: 50,
});

const paths: Array<string> = [];
if (args._) {
for await (const path of args._) {
Expand Down