Skip to content

lambdalisue/deno-ansi-escape-code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ansi-escape-code

jsr denoland deno doc Test

Utilities to trim and parse ANSI escape sequence.

Usage

import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { trimAndParse } from "https://deno.land/x/ansi_escape_code/mod.ts";

const [trimmed, annotations] = trimAndParse(
  "\x1b[1mHe\x1b[30mll\x1b[31mo\x1b[m world",
);

assertEquals(trimmed, "Hello world");
assertEquals(annotations, [
  { offset: 0, raw: "\x1b[1m", csi: { sgr: { bold: true } } },
  { offset: 2, raw: "\x1b[30m", csi: { sgr: { foreground: 0 } } },
  { offset: 4, raw: "\x1b[31m", csi: { sgr: { foreground: 1 } } },
  { offset: 5, raw: "\x1b[m", csi: { sgr: { reset: true } } },
]);

License

The code follows MIT license written in LICENSE. Contributors need to agree that any modifications sent in this repository follow the license.