npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cli-canvas

v0.6.0

Published

A no-dependency package for drawing terminal graphics efficiently

Downloads

4

Readme

Cli-Canvas

A no-dependency package for rendering terminal graphics efficiently

What cli-canvas ISN'T

cli-canvas is not an implementation of the Canvas API, don't expect it to do the same things the same way

What it IS

cli-canvas is used to render graphics using buffers, so as to reduce reduce redraws, lowering the 'flicker' that terminal graphics often have.

Documentation

Setup

const cliCanves = require("cli-canvas");

let ctx = new cliCanvas.Context();
ctx.begin();
// All rendering goes between begin() and end()
ctx.end();

Rendering Primitives

Note, (0, 0) is top left, and (width, height) is bottom right.

ctx.point(x, y, character)

  • character can be any string, but only the first character will be drawn

ctx.line(x, y, width, height[, character])

  • character defaults to ctx.style.line

ctx.rect(x, y, width, height[, character])

  • character defaults to ctx.style.line

ctx.filledRect(x, y, width, height[, fillCharacter, lineCharacter])

  • fillCharacter defaults to ctx.style.fill
  • lineCharacter defaults to ctx.style.line

ctx.text(x, y, string)

Working With Style & Color

Render characters are controlled by the ctx.style object (Class cliCanvas.Style)

Examples

// Render in (243, 54, 190) on black, change line symbol to 'M'
ctx.style.line = "M";
ctx.style.foreground = cliCanvas.Color.rgb(243, 54, 190);
ctx.style.background = cliCanvas.Color.Black;

Default Style Values:

line = "X";
fill = "O";
empty = " ";

// Borders & Corers
top = "\u2550";
bottom = "\u2550";
left = "\u2551";
right = "\u2551";

topLeft = "\u2554";
topRight = "\u2557";
bottomLeft = "\u255A";
bottomRight = "\u255D";

// Colors
foreground = Color.DefaultFG;
Background = Color.DefaultBG;

Events

Event handlers can be set through ctx.on("event", callback)

Current Events

  • resize: calls callback on terminal resize

Public Variables

  • ctx.width Width of canvas
  • ctx.height Height of canvas
  • ctx.style Style properties
  • cliCanvas.Style.Color terminal color object, has some predefined colors
  • cliCanvas.Style.Color.rgb(0-255, 0-255, 0-255) returns a terminal color
  • cliCanvas.Style(params) Style object constructor, params is object with values

Changelog

v0.6.0

  • Added floating point support
  • Added transform support

v0.5.0

  • Updated color support to accommodate 256 colors

v0.4.2

  • Fixed bug with passing non strings to point()

v0.4.1

  • Improved documentation

v0.4.0

  • Improved color API

v0.3.0

  • Early color support, expect it to change

v0.2.0

  • Style object
  • Rectangle
  • Filled Rectangle
  • Text

Fixed:

  • Gaps in line()