Cliffy

Ansi

The ansi module exports an ansi object with chainable methods and properties for generating ansi escape sequence strings. The last property must be invoked as a method to generate the ansi string.

import { ansi } from "@cliffy/ansi";

console.log(
  ansi.cursorUp.cursorLeft.eraseDown(),
);Copy

Arguments

If the last method takes some arguments, you have to invoke the .toString() method to generate the ansi string.

import { ansi } from "@cliffy/ansi";

console.log(
  ansi.cursorUp(2).cursorLeft.eraseDown(2).toString(),
);Copy

Uint8Array

Convert to Uint8Array:

import { ansi } from "@cliffy/ansi";

await Deno.stdout.write(
  ansi.cursorUp.cursorLeft.eraseDown.bytes(),
);Copy

Functional

You can also directly import the ansi escape methods from the ansi_escapes.ts module.

import { cursorTo, eraseDown, image, link } from "@cliffy/ansi/ansi-escapes";

const response = await fetch(
  "https://raw.githubusercontent.com/c4spar/deno-cliffy/main/logo.png",
);
const imageBuffer: ArrayBuffer = await response.arrayBuffer();

console.log(
  cursorTo(0, 0) +
    eraseDown() +
    image(imageBuffer, {
      width: 29,
      preserveAspectRatio: true,
    }) +
    "\n          " +
    link("Deno", "https://deno.com") +
    "\n",
);Copy