Comparing version 2.0.0 to 2.1.0
export { Canvas, Region } from "./antsy/canvas"; | ||
export { Terminal } from "./antsy/terminal"; | ||
export { TextBuffer } from "./antsy/text_buffer"; | ||
export { get_color } from "./antsy/xterm256"; | ||
export { get_color, name_to_rgb, xterm_to_rgb } from "./antsy/xterm256"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var canvas_1 = require("./antsy/canvas"); | ||
exports.Canvas = canvas_1.Canvas; | ||
exports.Region = canvas_1.Region; | ||
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 terminal_1 = require("./antsy/terminal"); | ||
exports.Terminal = terminal_1.Terminal; | ||
Object.defineProperty(exports, "Terminal", { enumerable: true, get: function () { return terminal_1.Terminal; } }); | ||
var text_buffer_1 = require("./antsy/text_buffer"); | ||
exports.TextBuffer = text_buffer_1.TextBuffer; | ||
Object.defineProperty(exports, "TextBuffer", { enumerable: true, get: function () { return text_buffer_1.TextBuffer; } }); | ||
var xterm256_1 = require("./antsy/xterm256"); | ||
exports.get_color = xterm256_1.get_color; | ||
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, "xterm_to_rgb", { enumerable: true, get: function () { return xterm256_1.xterm_to_rgb; } }); | ||
//# sourceMappingURL=antsy.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.computeDiff = void 0; | ||
const terminal_1 = require("./terminal"); | ||
@@ -190,4 +191,4 @@ // if we see this many blanks in a row, check if clear-to-end-of-line would help | ||
function checkScroll(oldBuffer, newBuffer, s) { | ||
let newCost = 0; | ||
const originalCost = sum(range(s.top, s.bottom), y => computeRowDistance(oldBuffer, y, newBuffer).distance); | ||
let newCost = 0; | ||
if (s.rows > 0) { | ||
@@ -194,0 +195,0 @@ newCost += sum(range(s.top, s.bottom - s.rows), y => { |
@@ -11,3 +11,5 @@ import { TextBuffer } from "./text_buffer"; | ||
write(x: number, y: number, attr: number, s: string): void; | ||
writeChars(x: number, y: number, attr: number, chars: string[]): void; | ||
paint(): string; | ||
paintInline(): string; | ||
} | ||
@@ -24,4 +26,4 @@ export declare class Region { | ||
constructor(canvas: Canvas, x1: number, y1: number, x2: number, y2: number); | ||
readonly cols: number; | ||
readonly rows: number; | ||
get cols(): number; | ||
get rows(): number; | ||
all(): Region; | ||
@@ -28,0 +30,0 @@ clip(x1: number, y1: number, x2: number, y2: number): Region; |
"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"); | ||
@@ -28,6 +30,8 @@ const xterm256 = require("./xterm256"); | ||
write(x, y, attr, s) { | ||
for (let i = 0; i < s.length; i++) { | ||
const ch = s.codePointAt(i) || SPACE; | ||
if (ch > 0xffff) | ||
i++; | ||
this.writeChars(x, y, attr, [...s]); | ||
} | ||
writeChars(x, y, attr, chars) { | ||
var _a; | ||
for (let i = 0; i < chars.length; i++) { | ||
const ch = (_a = chars[i].codePointAt(0)) !== null && _a !== void 0 ? _a : SPACE; | ||
this.nextBuffer.put(x++, y, attr, ch); | ||
@@ -44,2 +48,22 @@ if (x >= this.cols || y >= this.rows) | ||
} | ||
// generate linefeed-terminated lines of text, assuming we don't own the | ||
// screen, so we can't move the cursor and have to output every char. | ||
paintInline() { | ||
return [...Array(this.nextBuffer.rows).keys()].map(y => { | ||
let line = ""; | ||
let fg = -1, bg = -1; | ||
for (let x = 0; x < this.nextBuffer.cols; x++) { | ||
const attr = this.nextBuffer.getAttr(x, y); | ||
if ((attr >> 8) != bg) | ||
line += terminal_1.Terminal.bg(attr >> 8); | ||
if ((attr & 0xff) != fg) | ||
line += terminal_1.Terminal.fg(attr & 0xff); | ||
line += String.fromCodePoint(this.nextBuffer.getChar(x, y)); | ||
fg = attr & 0xff; | ||
bg = attr >> 8; | ||
} | ||
line += terminal_1.Terminal.noColor() + "\n"; | ||
return line; | ||
}).join(""); | ||
} | ||
} | ||
@@ -84,7 +108,7 @@ exports.Canvas = Canvas; | ||
color(fg, bg) { | ||
if (fg) { | ||
if (fg !== undefined) { | ||
const attr = (typeof fg === "string") ? xterm256.get_color(fg) : fg; | ||
this.attr = (this.attr & 0xff00) | attr; | ||
} | ||
if (bg) { | ||
if (bg !== undefined) { | ||
const attr = (typeof bg === "string") ? xterm256.get_color(bg) : bg; | ||
@@ -108,3 +132,4 @@ this.attr = (this.attr & 0xff) | (attr << 8); | ||
write(s) { | ||
while (s.length > 0) { | ||
let chars = [...s]; | ||
while (chars.length > 0) { | ||
// check for auto-scroll, only when we need to write another glyph | ||
@@ -120,6 +145,6 @@ if (this.cursorX >= this.cols) { | ||
const n = this.cols - this.cursorX; | ||
const text = s.slice(0, n); | ||
this.canvas.write(this.x1 + this.cursorX, this.y1 + this.cursorY, this.attr, text); | ||
this.cursorX += text.length; | ||
s = s.slice(n); | ||
const slice = chars.slice(0, n); | ||
this.canvas.writeChars(this.x1 + this.cursorX, this.y1 + this.cursorY, this.attr, slice); | ||
this.cursorX += slice.length; | ||
chars = chars.slice(slice.length); | ||
} | ||
@@ -126,0 +151,0 @@ return this; |
"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 = { | ||
@@ -5,0 +6,0 @@ "aqua": "0ff", |
@@ -10,4 +10,5 @@ export declare class Terminal { | ||
static bg(index: number): string; | ||
static noColor(): string; | ||
static scrollUp(top: number, bottom: number, rows: number): string; | ||
static scrollDown(top: number, bottom: number, rows: number): string; | ||
} |
"use strict"; | ||
// fancy CSI codes for updating a VT100/xterm terminal | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Terminal = void 0; | ||
const CSI = "\u001b["; | ||
@@ -54,2 +55,5 @@ /* | ||
} | ||
static noColor() { | ||
return `${CSI}m`; | ||
} | ||
// note: most terminals will scramble cursor location after scrolling | ||
@@ -56,0 +60,0 @@ static scrollUp(top, bottom, rows) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TextBuffer = exports.ScrollRegion = void 0; | ||
const SPACE = 0x20; | ||
@@ -4,0 +5,0 @@ const MAX_HEIGHT = 32767; |
export declare function get_color(name: string): number; | ||
export declare function name_to_rgb(name: string): number; | ||
export declare function xterm_to_rgb(xtermColor: number): number; | ||
export declare function color_from_hex(hex: string): number; | ||
@@ -3,0 +5,0 @@ export declare function nearest_color(red: number, green: number, blue: number): number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.nearest_ansi = exports.nearest_gray = exports.nearest_color_cube = exports.nearest_color = exports.color_from_hex = exports.xterm_to_rgb = exports.name_to_rgb = exports.get_color = void 0; | ||
const color_names_1 = require("./color_names"); | ||
@@ -31,3 +32,43 @@ const COLOR_CUBE = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff]; | ||
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]; | ||
if (name[0] == "#") | ||
name = name.slice(1); | ||
if (name.match(HEX_RE)) | ||
return hex_to_rgb(name); | ||
// default to gray | ||
return 0x7f7f7f; | ||
} | ||
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) | ||
function hex_to_rgb(hex) { | ||
if (hex.length == 3) | ||
return hex_to_rgb(hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]); | ||
const [red, green, blue] = [ | ||
parseInt(hex.slice(0, 2), 16), | ||
parseInt(hex.slice(2, 4), 16), | ||
parseInt(hex.slice(4, 6), 16) | ||
]; | ||
return (red << 16) | (green << 8) | blue; | ||
} | ||
// return an RRGGBB value for the given xterm color | ||
function xterm_to_rgb(xtermColor) { | ||
if (xtermColor < 0 || xtermColor > 0xff) | ||
return 0; | ||
if (xtermColor < 0x10) { | ||
const [r, g, b] = ANSI_LINE[xtermColor]; | ||
return r * 0x10000 + g * 0x100 + b; | ||
} | ||
if (xtermColor < 0xe8) { | ||
const r = COLOR_CUBE[Math.floor((xtermColor - 0x10) / 36)]; | ||
const g = COLOR_CUBE[Math.floor(((xtermColor - 0x10) % 36) / 6)]; | ||
const b = COLOR_CUBE[(xtermColor - 0x10) % 6]; | ||
return r * 0x10000 + g * 0x100 + b; | ||
} | ||
return GRAY_LINE[xtermColor - 0xe8] * 0x10101; | ||
} | ||
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) { | ||
@@ -34,0 +75,0 @@ if (cache[hex] != null) |
@@ -56,4 +56,19 @@ "use strict"; | ||
}); | ||
it("get_rgb", () => { | ||
xterm256.xterm_to_rgb(0).should.eql(0x000000); | ||
xterm256.xterm_to_rgb(3).should.eql(0x808000); | ||
xterm256.xterm_to_rgb(12).should.eql(0x0000ff); | ||
xterm256.xterm_to_rgb(15).should.eql(0xffffff); | ||
xterm256.xterm_to_rgb(16).should.eql(0x000000); | ||
xterm256.xterm_to_rgb(100).should.eql(0x878700); | ||
xterm256.xterm_to_rgb(188).should.eql(0xd7d7d7); | ||
xterm256.xterm_to_rgb(197).should.eql(0xff005f); | ||
xterm256.xterm_to_rgb(231).should.eql(0xffffff); | ||
xterm256.xterm_to_rgb(232).should.eql(0x080808); | ||
xterm256.xterm_to_rgb(252).should.eql(0xd0d0d0); | ||
xterm256.xterm_to_rgb(253).should.eql(0xdadada); | ||
xterm256.xterm_to_rgb(255).should.eql(0xeeeeee); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=test_xterm256.js.map |
{ | ||
"name": "antsy", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "draw full-color (xterm-256) ansi graphics into a buffer", | ||
@@ -26,7 +26,7 @@ "keywords": [ | ||
"@types/mocha": "^5.2.5", | ||
"@types/node": "^10.10.3", | ||
"mocha": "^5.2.0", | ||
"@types/node": "^10.17.28", | ||
"mocha": "^8.1.1", | ||
"should": "^13.2.3", | ||
"source-map-support": "^0.5.9", | ||
"typescript": "^3.0.3" | ||
"typescript": "^3.9.7" | ||
}, | ||
@@ -33,0 +33,0 @@ "main": "./lib/antsy.js", |
@@ -63,3 +63,3 @@ # Antsy | ||
A clip region maps a rectangle of the canvas. | ||
A clip region maps a rectangle of the canvas, and can be drawn on. | ||
@@ -93,3 +93,3 @@ - `all(): Region` | ||
Copy a region from another canvas into this region. If the other region is larger than this one, it will be clipped. The other region is always drawn into this one at `(0, 0)`: to draw into another coordinate, `clip` the region first. | ||
Copy a region from another canvas into this region. If the other region is larger than this one, it will be clipped. The other region is always drawn into this one at `(0, 0)`: to draw into another coordinate, `clip` the region first. You can use this to give each UX element ("widget") its own canvas, and draw them into a region of the canvas representing the screen. | ||
@@ -96,0 +96,0 @@ - `scrollUp(rows: number = 1): this` |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
141444
1684
0
36