• Stars
    star
    6
  • Rank 2,539,965 (Top 51 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

String based text rendering for Node and Browser

ASCII Canvas Logo

npm LICENSE MIT

ASCII canvas is library that help position elements on the screen.

I can be used with Node.js or Browser to render ASCII Text. I can be used with other ASCII libraries like charts and position them on the screen.

Installation

npm install ascii-canvas

Usage

Node

const { Canvas, Item } = require('ascii-canvas');
// or
import { Canvas, Item } from 'ascii-canvas';

Browser

<script src="https://unpkg.com/ascii-canvas"></script>
<script>
const { Canvas, Item } = canvas;
</script>

Example

const ROWS = 24;
const COLS = 80;
const my_canvas = new Canvas(COLS, ROWS);

// see boxen on npm
const str = boxen('unicorn', { padding: 1 });

const x_start = 10;
const y_start = 5;

myCanvas.append(new Item(frame()));

for (var i = 0; i < 3; ++i) {
  const x = i * 10;
  const y = i * 3;
  const box = new Item(str, { x: x_start + x, y: y_start + y });
  my_canvas.append(box);
}

console.log(my_canvas.toString());

// functions to render box frame
function rep(str, count) {
    return new Array(count).fill(str).join('');
}

function frame() {
    const output = [];
    const x_count = COLS - 2;
    const y_Count = ROWS - 2;
    output.push(`+${rep('-', x_count)}+`);
    for (let i = 0; i < y_Count; ++i) {
        output.push(`|${rep(' ', x_count)}|`);
    }
    output.push(`+${rep('-', x_count)}+`);
    return output.join('\n');
}

Terminal Screenshot

Demo

Browser Demo. To see demo in Node.js you need to do those steps.

# clone repo
git clone https://github.com/jcubic/ascii-canvas.git
cd ascii-canvas
# install dev dependencies (including example ASCII libraries)
npm install
# run the code
node --experimental-modules ./demo/demo.js

API

  • Canvas
class Canvas {
    constructor(width, height, { overflow: true || false });
    remove(item);
    resize(width, height);
    append(item);
    toString();
    get children;
}
  • Item
class Item {
    constructor(string, {x, y, z});
    clone();
    remove();
    update(string)
    move({x,y,z});
    get width;
    get height;
    get x;
    get y;
    get z;
    get rect;
}

Changelog

0.3.0

  • add Canvas::resize
  • add read only Canvas::children
  • add overflow option to Canvas
  • fix negative y when rendering item
  • add read only Item::rect/width/height
  • rename Canvas::remove_child() to Canvas::remove()

0.2.0

  • add Item::remove
  • fix Item::clone

0.1.2

  • throw exception when x or y outside of Canvas dimensions

0.1.1

  • fix infinite loop when x or y is float

0.1.0

  • Initial version

License

Copyright (C) 2020-2023 Jakub T. Jankiewicz [email protected]
Released with MIT License

More Repositories

1

jquery.terminal

jQuery Terminal Emulator - JavaScript library for creating web-based terminals with custom commands
JavaScript
2,940
star
2

sysend.js

Web application synchronization between different tabs
JavaScript
1,025
star
3

wayne

Service Worker Routing library for in browser HTTP requests
JavaScript
547
star
4

lips

Scheme based powerful lisp interpreter written in JavaScript
JavaScript
323
star
5

chat-gpt

ChatGPT conversation saving bookmark
JavaScript
291
star
6

tagger

Zero Dependency, Vanilla JavaScript Tag Editor
JavaScript
261
star
7

jquery.splitter

jQuery Splitter is plugin that split your content with movable splitter between them
JavaScript
240
star
8

gaiman

Gaiman: Text based game engine and programming language
JavaScript
137
star
9

leash

Browser Shell
JavaScript
120
star
10

jquery.rotate

Simple plugin that add rotate css property and animation
JavaScript
94
star
11

git

GIT Web Terminal
JavaScript
82
star
12

Clarity

Customizable Monoshape Vector Icon Theme for GTK+
SVG
39
star
13

jquery.filebrowser

File browser jQuery plugin
JavaScript
30
star
14

jquery.terminal-www

jQuery Terminal Website
HTML
26
star
15

favloader

Vanilla JavaScript library for loading animation in favicon
JavaScript
23
star
16

cmatrix

Render Matrix effect animation on Canvas in JavaScript
JavaScript
22
star
17

lily

Simple JavaScript options parser inspired by yargs
JavaScript
21
star
18

jsh.php

Terminal like php shell (PHP web terminal emulator)
PHP
20
star
19

jsvi

fork of JSVI - VI in JavaScript
JavaScript
18
star
20

Monadic

JavaScript micro library - POC
JavaScript
16
star
21

fake-linux-terminal

Fake GNU/Linux, Unix, MacOS terminal based system
HTML
15
star
22

json-rpc

JSON-RPC implementaion in php and JavaScript
PHP
13
star
23

electron-terminal

Base for jQuery Terminal based Electron apps
JavaScript
12
star
24

route.js

Simple routing library that can be use on the server or in the browser
JavaScript
11
star
25

jquery.micro

Pico/Nano like editor for jquery.
JavaScript
11
star
26

coverage.el

Emacs minor mode for displaying code coverage
Emacs Lisp
10
star
27

chat

Simple Chat with Server Side Events, PHP and SQLite
PHP
8
star
28

prism-cli

Syntax highlighting for command line
JavaScript
7
star
29

try-python

Try Python website
Python
7
star
30

commodore64

Commodore 64 jQuery Terminal Demo
HTML
7
star
31

jquery.resize

Custom resize jQuery event for element
JavaScript
6
star
32

notes

Simple text based notes taking app
JavaScript
6
star
33

webrtc-share

Application for sharing files using WebRTC
PHP
6
star
34

jcubic.pl

Głównie JavaScript - blog głównie o Front-Endzie
PHP
5
star
35

awesome-ascii

List of Awesome ASCII libraries
5
star
36

ansidec

Unix formatting transformer in JavaScript
JavaScript
5
star
37

firepad

Simple firepad based source code editor
HTML
5
star
38

quizerach

Simple Quiz Maker Open Source App (WIP)
TypeScript
4
star
39

calendar

ASCII calendar that can be used in Node.js or Browser
JavaScript
4
star
40

angular.piechart

Angular 1.5 component for svg based piecharts
JavaScript
4
star
41

velvet

Vanilla JavaScript Universal CSS in JS library
TypeScript
4
star
42

jcubic

3
star
43

chess

Terminal based chess game
HTML
3
star
44

snapp

Simple Text based notes taking app
PHP
3
star
45

open-source-library

Template for JavaScript Open Source library
Makefile
3
star
46

ToME

ToME - Tales of Middle Earth
C
3
star
47

leash-cordova

Cordova leash shell
JavaScript
3
star
48

filter-paste-js

intercept content pasting into iframe with design mode
JavaScript
3
star
49

fs-browser

In Browser File System App
JavaScript
3
star
50

jquery-position-event

jQuery cursor position change event
JavaScript
2
star
51

isomorphic-lolcat

Lolcat gradient that can be used in browser or Node
JavaScript
2
star
52

react-wayne-auth

JavaScript
2
star
53

koduj-curriculum

Curriculum for teaching programming using JavaScript and p5.js library
2
star
54

dotfiles

Linux dotfiles
Shell
2
star
55

cataloger

Shopping cart like catalog library
JavaScript
2
star
56

json-rpc-list

List of JSON-RPC implementations
2
star
57

compickr

Flickr composition checker
JavaScript
2
star
58

jankiewicz

Personal Blog of Jakub T. Jankiewicz
Liquid
2
star
59

aimed

Simple JavaScript Markdown Editor
JavaScript
2
star
60

yapp

Yet Another PHP Proxy
JavaScript
2
star
61

kopalinski.sqlite

Słownik Wyrazów Obcych Kopalińskiego jako baza sqlite
Python
2
star
62

koduj

P5.js playground
PHP
2
star
63

static

static files used with cdn.jsdelivr.net
JavaScript
2
star
64

opensourcelogo

Logo for you Open Source project
2
star
65

price.py

Scraping prices from Ceneo.pl and save in SQLite database
Python
1
star
66

php-terminal-jwt

Demo of JWT with jQuery Terminal
PHP
1
star
67

refClass

R
1
star
68

jquery.draglessClick

Better jQuery click event that's not invoked when you drag or select text
JavaScript
1
star
69

swift.manager

Server file browser and terminal with apps support
JavaScript
1
star
70

bassel.jcubic.pl

Bassel badge page
PHP
1
star
71

roman

ReactJS application with unit tests
TypeScript
1
star
72

REPL

REPL Bookmarklets for different languages
1
star
73

Similar-Stuff

Get Similar stuff from tastekid.com
Python
1
star
74

expression.php

Safely evaluate math, string, and boolean expressions
PHP
1
star
75

cv

My resume
Makefile
1
star
76

quatro

Simple Q&A Open Source application in PHP
PHP
1
star
77

interactive-scheme-tutorial

Interactive Scheme Tutorial
HTML
1
star
78

Downloader

Command Line tool for download file from file hosting sites.
Ruby
1
star
79

gps.py

Simple script to add GPS EXIF data to images
Python
1
star
80

flash-3d

School project 3D Flash animation in C++
C
1
star
81

FizzBuzz

JavaScript version of function only FizzBuzz
JavaScript
1
star
82

uncp

UNsplash Cache Proxy
PHP
1
star
83

jsvi-app

jsvi app for leash shell
JavaScript
1
star
84

bash

Bash Interpreter written in JavaScript
1
star