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

telerin

v0.1.0

Published

Terminal/tileset renderer for web based games.

Downloads

4

Readme

Terminal/tileset renderer for web based games.

Example

import { Terminal } from "telerin";

let term = new Terminal(20, 20);
term.color = "red";
term.background = "#0000FF";
term.put(0, 0, 0x10);
term.write(10, 10, "Hello world");

// Wait for the tileset to load before rendering
term.tileset.onload = () => term.refresh();

// Make the canvas visible
document.body.append(term.canvas);

constructor

Creates a new terminal instance with a size in rows and columns.

new Terminal(20, 20);

To use a custom font/tileset pass the url and cell width/height.

new Terminal(20, 20, "mytiles.png", 16, 16);

codepage

By default the terminal uses CP437 for character mapping. Use the codepage property to setup an alternative map.

// Map char code 20 to char code 1
terminal.codepage = { 20: 1 };

scale

Resize the canvas to render at a larger scale.

// Render the canvas twice as big
terminal.scale(2);

layer

Set the current layer index.

terminal.layer = 3;

color

Sets the foreground color for subsequent drawing functions to use.

terminal.color = "red";
terminal.color = "#FF0000";
terminal.color = "rgb(255, 0, 0)";
terminal.color = "hsl(0, 50%, 50%)";

// Tiles will be drawn in their original colors
terminal.color = undefined;

background

Sets the background color for subsequent drawing functions to use.

terminal.background = "red";
terminal.background = "#FF0000";
terminal.background = "rgb(255, 0, 0)";
terminal.background = "hsl(0, 50%, 50%)";

// Tiles will be drawn without a background color
terminal.color = undefined;

clear

Clears the contents of all layers.

terminal.clear();

clearLayer

Clears the contents of the current layer.

terminal.clearLayer();

clip

Sets the clipping rectangle for the current layer.

// Clips content outside of a 3x4 rect at 1,2
terminal.clip(1, 2, 3, 4)

// Reset the clip area for the current layer
terminal.clip();

put

Puts a character code into a cell.

terminal.put(0, 0, 40);
terminal.put(0, 0, "@".charCodeAt(0));

Also supports passing an offset in pixels.

terminal.put(0, 0, 40, 3, -3);

write

Write a string of text.

terminal.write(0, 0, "Hello, world!");

Respects linebreaks, but does no wrapping.

box

Draws a box.

// Draws a 3x4 box at 1,2 using the default box drawing characters
terminal.write(1, 2, 3, 4);
// Using a custom set of box drawing characters
terminal.write(1, 2, 3, 4, "┌┐└┘─│");

refresh

Draws the contents of the terminal to the canvas.

terminal.refresh();

screenToGrid

Converts a point on the screen to terminal grid coordinates.

onmousemove = event => {
  let { x, y } = terminal.screenToGrid(event.x, event.y);
  // x, y are rounded grid coordinates
}