All Projects β†’ ghaiklor β†’ Terminal Canvas

ghaiklor / Terminal Canvas

Licence: mit
Manipulate the cursor in your terminal via high-performant, low-level, canvas-like API

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Terminal Canvas

Imgcat
It's like cat, but for images.
Stars: ✭ 577 (+361.6%)
Mutual labels:  terminal, ansi
Unicute
πŸ’™ Cute Unicode symbols. Make the terminal GREAT AGAIN
Stars: ✭ 35 (-72%)
Mutual labels:  terminal, ansi
Diagram
CLI app to convert ASCII arts into hand drawn diagrams.
Stars: ✭ 642 (+413.6%)
Mutual labels:  terminal, canvas
Colorful
Terminal string styling done right, in Python 🐍 πŸŽ‰
Stars: ✭ 456 (+264.8%)
Mutual labels:  terminal, ansi
Rang
A Minimal, Header only Modern c++ library for terminal goodies πŸ’„βœ¨
Stars: ✭ 1,080 (+764%)
Mutual labels:  terminal, ansi
Termplay
GitLab: https://gitlab.com/jD91mZM2/termplay
Stars: ✭ 500 (+300%)
Mutual labels:  terminal, ansi
Pixterm
Draw images in your ANSI terminal with true color
Stars: ✭ 782 (+525.6%)
Mutual labels:  terminal, ansi
Canvasapi
Python API wrapper for Instructure's Canvas LMS. Easily manage courses, users, gradebooks, and more.
Stars: ✭ 306 (+144.8%)
Mutual labels:  wrapper, canvas
Crossline
A small, self-contained, zero-config, MIT licensed, cross-platform, readline and libedit replacement.
Stars: ✭ 53 (-57.6%)
Mutual labels:  terminal, cursor
Colorette
Easily set the color and style of text in the terminal.
Stars: ✭ 1,047 (+737.6%)
Mutual labels:  terminal, ansi
Mordant
Full-featured text styling for Kotlin command-line applications
Stars: ✭ 382 (+205.6%)
Mutual labels:  terminal, ansi
Progress.c
Progress display lib for c
Stars: ✭ 67 (-46.4%)
Mutual labels:  terminal, ansi
Hues
Colored terminal text made easy for Python and happiness.
Stars: ✭ 345 (+176%)
Mutual labels:  terminal, ansi
Termenv
Advanced ANSI style & color support for your terminal applications
Stars: ✭ 555 (+344%)
Mutual labels:  terminal, ansi
Paint
Ruby gem for ANSI terminal colors 🎨︎ VERY FAST
Stars: ✭ 317 (+153.6%)
Mutual labels:  terminal, ansi
Chafa
πŸ“ΊπŸ—Ώ Terminal graphics for the 21st century.
Stars: ✭ 774 (+519.2%)
Mutual labels:  terminal, ansi
Chalk
πŸ– Terminal string styling done right
Stars: ✭ 17,566 (+13952.8%)
Mutual labels:  terminal, ansi
Enigma Bbs
ENiGMAΒ½ BBS Software
Stars: ✭ 294 (+135.2%)
Mutual labels:  terminal, ansi
Crossterm
Cross platform terminal library rust
Stars: ✭ 1,023 (+718.4%)
Mutual labels:  terminal, cursor
Asciichart
Nice-looking lightweight console ASCII line charts β•­β”ˆβ•― for NodeJS, browsers and terminal, no dependencies
Stars: ✭ 1,107 (+785.6%)
Mutual labels:  terminal, ansi

terminal-canvas

Travis (.com) Codecov npm

GitHub Follow Twitter Follow

Manipulate the cursor in your terminal via high-performant, low-level, canvas-like API.

Entirely written with TypeScript, terminal-canvas exposes features that you can use for rendering in terminal. High-performance algorithms and optimizations allow to render only cells which have been changed. Just look at the demo videos below to see, what you can do with terminal-canvas πŸ˜ƒ

Demo

Touhou - Bad Apple (ASCII Art) Touhou - Bad Apple (Colorful Edition) Doom (Colorful Edition)
1 1 1

Getting Started

Install it via npm:

npm install terminal-canvas

Include in your project:

const Canvas = require('terminal-canvas');
const canvas = new Canvas();

canvas.moveTo(10, 10).write('Hello, world').flush();

Examples

A lot of examples are available to you here

API Reference

API Reference is accessible here

How terminal-canvas works

Control Sequences

terminal-canvas uses VT100 compatible control sequences to manipulate the cursor in the terminal.

You can find a lot of useful information about that here:

The next thing which terminal-canvas does is wrap those control codes, so you are able to call JavaScript methods.

Virtual Terminal

The first releases of the terminal-canvas (which was kittik-cursor) were based on real-time updating terminal cursor, when you are calling some method on the canvas.

This caused performance issues. So I decided to create my own wrapper around terminal cells.

Each real cell in the terminal has a wrapper (class Cell in the src folder). The main problem, which Cell resolves, is to render each cell independently from another cells. So I can grab any cell at any coordinate and render it independently from others.

It works the following way. Each Cell has style settings and position in the real terminal. When you are converting Cell to the control sequences, it concatenates the following sequences:

  1. Convert cell position to control sequence
  2. Convert foreground and background color to control sequence
  3. Convert display settings to control sequences
  4. Pre-pend the cell char with sequences above
  5. Reset all display settings to default

That way, each cell wrapped in own control sequences that can be flushed at any moment.

Difference between two frames

The last thing I did, was update only cells that really changed.

The algorithm is simple.

When you are writing to the canvas, all write operations mark virtual cells as modified cells. After some time, you decide to flush changes. When flush() method is called it does 2 things:

  1. Iterate through all cells and find only cells with modified marker;
  2. Convert modified cell to control sequence and compare that sequence with the sequence that was used at the previous frame;
  3. If they are not equal, store new control sequence and write to stream, otherwise, ignore it

That's how I made it possible to render videos in the terminal at 30 FPS.

BTW, if I remove Throttle stream, I'm getting 120 FPS πŸ˜ƒ

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].