Skip to main content
Module

x/ink/README.md

Terminal string color for Deno
Go to Latest
File

ink

Terminal string color for deno

GitHub code size in bytes GitHub GitHub last commit GitHub Workflow Status

Run the welcome page for interactive demo:

deno run -A https://deno.land/x/ink/welcome.ts

Examples

import * as ink from 'https://deno.land/x/ink/mod.ts'

let text = ink.colorize('<red>Hello World</red>')
console.log(text)

Output:

- Hello World

You can use nested style:

import * as ink from 'https://deno.land/x/ink/mod.ts'

let text = ink.colorize('<bg-blue><red>Hello World</bg-blue></red>')

console.log(text)

Support tags [Simple Mode]

  • <b>: bold

  • <i>: italic

  • <u>: underline

  • <s>: strikethrough

  • <hidden>: hidden text

  • <inv>: inverted color

  • <dim>: dim light

  • <u>: underline

  • <red>: text red

  • <green>: text green

  • <blue>: text blue

  • <yellow>: text yellow

  • <magenta>: text magenta

  • <cyan>: text cyan

  • <white>: text white

  • <black>: text black

  • <bg-red>: background red

  • <bg-green>: background green

  • <bg-blue>: background blue

  • <bg-yellow>: background yellow

  • <bg-magenta>: background magenta

  • <bg-cyan>: background cyan

  • <bg-white>: background white

  • <bg-black>: background black

Alias to console

You can use the object terminal to call console.log, console.trace … directly form ink module.

import * as ink from 'https://deno.land/x/ink/mod.ts'

ink.terminal.log('<red>Hello</red> %s', '<b>World</b>')

Advanced mode

You can use html like style for advanced and nested mode using the ink tag:

import * as ink from 'https://deno.land/x/ink/mod.ts'

let result = ink.html("<ink style='color: #ff0000;font:bold;'>Hello World</ink>")
console.log(result);

ink also supports nested styles:

let html = `
<ink style="color: rgb(255, 0, 0); background-color: #00ff00;font: underline, bold">
    I'm Red, background Green, underlined and bold! 
    <ink style="background-color: rgb(0, 0, 0); font: italic;">
        My BG is black again, but I'm italic :(
    </ink>
    My BG is Green Again!
</ink>
No Format here
`

let result = ink.html(html)
console.log(result);

Output:

output

String Extension

ink also supports string extension:

import "https://deno.land/x/ink/mod.ts" //Import .toColor() extension

console.log("<ink style='color: #ff0000; font: bold'>Hello Deno</ink>".toColor())

Supported Styles

  • color: Hex Or RGB [#ff0000, rgb(0, 255, 0) …]
  • background-color: Hex Or RGB [#ff0000, rgb(0, 255, 0) …]
  • font: comma separated values [bold, dim, italic, underline, inverse, hidden, strikethrough]

Draw Image

Ink module also can draw a JPEG image from local or remote source into the terminal:

import * as ink from "./mod.ts"

await ink.drawImage("https://placekitten.com/50/50")

output

License

MIT

FOSSA Status