minitel-standalone
Advanced tools
Comparing version 1.8.0 to 1.8.2
@@ -17,2 +17,3 @@ /// <reference types="node" /> | ||
key: [string]; | ||
frame: []; | ||
}> { | ||
@@ -26,5 +27,8 @@ static defaultScreenAttributes: CharAttributes; | ||
lastImmediate: NodeJS.Immediate | null; | ||
speed: number | undefined; | ||
rxQueue: LinkedList; | ||
model: string | undefined; | ||
private tillReady; | ||
constructor(stream: Duplex, settings: Partial<MinitelSettings>); | ||
readyAsync(): Promise<void>; | ||
invalidateRender(): void; | ||
@@ -39,3 +43,4 @@ renderString(): string; | ||
queueCommandAsync(command: string, expected: string | RegExp): Promise<string>; | ||
requestAnimationFrame(callback: () => any): void; | ||
get colors(): number[][]; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -18,2 +27,3 @@ exports.Minitel = void 0; | ||
this.lastImmediate = null; | ||
this.tillReady = []; | ||
this.minitel = this; | ||
@@ -45,5 +55,10 @@ this.children = new singleton_js_1.SingletonArray(); | ||
].join(''), '\x1b\x3a\x73'); | ||
this.queueCommand('\x1b\x39\x7b', /^\x01.{3}\x04$/, (function (result) { | ||
this.tillReady.push(this.queueCommandAsync('\x1b\x39\x7b', /^\x01.{3}\x04$/) | ||
.then((function (result) { | ||
this.model = result.slice(1, 4); | ||
}).bind(this)); | ||
}).bind(this))); | ||
this.tillReady.push(this.queueCommandAsync('\x1b\x39\x74', '\x1b\x3a\x75') | ||
.then((function (result) { | ||
this.speed = { '\x52': 300, '\x64': 1200, '\x76': 4800, '\x7f': 9600 }[result[3]]; | ||
}).bind(this))); | ||
this.stream.write('\x1f\x40\x41\x18\x0c'); // Clear status; clear screen | ||
@@ -108,2 +123,7 @@ let acc = ''; | ||
} | ||
readyAsync() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield Promise.all(this.tillReady); | ||
}); | ||
} | ||
invalidateRender() { | ||
@@ -150,3 +170,3 @@ this.renderInvalidated = true; | ||
skippedACharCounter += 1; | ||
lastAttributes = Object.assign({ fg: 7, doubleWidth: false, doubleHeight: false, noBlink: true, invert: false, charset: 0 }, richchar_js_1.RichChar.getDelimited(prevChar.attributes)); | ||
lastAttributes = Object.assign({ fg: 7, bg: 0, doubleWidth: false, doubleHeight: false, noBlink: true, invert: false }, richchar_js_1.RichChar.getDelimited(prevChar.attributes, lastAttributes.charset)); | ||
} | ||
@@ -171,3 +191,3 @@ else { | ||
outputString.push('\x1f\x41\x41'); | ||
lastAttributes = Object.assign(Object.assign({}, lastAttributes), richchar_js_1.RichChar.getDelimited(Minitel.defaultScreenAttributes)); | ||
lastAttributes = Object.assign(Object.assign({}, lastAttributes), richchar_js_1.RichChar.getDelimited(Minitel.defaultScreenAttributes, lastAttributes.charset)); | ||
} | ||
@@ -184,7 +204,7 @@ this.previousRender = renderGrid.copy(); | ||
} | ||
// if i get bullied in prépa, it will be because of this | ||
let preOptimized = outputString.join('\x80'); | ||
preOptimized = preOptimized.replace(/(.)(\x80\1){2,62}/g, (v) => `${v[0]}\x12${String.fromCharCode((v.length + 1) / 2 + 63)}`); | ||
// parcoursuop forbid me from going to prépa. RIP :') | ||
let preOptimized = outputString.filter((v) => v !== '').join('€'); | ||
preOptimized = preOptimized.replace(/(.)(€\1){2,62}/g, (v) => `${v[0]}\x12${String.fromCharCode((v.length + 1) / 2 + 63)}`); | ||
// console.log(JSON.stringify(preOptimized)); | ||
return preOptimized.split('\x80').join(''); | ||
return preOptimized.split('€').join(''); | ||
} | ||
@@ -241,3 +261,5 @@ toCursorMove(y, x) { | ||
// this.stream.write('\x0c'); | ||
this.stream.write(this.renderString()); | ||
const renderMe = this.renderString(); | ||
this.stream.write(renderMe); | ||
setTimeout((function () { this.emit('frame'); }).bind(this), renderMe.length * (8000 / (this.speed || 300))); | ||
} | ||
@@ -252,2 +274,5 @@ queueCommand(command, expected, callback = ((_arg0) => { })) { | ||
} | ||
requestAnimationFrame(callback) { | ||
this.once('frame', () => callback()); | ||
} | ||
get colors() { | ||
@@ -254,0 +279,0 @@ if (this.model === 'Bs0') { |
@@ -7,3 +7,7 @@ import { CharAttributes } from './types.js'; | ||
char: T; | ||
static getDelimited(attributes: CharAttributes): Pick<CharAttributes, 'bg' | 'underline'>; | ||
static getDelimited(attributes: CharAttributes, charset: number): { | ||
underline: boolean; | ||
charset: number; | ||
bg?: number | undefined; | ||
}; | ||
static normalizeAttributes(attributes: Partial<CharAttributes>): CharAttributes; | ||
@@ -10,0 +14,0 @@ static getAttributesApplier(attributes: Partial<CharAttributes>, previousAttributes: CharAttributes): string; |
@@ -6,7 +6,4 @@ "use strict"; | ||
// skip: boolean; | ||
static getDelimited(attributes) { | ||
return { | ||
bg: attributes.bg, | ||
underline: attributes.underline, | ||
}; | ||
static getDelimited(attributes, charset) { | ||
return Object.assign(Object.assign({}, (charset !== 1 ? { bg: attributes.bg } : {})), { underline: attributes.underline, charset: attributes.charset }); | ||
} | ||
@@ -13,0 +10,0 @@ static normalizeAttributes(attributes) { |
{ | ||
"name": "minitel-standalone", | ||
"version": "1.8.0", | ||
"version": "1.8.2", | ||
"description": "A standalone package for minitel components", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -22,3 +22,3 @@ import { Duplex } from 'stream'; | ||
export class Minitel extends Container<ContainerAttributes, { key: [string] }> { | ||
export class Minitel extends Container<ContainerAttributes, { key: [string], frame: [] }> { | ||
static defaultScreenAttributes: CharAttributes = { | ||
@@ -41,4 +41,6 @@ fg: 7, | ||
lastImmediate: NodeJS.Immediate | null = null; | ||
speed: number | undefined; | ||
rxQueue: LinkedList; | ||
model: string | undefined; | ||
private tillReady: Promise<void>[] = []; | ||
constructor(stream: Duplex, settings: Partial<MinitelSettings>) { | ||
@@ -84,6 +86,15 @@ const that = null as unknown as Minitel; | ||
this.tillReady.push( | ||
this.queueCommandAsync('\x1b\x39\x7b', /^\x01.{3}\x04$/) | ||
.then((function (this: Minitel, result: string) { | ||
this.model = result.slice(1, 4); | ||
}).bind(this)), | ||
); | ||
this.queueCommand('\x1b\x39\x7b', /^\x01.{3}\x04$/, (function (this: Minitel, result: string) { | ||
this.model = result.slice(1, 4); | ||
}).bind(this)); | ||
this.tillReady.push( | ||
this.queueCommandAsync('\x1b\x39\x74', '\x1b\x3a\x75') | ||
.then((function (this: Minitel, result: string) { | ||
this.speed = { '\x52': 300, '\x64': 1200, '\x76': 4800, '\x7f': 9600 }[result[3]]!; | ||
}).bind(this)), | ||
); | ||
@@ -148,2 +159,5 @@ this.stream.write('\x1f\x40\x41\x18\x0c'); // Clear status; clear screen | ||
} | ||
async readyAsync() { | ||
await Promise.all(this.tillReady); | ||
} | ||
invalidateRender(): void { | ||
@@ -205,2 +219,3 @@ this.renderInvalidated = true; | ||
fg: 7, | ||
bg: 0, | ||
doubleWidth: false, | ||
@@ -210,4 +225,3 @@ doubleHeight: false, | ||
invert: false, | ||
charset: 0, | ||
...RichChar.getDelimited(prevChar.attributes), | ||
...RichChar.getDelimited(prevChar.attributes, lastAttributes.charset), | ||
}; | ||
@@ -232,3 +246,3 @@ } else { | ||
if (+lineIdx === 0 && this.settings.statusBar) outputString.push('\x1f\x41\x41'); | ||
lastAttributes = { ...lastAttributes, ...RichChar.getDelimited(Minitel.defaultScreenAttributes) }; | ||
lastAttributes = { ...lastAttributes, ...RichChar.getDelimited(Minitel.defaultScreenAttributes, lastAttributes.charset) }; | ||
} | ||
@@ -250,6 +264,6 @@ this.previousRender = renderGrid.copy(); | ||
} | ||
// if i get bullied in prépa, it will be because of this | ||
let preOptimized = outputString.join('\x80'); | ||
// parcoursuop forbid me from going to prépa. RIP :') | ||
let preOptimized = outputString.filter((v) => v !== '').join('€'); | ||
preOptimized = preOptimized.replace( | ||
/(.)(\x80\1){2,62}/g, | ||
/(.)(€\1){2,62}/g, | ||
(v) => `${v[0]}\x12${String.fromCharCode((v.length + 1) / 2 + 63)}`, | ||
@@ -259,3 +273,3 @@ ); | ||
// console.log(JSON.stringify(preOptimized)); | ||
return preOptimized.split('\x80').join(''); | ||
return preOptimized.split('€').join(''); | ||
} | ||
@@ -311,3 +325,5 @@ toCursorMove(y: number, x: number) { | ||
// this.stream.write('\x0c'); | ||
this.stream.write(this.renderString()); | ||
const renderMe = this.renderString(); | ||
this.stream.write(renderMe); | ||
setTimeout((function (this: Minitel) { this.emit('frame') }).bind(this), renderMe.length * (8000 / (this.speed || 300))); | ||
} | ||
@@ -324,2 +340,5 @@ queueCommand(command: string, expected: string | RegExp, callback: ((_arg0: string) => any) = ((_arg0: string) => {})) { | ||
} | ||
requestAnimationFrame(callback: () => any) { | ||
this.once('frame', () => callback()); | ||
} | ||
get colors() { | ||
@@ -326,0 +345,0 @@ if (this.model === 'Bs0') { |
@@ -9,6 +9,7 @@ import { CharAttributes } from './types.js'; | ||
// skip: boolean; | ||
static getDelimited(attributes: CharAttributes): Pick<CharAttributes, 'bg' | 'underline'> { | ||
static getDelimited(attributes: CharAttributes, charset: number) { | ||
return { | ||
bg: attributes.bg, | ||
...(charset !== 1 ? { bg: attributes.bg } : {}), | ||
underline: attributes.underline, | ||
charset: attributes.charset, | ||
} | ||
@@ -15,0 +16,0 @@ } |
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
193670
4230