Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

antsy

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

antsy - npm Package Compare versions

Comparing version 3.0.3 to 4.0.0

12

lib/antsy.d.ts

@@ -1,6 +0,6 @@

export { Canvas, Region } from "./antsy/canvas";
export { Constraint, GridLayout } from "./antsy/grid_layout";
export { Key, KeyParser, KeyType, Modifier } from "./antsy/keys";
export { Terminal } from "./antsy/terminal";
export { TextBuffer } from "./antsy/text_buffer";
export { get_color, name_to_rgb, rgb_to_xterm, xterm_to_rgb } from "./antsy/xterm256";
export { Canvas, Region } from "./antsy/canvas.js";
export { Constraint, GridLayout } from "./antsy/grid_layout.js";
export { Key, KeyParser, KeyType, Modifier } from "./antsy/keys.js";
export { Terminal } from "./antsy/terminal.js";
export { TextBuffer } from "./antsy/text_buffer.js";
export { get_color, name_to_rgb, rgb_to_xterm, xterm_to_rgb } from "./antsy/xterm256.js";

@@ -1,22 +0,7 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var canvas_1 = require("./antsy/canvas");
Object.defineProperty(exports, "Canvas", { enumerable: true, get: function () { return canvas_1.Canvas; } });
Object.defineProperty(exports, "Region", { enumerable: true, get: function () { return canvas_1.Region; } });
var grid_layout_1 = require("./antsy/grid_layout");
Object.defineProperty(exports, "GridLayout", { enumerable: true, get: function () { return grid_layout_1.GridLayout; } });
var keys_1 = require("./antsy/keys");
Object.defineProperty(exports, "Key", { enumerable: true, get: function () { return keys_1.Key; } });
Object.defineProperty(exports, "KeyParser", { enumerable: true, get: function () { return keys_1.KeyParser; } });
Object.defineProperty(exports, "KeyType", { enumerable: true, get: function () { return keys_1.KeyType; } });
Object.defineProperty(exports, "Modifier", { enumerable: true, get: function () { return keys_1.Modifier; } });
var terminal_1 = require("./antsy/terminal");
Object.defineProperty(exports, "Terminal", { enumerable: true, get: function () { return terminal_1.Terminal; } });
var text_buffer_1 = require("./antsy/text_buffer");
Object.defineProperty(exports, "TextBuffer", { enumerable: true, get: function () { return text_buffer_1.TextBuffer; } });
var xterm256_1 = require("./antsy/xterm256");
Object.defineProperty(exports, "get_color", { enumerable: true, get: function () { return xterm256_1.get_color; } });
Object.defineProperty(exports, "name_to_rgb", { enumerable: true, get: function () { return xterm256_1.name_to_rgb; } });
Object.defineProperty(exports, "rgb_to_xterm", { enumerable: true, get: function () { return xterm256_1.rgb_to_xterm; } });
Object.defineProperty(exports, "xterm_to_rgb", { enumerable: true, get: function () { return xterm256_1.xterm_to_rgb; } });
export { Canvas, Region } from "./antsy/canvas.js";
export { GridLayout } from "./antsy/grid_layout.js";
export { Key, KeyParser, KeyType, Modifier } from "./antsy/keys.js";
export { Terminal } from "./antsy/terminal.js";
export { TextBuffer } from "./antsy/text_buffer.js";
export { get_color, name_to_rgb, rgb_to_xterm, xterm_to_rgb } from "./antsy/xterm256.js";
//# sourceMappingURL=antsy.js.map

@@ -1,2 +0,2 @@

import { TextBuffer } from "./text_buffer";
import { TextBuffer } from "./text_buffer.js";
export declare function computeDiff(oldBuffer: TextBuffer, newBuffer: TextBuffer): string;

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.computeDiff = void 0;
const terminal_1 = require("./terminal");
import { Terminal } from "./terminal.js";
// if we see this many blanks in a row, check if clear-to-end-of-line would help

@@ -15,2 +12,7 @@ const THRESHOLD_BLANKS = 8;

class ClearPoint {
attr;
bg;
x;
score;
chainScore;
constructor(attr, bg, // (attr >> 8) & 0xff, for convenience

@@ -29,2 +31,4 @@ x, score = CLEAR_STARTING_SCORE, // how much better is it to do this clrtoeol vs without?

class LineDistance {
distance;
clears;
constructor(distance, clears) {

@@ -44,6 +48,6 @@ this.distance = distance;

*/
function computeDiff(oldBuffer, newBuffer) {
export function computeDiff(oldBuffer, newBuffer) {
let out = "";
if (newBuffer.pendingClear) {
out += changeAttr(oldBuffer, newBuffer.pendingClear) + terminal_1.Terminal.clearScreen();
out += changeAttr(oldBuffer, newBuffer.pendingClear) + Terminal.clearScreen();
oldBuffer.clearBox(0, 0, oldBuffer.cols, oldBuffer.rows, newBuffer.pendingClear);

@@ -73,3 +77,3 @@ oldBuffer.cursorX = 0;

const c = distance.clears[0];
out += move(oldBuffer, c.x, y) + changeAttr(oldBuffer, c.attr, false) + terminal_1.Terminal.eraseLine();
out += move(oldBuffer, c.x, y) + changeAttr(oldBuffer, c.attr, false) + Terminal.eraseLine();
distance.clears.shift();

@@ -89,3 +93,3 @@ }

const c = distance.clears[0];
out += move(oldBuffer, c.x, y) + changeAttr(oldBuffer, c.attr, false) + terminal_1.Terminal.eraseLine();
out += move(oldBuffer, c.x, y) + changeAttr(oldBuffer, c.attr, false) + Terminal.eraseLine();
distance.clears.shift();

@@ -98,3 +102,2 @@ }

}
exports.computeDiff = computeDiff;
function computeRowDistance(oldBuffer, oldy, newBuffer, newy = oldy) {

@@ -220,7 +223,7 @@ // difference between source & dist lines, in # of cells that have to be redrawn

if (s.rows > 0) {
out += terminal_1.Terminal.scrollUp(s.top, s.bottom, s.rows);
out += Terminal.scrollUp(s.top, s.bottom, s.rows);
oldBuffer.scrollUp(0, s.top, oldBuffer.cols, s.bottom, s.rows, oldBuffer.attr);
}
else {
out += terminal_1.Terminal.scrollDown(s.top, s.bottom, -s.rows);
out += Terminal.scrollDown(s.top, s.bottom, -s.rows);
oldBuffer.scrollDown(0, s.top, oldBuffer.cols, s.bottom, -s.rows, oldBuffer.attr);

@@ -252,3 +255,3 @@ }

buffer.attr = attr;
return (oldfg != newfg ? terminal_1.Terminal.fg(newfg) : "") + ((oldbg != newbg) ? terminal_1.Terminal.bg(newbg) : "");
return (oldfg != newfg ? Terminal.fg(newfg) : "") + ((oldbg != newbg) ? Terminal.bg(newbg) : "");
}

@@ -261,7 +264,7 @@ // move cursor to (newX, newY)

if (oldX < 0 || oldY < 0)
return terminal_1.Terminal.move(newX, newY);
return Terminal.move(newX, newY);
if (oldX == newX && oldY == newY)
return "";
if (oldX == newX)
return terminal_1.Terminal.moveRelative(0, newY - oldY);
return Terminal.moveRelative(0, newY - oldY);
// vt100 quirk: if we think the cursor is "just off-screen", what really

@@ -272,4 +275,4 @@ // happened is that we wrote into the final column of the screen, and

if (oldY == newY && oldX < buffer.cols)
return terminal_1.Terminal.moveRelative(newX - oldX, 0);
return terminal_1.Terminal.move(newX, newY);
return Terminal.moveRelative(newX - oldX, 0);
return Terminal.move(newX, newY);
}

@@ -276,0 +279,0 @@ // *sings the song of my people*: "this should be in the stdlib"

@@ -1,3 +0,3 @@

/// <reference types="node" />
import { TextBuffer } from "./text_buffer";
/// <reference types="node" resolution-mode="require"/>
import { TextBuffer } from "./text_buffer.js";
export declare class Canvas {

@@ -4,0 +4,0 @@ cols: number;

@@ -1,8 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Region = exports.Canvas = void 0;
const canvas_diff_1 = require("./canvas_diff");
const terminal_1 = require("./terminal");
const text_buffer_1 = require("./text_buffer");
const xterm256 = require("./xterm256");
import { computeDiff } from "./canvas_diff.js";
import { Terminal } from "./terminal.js";
import { TextBuffer } from "./text_buffer.js";
import * as xterm256 from "./xterm256.js";
const WHITE = 7; // xterm256.get_color("gray");

@@ -13,12 +10,25 @@ const BLACK = 16; // xterm256.get_color("black");

let ID = 1;
class Canvas {
export class Canvas {
cols;
rows;
// next: what we're drawing
nextBuffer;
// current: what's currently on the screen
currentBuffer;
// cache the main region
_all;
// do we want to be redrawn?
dirty = true;
// do we want to force the entire canvas to be redrawn?
forceAll = false;
// track a debounce listener for dirty events
dirtyListener;
dirtyTimer;
dirtyDebounceDelay = 0;
// for debugging
id;
constructor(cols, rows) {
this.cols = cols;
this.rows = rows;
// do we want to be redrawn?
this.dirty = true;
// do we want to force the entire canvas to be redrawn?
this.forceAll = false;
this.dirtyDebounceDelay = 0;
this.nextBuffer = new text_buffer_1.TextBuffer(cols, rows);
this.nextBuffer = new TextBuffer(cols, rows);
this.nextBuffer.clearBox(0, 0, cols, rows, DEFAULT_ATTR);

@@ -79,6 +89,5 @@ this.id = ID++;

writeChars(x, y, attr, chars) {
var _a;
this.setDirty();
for (let i = 0; i < chars.length; i++) {
const ch = (_a = chars[i].codePointAt(0)) !== null && _a !== void 0 ? _a : SPACE;
const ch = chars[i].codePointAt(0) ?? SPACE;
this.nextBuffer.put(x++, y, attr, ch);

@@ -96,3 +105,3 @@ if (x >= this.cols || y >= this.rows)

if (this.currentBuffer === undefined) {
this.currentBuffer = new text_buffer_1.TextBuffer(this.cols, this.rows);
this.currentBuffer = new TextBuffer(this.cols, this.rows);
}

@@ -102,3 +111,3 @@ let clear = "";

this.forceAll = false;
this.currentBuffer = new text_buffer_1.TextBuffer(this.cols, this.rows);
this.currentBuffer = new TextBuffer(this.cols, this.rows);
this.nextBuffer.pendingClear = DEFAULT_ATTR;

@@ -108,3 +117,3 @@ this.nextBuffer.setAllDirty();

this.dirty = false;
return clear + canvas_diff_1.computeDiff(this.currentBuffer, this.nextBuffer);
return clear + computeDiff(this.currentBuffer, this.nextBuffer);
}

@@ -120,5 +129,5 @@ // generate linefeed-terminated lines of text, assuming we don't own the

if ((attr >> 8) != bg)
line += terminal_1.Terminal.bg(attr >> 8);
line += Terminal.bg(attr >> 8);
if ((attr & 0xff) != fg)
line += terminal_1.Terminal.fg(attr & 0xff);
line += Terminal.fg(attr & 0xff);
line += String.fromCodePoint(this.nextBuffer.getChar(x, y));

@@ -128,3 +137,3 @@ fg = attr & 0xff;

}
line += terminal_1.Terminal.noColor() + "\n";
line += Terminal.noColor() + "\n";
return line;

@@ -134,5 +143,16 @@ }).join("");

}
exports.Canvas = Canvas;
// Clipped region of a canvas
class Region {
export class Region {
canvas;
x1;
y1;
x2;
y2;
cursorX;
cursorY;
attr;
resizeListeners = new Set();
// used when this region was created by clipping another region:
// remember the parent region so resizes can be relative to it
parent;
constructor(canvas, x1, y1, x2, y2) {

@@ -144,3 +164,2 @@ this.canvas = canvas;

this.y2 = y2;
this.resizeListeners = new Set();
this.cursorX = 0;

@@ -164,4 +183,3 @@ this.cursorY = 0;

get parentOffset() {
var _a, _b, _c, _d;
return [this.x1 - ((_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.x1) !== null && _b !== void 0 ? _b : 0), this.y1 - ((_d = (_c = this.parent) === null || _c === void 0 ? void 0 : _c.y1) !== null && _d !== void 0 ? _d : 0)];
return [this.x1 - (this.parent?.x1 ?? 0), this.y1 - (this.parent?.y1 ?? 0)];
}

@@ -192,7 +210,6 @@ offsetFrom(region) {

resize(x1, y1, x2, y2) {
var _a, _b, _c, _d, _e, _f, _g, _h;
this.x1 = x1 + ((_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.x1) !== null && _b !== void 0 ? _b : 0);
this.y1 = y1 + ((_d = (_c = this.parent) === null || _c === void 0 ? void 0 : _c.y1) !== null && _d !== void 0 ? _d : 0);
this.x2 = x2 + ((_f = (_e = this.parent) === null || _e === void 0 ? void 0 : _e.x1) !== null && _f !== void 0 ? _f : 0);
this.y2 = y2 + ((_h = (_g = this.parent) === null || _g === void 0 ? void 0 : _g.y1) !== null && _h !== void 0 ? _h : 0);
this.x1 = x1 + (this.parent?.x1 ?? 0);
this.y1 = y1 + (this.parent?.y1 ?? 0);
this.x2 = x2 + (this.parent?.x1 ?? 0);
this.y2 = y2 + (this.parent?.y1 ?? 0);
// clip cursor:

@@ -236,8 +253,7 @@ this.at(this.cursorX, this.cursorY);

write(s) {
var _a, _b;
const lines = s.split("\n");
this.writeLine((_a = lines.shift()) !== null && _a !== void 0 ? _a : "");
this.writeLine(lines.shift() ?? "");
while (lines.length > 0) {
this.lf();
this.writeLine((_b = lines.shift()) !== null && _b !== void 0 ? _b : "");
this.writeLine(lines.shift() ?? "");
}

@@ -305,3 +321,2 @@ return this;

}
exports.Region = Region;
//# sourceMappingURL=canvas.js.map

@@ -1,6 +0,3 @@

"use strict";
// a subset of the web color names, for convenience.
Object.defineProperty(exports, "__esModule", { value: true });
exports.COLOR_NAMES = void 0;
exports.COLOR_NAMES = {
export const COLOR_NAMES = {
"aqua": "0ff",

@@ -7,0 +4,0 @@ "black": "000",

@@ -1,2 +0,2 @@

import { Region } from "./canvas";
import { Region } from "./canvas.js";
export interface Constraint {

@@ -3,0 +3,0 @@ minimum: number;

@@ -1,5 +0,9 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GridLayout = void 0;
class GridLayout {
export class GridLayout {
region;
colConstraints;
rowConstraints;
lefts = [];
tops = [];
resizeListeners = new Set();
onResize = () => this.resize(this.region.cols, this.region.rows);
constructor(region, colConstraints, rowConstraints) {

@@ -9,6 +13,2 @@ this.region = region;

this.rowConstraints = rowConstraints;
this.lefts = [];
this.tops = [];
this.resizeListeners = new Set();
this.onResize = () => this.resize(this.region.cols, this.region.rows);
this.resize(region.cols, region.rows);

@@ -76,3 +76,2 @@ region.onResize(this.onResize);

}
exports.GridLayout = GridLayout;
function sum(list) {

@@ -113,3 +112,3 @@ return list.reduce((sum, n) => sum + n, 0);

// to the stretch constraints until it's used up.
let total = sum(results.map(r => { var _a; return (_a = r.size) !== null && _a !== void 0 ? _a : r.possibleSize; }));
let total = sum(results.map(r => r.size ?? r.possibleSize));
for (let i = 0; total < size && i < results.length; i++) {

@@ -121,4 +120,4 @@ if (results[i].constraint.factor > 0 && results[i].size === undefined) {

}
return results.map(r => { var _a; return (_a = r.size) !== null && _a !== void 0 ? _a : r.possibleSize; });
return results.map(r => r.size ?? r.possibleSize);
}
//# sourceMappingURL=grid_layout.js.map
export declare enum Modifier {
None = 0,
Shift = 1,

@@ -3,0 +4,0 @@ Alt = 2,

@@ -1,6 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KeyParser = exports.Key = exports.KeyType = exports.Modifier = void 0;
var Modifier;
export var Modifier;
(function (Modifier) {
Modifier[Modifier["None"] = 0] = "None";
Modifier[Modifier["Shift"] = 1] = "Shift";

@@ -10,4 +8,4 @@ Modifier[Modifier["Alt"] = 2] = "Alt";

Modifier[Modifier["Meta"] = 8] = "Meta";
})(Modifier = exports.Modifier || (exports.Modifier = {}));
var KeyType;
})(Modifier || (Modifier = {}));
export var KeyType;
(function (KeyType) {

@@ -32,4 +30,7 @@ KeyType[KeyType["Normal"] = 0] = "Normal";

KeyType[KeyType["Return"] = 17] = "Return";
})(KeyType = exports.KeyType || (exports.KeyType = {}));
class Key {
})(KeyType || (KeyType = {}));
export class Key {
modifiers;
type;
key;
constructor(modifiers, type, key = "") {

@@ -75,3 +76,2 @@ this.modifiers = modifiers;

}
exports.Key = Key;
var State;

@@ -101,13 +101,13 @@ (function (State) {

// parse incoming xterm-encoded keypresses and emit decoded keys
class KeyParser {
constructor() {
this.state = State.Normal;
this.modifiers = 0;
this.buffer = "";
this.lastKey = Date.now();
// async iterator state: queued keys or waiting reader
this.queue = [];
this.ended = false;
this.receiverRunning = false;
}
export class KeyParser {
state = State.Normal;
modifiers = Modifier.None;
buffer = "";
lastKey = Date.now();
// async iterator state: queued keys or waiting reader
queue = [];
resolve;
ended = false;
receiver;
receiverRunning = false;
[Symbol.asyncIterator]() {

@@ -353,3 +353,2 @@ return this;

}
exports.KeyParser = KeyParser;
//# sourceMappingURL=keys.js.map

@@ -1,5 +0,2 @@

"use strict";
// fancy CSI codes for updating a VT100/xterm terminal
Object.defineProperty(exports, "__esModule", { value: true });
exports.Terminal = void 0;
const CSI = "\u001b[";

@@ -11,3 +8,3 @@ /*

*/
class Terminal {
export class Terminal {
static moveX(x) {

@@ -68,3 +65,2 @@ if (x == 0)

}
exports.Terminal = Terminal;
//# sourceMappingURL=terminal.js.map

@@ -1,4 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextBuffer = exports.ScrollRegion = void 0;
const SPACE = 0x20;

@@ -8,3 +5,7 @@ const MAX_HEIGHT = 32767;

const MAX_SCROLLS = 3;
class ScrollRegion {
export class ScrollRegion {
top;
bottom;
rows;
attr;
constructor(top, bottom, rows, attr) {

@@ -18,9 +19,23 @@ this.top = top;

}
exports.ScrollRegion = ScrollRegion;
class TextBuffer {
export class TextBuffer {
cols;
rows;
// unicode codepoint for each grid element (0 = blank)
chars;
// BBFF: background color (u8), foreground color (u8)
attrs;
// mark rows that have been updated
dirty;
// was "clear" called, and it's waiting to be painted?
pendingClear;
// remember the last few vertical scrolls, in case they help optimize drawing
pendingScrolls = [];
// cursor location
cursorX;
cursorY;
// last-set attribute (BBFF)
attr;
constructor(cols, rows) {
this.cols = cols;
this.rows = rows;
// remember the last few vertical scrolls, in case they help optimize drawing
this.pendingScrolls = [];
this.alloc(cols, rows);

@@ -213,3 +228,2 @@ this.cursorX = 0;

transform(f) {
var _a, _b;
for (let y = 0; y < this.rows; y++) {

@@ -222,4 +236,4 @@ for (let x = 0; x < this.cols; x++) {

const change = f(fg, bg, ch, x, y);
const newAttr = change[0] | (((_a = change[1]) !== null && _a !== void 0 ? _a : bg) << 8);
this.put(x, y, newAttr, (_b = change[2]) !== null && _b !== void 0 ? _b : ch);
const newAttr = change[0] | ((change[1] ?? bg) << 8);
this.put(x, y, newAttr, change[2] ?? ch);
}

@@ -229,3 +243,2 @@ }

}
exports.TextBuffer = TextBuffer;
//# sourceMappingURL=text_buffer.js.map

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nearest_ansi = exports.nearest_gray = exports.nearest_color_cube = exports.nearest_color = exports.color_from_r_g_b = exports.rgb_to_xterm = exports.color_from_hex = exports.xterm_to_rgb = exports.name_to_rgb = exports.get_color = void 0;
const color_names_1 = require("./color_names");
import { COLOR_NAMES } from "./color_names.js";
const COLOR_CUBE = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff];

@@ -21,5 +18,5 @@ const GRAY_LINE = [

// parse a color name, or "#fff" or "#cc0033" into a color index
function get_color(name) {
if (color_names_1.COLOR_NAMES[name])
name = color_names_1.COLOR_NAMES[name];
export function get_color(name) {
if (COLOR_NAMES[name])
name = COLOR_NAMES[name];
if (name[0] == "#")

@@ -32,7 +29,6 @@ name = name.slice(1);

}
exports.get_color = get_color;
// return an RRGGBB value for a given color name
function name_to_rgb(name) {
if (color_names_1.COLOR_NAMES[name])
name = color_names_1.COLOR_NAMES[name];
export function name_to_rgb(name) {
if (COLOR_NAMES[name])
name = COLOR_NAMES[name];
if (name[0] == "#")

@@ -45,3 +41,2 @@ name = name.slice(1);

}
exports.name_to_rgb = name_to_rgb;
// given a hex like "fff" or "cc0033", return the closest matching color in xterm-256 as an index (0 - 255)

@@ -59,3 +54,3 @@ function hex_to_rgb(hex) {

// return an RRGGBB value for the given xterm color
function xterm_to_rgb(xtermColor) {
export function xterm_to_rgb(xtermColor) {
if (xtermColor < 0 || xtermColor > 0xff)

@@ -75,5 +70,4 @@ return 0;

}
exports.xterm_to_rgb = xterm_to_rgb;
// given a hex like "fff" or "cc0033", return the closest matching color in xterm-256 as an index (0 - 255)
function color_from_hex(hex) {
export function color_from_hex(hex) {
if (cache[hex] != null)

@@ -92,9 +86,7 @@ return cache[hex];

}
exports.color_from_hex = color_from_hex;
// return an RRGGBB value for the given xterm color
function rgb_to_xterm(rgb) {
export function rgb_to_xterm(rgb) {
return color_from_r_g_b((rgb >> 16) & 0xff, (rgb >> 8) & 0xff, rgb & 0xff);
}
exports.rgb_to_xterm = rgb_to_xterm;
function color_from_r_g_b(red, green, blue) {
export function color_from_r_g_b(red, green, blue) {
let index = nearest_color(red, green, blue);

@@ -106,4 +98,3 @@ // some terminals have a bug where "color 0" is not actually black, so convert it to gray0 instead

}
exports.color_from_r_g_b = color_from_r_g_b;
function nearest_color(red, green, blue) {
export function nearest_color(red, green, blue) {
const [cube_index, cube_distance] = nearest_color_cube(red, green, blue);

@@ -122,5 +113,4 @@ const [gray_index, gray_distance] = nearest_gray(red, green, blue);

}
exports.nearest_color = nearest_color;
// returns [ index into color cube, distance ]
function nearest_color_cube(red, green, blue) {
export function nearest_color_cube(red, green, blue) {
const redi = find_closest(red, COLOR_CUBE);

@@ -132,4 +122,3 @@ const greeni = find_closest(green, COLOR_CUBE);

}
exports.nearest_color_cube = nearest_color_cube;
function nearest_gray(red, green, blue) {
export function nearest_gray(red, green, blue) {
const gray = (red + green + blue) / 3;

@@ -140,4 +129,3 @@ const i = find_closest(gray, GRAY_LINE);

}
exports.nearest_gray = nearest_gray;
function nearest_ansi(red, green, blue) {
export function nearest_ansi(red, green, blue) {
const distances = ANSI_LINE.map(([r, g, b]) => color_distance(r, g, b, red, green, blue));

@@ -147,3 +135,2 @@ const i = find_closest(0, distances);

}
exports.nearest_ansi = nearest_ansi;
function color_distance(red1, green1, blue1, red2, green2, blue2) {

@@ -150,0 +137,0 @@ // don't bother with sqrt, we just care about which is smaller.

@@ -1,7 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const canvas_1 = require("../antsy/canvas");
require("should");
require("source-map-support/register");
const xterm256_1 = require("../antsy/xterm256");
import { Canvas } from "../antsy/canvas";
import "should";
import "source-map-support/register";
import { rgb_to_xterm, xterm_to_rgb } from "../antsy/xterm256";
const SET_BG_BLACK = "[[48;5;16m";

@@ -19,7 +17,7 @@ const RESET_COLOR = "[[37m" + SET_BG_BLACK;

it("makes a blank grid", () => {
const c = new canvas_1.Canvas(3, 3);
const c = new Canvas(3, 3);
escpaint(c).should.eql(`${RESET}`);
});
it("sets colors", () => {
const c = new canvas_1.Canvas(5, 3);
const c = new Canvas(5, 3);
c.all().at(1, 0).color("green").write("wh").color(undefined, "00f").write("ut");

@@ -29,3 +27,3 @@ escpaint(c).should.eql(`${RESET} ${SET_FG_GREEN}wh${SET_BG_BLUE}ut[[H`);

it("clears", () => {
const c = new canvas_1.Canvas(5, 3);
const c = new Canvas(5, 3);
c.all().color("red", "blue").clear();

@@ -35,3 +33,3 @@ escpaint(c).should.eql(`${SET_FG_RED}${SET_BG_BLUE}${CLEAR}`);

it("skips unchanged", () => {
const c = new canvas_1.Canvas(15, 3);
const c = new Canvas(15, 3);
const r = c.all();

@@ -47,3 +45,3 @@ r.at(0, 0).write("hi");

it("honors clipping", () => {
const c = new canvas_1.Canvas(15, 3);
const c = new Canvas(15, 3);
const r = c.clip(5, 1, 10, 3);

@@ -54,3 +52,3 @@ r.at(0, 0).color("purple").write("midnight");

it("clips around linefeeds", () => {
const c = new canvas_1.Canvas(15, 3);
const c = new Canvas(15, 3);
const r = c.clip(0, 1, 15, 3);

@@ -62,3 +60,3 @@ r.at(0, 0).color("purple").write("one\ntwo\nthree");

it("in the middle", () => {
const c = new canvas_1.Canvas(15, 3);
const c = new Canvas(15, 3);
const r = c.all();

@@ -71,3 +69,3 @@ r.at(0, 0).write("random words!");

it("at the start", () => {
const c = new canvas_1.Canvas(15, 3);
const c = new Canvas(15, 3);
const r = c.all();

@@ -80,3 +78,3 @@ r.at(0, 0).write("random-words!");

it("at the end", () => {
const c = new canvas_1.Canvas(15, 3);
const c = new Canvas(15, 3);
const r = c.all();

@@ -89,3 +87,3 @@ r.at(0, 0).write("random words!");

it("around the middle", () => {
const c = new canvas_1.Canvas(30, 3);
const c = new Canvas(30, 3);
const r = c.all();

@@ -99,3 +97,3 @@ r.at(0, 0).write("012345678901234567890123456789");

it("three times", () => {
const c = new canvas_1.Canvas(35, 3);
const c = new Canvas(35, 3);
const r = c.all();

@@ -109,3 +107,3 @@ r.at(0, 0).write("01234567890123456789012345678901234");

it("degenerate case", () => {
const c = new canvas_1.Canvas(105, 3);
const c = new Canvas(105, 3);
const r = c.all();

@@ -131,3 +129,3 @@ r.at(0, 0);

it("clears a region", () => {
const c = new canvas_1.Canvas(10, 10);
const c = new Canvas(10, 10);
for (let y = 0; y < 10; y++)

@@ -141,5 +139,5 @@ c.all().at(0, y).write("##########");

// make a background and a box, and draw them into the main canvas to simulate animation.
const c = new canvas_1.Canvas(10, 10);
const bg = new canvas_1.Canvas(10, 10);
const box = new canvas_1.Canvas(4, 4);
const c = new Canvas(10, 10);
const bg = new Canvas(10, 10);
const box = new Canvas(4, 4);
bg.all().backgroundColor("navy").clear();

@@ -173,3 +171,3 @@ box.all().backgroundColor("maroon").clear().at(0, 0).color("white").write("+--+| || |+--+");

it("places the cursor", () => {
const c = new canvas_1.Canvas(10, 10);
const c = new Canvas(10, 10);
c.all().at(0, 4).write(">").at(0, 3).write("Ready.").moveCursor(2, 4);

@@ -179,3 +177,3 @@ escpaint(c).should.eql(`${RESET}[[3BReady.[[5H>[[C`);

it("clears to end of line in clip region", () => {
const c = new canvas_1.Canvas(10, 4);
const c = new Canvas(10, 4);
for (let y = 0; y < 4; y++)

@@ -188,3 +186,3 @@ c.all().at(0, y).write(y.toString());

it("resizes", () => {
const c = new canvas_1.Canvas(10, 10);
const c = new Canvas(10, 10);
c.all().color("00f").at(5, 3).write("hello");

@@ -197,3 +195,3 @@ c.all().color("f00").at(0, 9).write("ok");

it("redraws", () => {
const c = new canvas_1.Canvas(10, 10);
const c = new Canvas(10, 10);
c.all().color("00f").at(5, 3).write("hello");

@@ -206,3 +204,3 @@ c.all().color("f00").at(0, 9).write("ok");

it("transformAttr", () => {
const c = new canvas_1.Canvas(10, 10);
const c = new Canvas(10, 10);
c.all().color("00f").at(5, 2).write("hello");

@@ -212,5 +210,5 @@ c.all().color("f00").at(2, 4).write("greet");

escpaint(c).should.eql(`${RESET}[[3;6H${SET_FG_BLUE}hello[[5;3H${SET_FG_RED}greet[[3B${SET_FG_B_GREEN}ok[[H`);
c.transform((fg, _bg) => [xterm256_1.rgb_to_xterm((xterm256_1.xterm_to_rgb(fg) & 0xfefefe) >> 1)]);
c.transform((fg, _bg) => [rgb_to_xterm((xterm_to_rgb(fg) & 0xfefefe) >> 1)]);
escpaint(c).should.eql(`[[3;6H[[34mhello[[5;3H[[31mgreet[[3B[[32mok[[H`);
c.transform((fg, _bg) => [xterm256_1.rgb_to_xterm((xterm256_1.xterm_to_rgb(fg) & 0xfefefe) >> 1)]);
c.transform((fg, _bg) => [rgb_to_xterm((xterm_to_rgb(fg) & 0xfefefe) >> 1)]);
escpaint(c).should.eql(`[[3;6H[[38;5;17mhello[[5;3H[[38;5;52mgreet[[3B[[38;5;22mok[[H`);

@@ -220,3 +218,3 @@ });

function stars() {
const c = new canvas_1.Canvas(7, 7);
const c = new Canvas(7, 7);
const r = c.all();

@@ -276,3 +274,3 @@ r.at(0, 0).write("*******");

it("on overflow", () => {
const c = new canvas_1.Canvas(5, 3);
const c = new Canvas(5, 3);
c.all().at(0, 2).write("hi");

@@ -279,0 +277,0 @@ escpaint(c).should.eql(`${RESET}[[2Bhi[[H`);

@@ -1,7 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const canvas_1 = require("../antsy/canvas");
const grid_layout_1 = require("../antsy/grid_layout");
require("should");
require("source-map-support/register");
import { Canvas } from "../antsy/canvas";
import { GridLayout } from "../antsy/grid_layout";
import "should";
import "source-map-support/register";
function dimensions(r) {

@@ -12,5 +10,5 @@ return [r.x1, r.y1, r.cols, r.rows];

it("basic layout", () => {
const c = new canvas_1.Canvas(80, 24);
const c = new Canvas(80, 24);
// left panel of 8 chars, bottom panel of 2
const grid = new grid_layout_1.GridLayout(c.all(), [grid_layout_1.GridLayout.fixed(8), grid_layout_1.GridLayout.stretch(1)], [grid_layout_1.GridLayout.stretch(1), grid_layout_1.GridLayout.fixed(2)]);
const grid = new GridLayout(c.all(), [GridLayout.fixed(8), GridLayout.stretch(1)], [GridLayout.stretch(1), GridLayout.fixed(2)]);
grid.lefts.should.eql([0, 8, 80]);

@@ -33,5 +31,5 @@ grid.tops.should.eql([0, 22, 24]);

it("multiple stretch zones", () => {
const c = new canvas_1.Canvas(80, 24);
const c = new Canvas(80, 24);
// left panel of 8 chars, bottom panel of 2
const grid = new grid_layout_1.GridLayout(c.all(), [grid_layout_1.GridLayout.fixed(8), grid_layout_1.GridLayout.stretch(2), grid_layout_1.GridLayout.stretch(1)], [grid_layout_1.GridLayout.stretch(1), grid_layout_1.GridLayout.fixed(2)]);
const grid = new GridLayout(c.all(), [GridLayout.fixed(8), GridLayout.stretch(2), GridLayout.stretch(1)], [GridLayout.stretch(1), GridLayout.fixed(2)]);
grid.lefts.should.eql([0, 8, 56, 80]);

@@ -72,4 +70,4 @@ grid.tops.should.eql([0, 22, 24]);

it("stretch with minimum", () => {
const c = new canvas_1.Canvas(60, 24);
const grid = new grid_layout_1.GridLayout(c.all(), [grid_layout_1.GridLayout.stretchWithMinimum(1, 8), grid_layout_1.GridLayout.stretch(2)], [grid_layout_1.GridLayout.stretch(1), grid_layout_1.GridLayout.fixed(2)]);
const c = new Canvas(60, 24);
const grid = new GridLayout(c.all(), [GridLayout.stretchWithMinimum(1, 8), GridLayout.stretch(2)], [GridLayout.stretch(1), GridLayout.fixed(2)]);
grid.lefts.should.eql([0, 20, 60]);

@@ -83,4 +81,4 @@ grid.tops.should.eql([0, 22, 24]);

// 10-min sidebar on each side, 1/2 center column, 1/6 right column
const c = new canvas_1.Canvas(120, 24);
const grid = new grid_layout_1.GridLayout(c.all(), [grid_layout_1.GridLayout.stretchWithMinimum(1, 10), grid_layout_1.GridLayout.stretch(3), grid_layout_1.GridLayout.stretch(1), grid_layout_1.GridLayout.stretchWithMinimum(1, 10)], [grid_layout_1.GridLayout.stretch(1)]);
const c = new Canvas(120, 24);
const grid = new GridLayout(c.all(), [GridLayout.stretchWithMinimum(1, 10), GridLayout.stretch(3), GridLayout.stretch(1), GridLayout.stretchWithMinimum(1, 10)], [GridLayout.stretch(1)]);
grid.lefts.should.eql([0, 20, 80, 100, 120]);

@@ -96,4 +94,4 @@ grid.tops.should.eql([0, 24]);

it("adjust constraints", () => {
const c = new canvas_1.Canvas(60, 24);
const grid = new grid_layout_1.GridLayout(c.all(), [grid_layout_1.GridLayout.stretchWithMinimum(1, 8), grid_layout_1.GridLayout.stretch(2)], [grid_layout_1.GridLayout.stretch(1), grid_layout_1.GridLayout.fixed(2)]);
const c = new Canvas(60, 24);
const grid = new GridLayout(c.all(), [GridLayout.stretchWithMinimum(1, 8), GridLayout.stretch(2)], [GridLayout.stretch(1), GridLayout.fixed(2)]);
grid.lefts.should.eql([0, 20, 60]);

@@ -105,3 +103,3 @@ grid.tops.should.eql([0, 22, 24]);

dimensions(r2).should.eql([20, 0, 40, 22]);
grid.adjustCol(0, grid_layout_1.GridLayout.stretchWithMinimum(1, 30));
grid.adjustCol(0, GridLayout.stretchWithMinimum(1, 30));
grid.lefts.should.eql([0, 30, 60]);

@@ -113,9 +111,9 @@ grid.tops.should.eql([0, 22, 24]);

describe("grid with all fixed widths", () => {
const c = new canvas_1.Canvas(60, 24);
const c = new Canvas(60, 24);
it("goldilocks", () => {
const grid = new grid_layout_1.GridLayout(c.all(), [grid_layout_1.GridLayout.stretch(1)], [6, 15, 3].map(n => grid_layout_1.GridLayout.fixed(n)));
const grid = new GridLayout(c.all(), [GridLayout.stretch(1)], [6, 15, 3].map(n => GridLayout.fixed(n)));
grid.tops.should.eql([0, 6, 21, 24]);
});
it("too small", () => {
const grid = new grid_layout_1.GridLayout(c.all(), [grid_layout_1.GridLayout.stretch(1)], [10, 15, 3].map(n => grid_layout_1.GridLayout.fixed(n)));
const grid = new GridLayout(c.all(), [GridLayout.stretch(1)], [10, 15, 3].map(n => GridLayout.fixed(n)));
// remainders should be zero-height

@@ -125,3 +123,3 @@ grid.tops.should.eql([0, 10, 24, 24]);

it("too big", () => {
const grid = new grid_layout_1.GridLayout(c.all(), [grid_layout_1.GridLayout.stretch(1)], [5, 10, 3].map(n => grid_layout_1.GridLayout.fixed(n)));
const grid = new GridLayout(c.all(), [GridLayout.stretch(1)], [5, 10, 3].map(n => GridLayout.fixed(n)));
// empty space at the end

@@ -132,20 +130,20 @@ grid.tops.should.eql([0, 5, 15, 18]);

it("resizes a nested region correctly", () => {
const c = new canvas_1.Canvas(10, 10);
const grid1 = new grid_layout_1.GridLayout(c.all(), [5, 5].map(n => grid_layout_1.GridLayout.fixed(n)), [5, 5].map(n => grid_layout_1.GridLayout.fixed(n)));
const grid2 = new grid_layout_1.GridLayout(grid1.layoutAt(1, 1), [grid_layout_1.GridLayout.fixed(2), grid_layout_1.GridLayout.stretch(1)], [grid_layout_1.GridLayout.fixed(2), grid_layout_1.GridLayout.stretch(1)]);
const c = new Canvas(10, 10);
const grid1 = new GridLayout(c.all(), [5, 5].map(n => GridLayout.fixed(n)), [5, 5].map(n => GridLayout.fixed(n)));
const grid2 = new GridLayout(grid1.layoutAt(1, 1), [GridLayout.fixed(2), GridLayout.stretch(1)], [GridLayout.fixed(2), GridLayout.stretch(1)]);
const r = grid2.layoutAt(1, 1);
[r.x1, r.y1, r.x2, r.y2].should.eql([7, 7, 10, 10]);
// inner region is moved
grid2.adjustCol(0, grid_layout_1.GridLayout.fixed(3));
grid2.adjustCol(0, GridLayout.fixed(3));
[r.x1, r.y1, r.x2, r.y2].should.eql([8, 7, 10, 10]);
// outer region is moved
grid1.adjustRow(0, grid_layout_1.GridLayout.fixed(4));
grid1.adjustRow(0, GridLayout.fixed(4));
[r.x1, r.y1, r.x2, r.y2].should.eql([8, 6, 10, 9]);
// outer region grows
grid1.adjustRow(1, grid_layout_1.GridLayout.stretch(1));
grid1.adjustRow(1, GridLayout.stretch(1));
[r.x1, r.y1, r.x2, r.y2].should.eql([8, 6, 10, 10]);
});
it("stretch min-max", () => {
const c = new canvas_1.Canvas(80, 24);
const grid = new grid_layout_1.GridLayout(c.all(), [grid_layout_1.GridLayout.stretchWithMinMax(1, 10, 20), grid_layout_1.GridLayout.stretch(2), grid_layout_1.GridLayout.stretch(1)], [grid_layout_1.GridLayout.stretch(1)]);
const c = new Canvas(80, 24);
const grid = new GridLayout(c.all(), [GridLayout.stretchWithMinMax(1, 10, 20), GridLayout.stretch(2), GridLayout.stretch(1)], [GridLayout.stretch(1)]);
grid.lefts.should.eql([0, 20, 60, 80]);

@@ -152,0 +150,0 @@ grid.tops.should.eql([0, 24]);

@@ -1,13 +0,4 @@

"use strict";
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
Object.defineProperty(exports, "__esModule", { value: true });
const keys_1 = require("../antsy/keys");
require("should");
require("source-map-support/register");
import { KeyParser } from "../antsy/keys";
import "should";
import "source-map-support/register";
function bundle(keys) {

@@ -18,22 +9,10 @@ return keys.map(k => k.toString()).join(",");

describe("KeyParser", () => {
let parser = new keys_1.KeyParser();
let parser = new KeyParser();
let output = [];
beforeEach(() => {
parser = new keys_1.KeyParser();
parser = new KeyParser();
output = [];
setTimeout(async () => {
var e_1, _a;
try {
for (var parser_1 = __asyncValues(parser), parser_1_1; parser_1_1 = await parser_1.next(), !parser_1_1.done;) {
const key = parser_1_1.value;
output.push(key);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (parser_1_1 && !parser_1_1.done && (_a = parser_1.return)) await _a.call(parser_1);
}
finally { if (e_1) throw e_1.error; }
}
for await (const key of parser)
output.push(key);
}, 0);

@@ -51,3 +30,3 @@ });

it("pipe", async () => {
const p = new keys_1.KeyParser();
const p = new KeyParser();
p.pipe(async (k) => { output.push(k); await delay(1); });

@@ -54,0 +33,0 @@ p.feed("hell");

{
"name": "antsy",
"version": "3.0.3",
"version": "4.0.0",
"type": "module",
"description": "draw full-color (xterm-256) ansi graphics into a buffer",

@@ -21,12 +22,12 @@ "keywords": [

"prepare": "npm run build",
"test": "npm run build && mocha -R spec --colors lib/test"
"test": "npm run build && mocha"
},
"devDependencies": {
"@types/mocha": "^5.2.5",
"@types/node": "^10.17.28",
"@types/source-map-support": "^0.5.3",
"mocha": "^10.1.0",
"should": "^13.2.3",
"source-map-support": "^0.5.9",
"typescript": "^3.9.7"
"@types/mocha": "^10.0.1",
"@types/node": "^18.16.5",
"@types/source-map-support": "^0.5.6",
"mocha": "^10.2.0",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
},

@@ -33,0 +34,0 @@ "main": "./lib/antsy.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc