tidepool 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/eslint.yml +50 -0
- package/{src/index.ts → dist/index.d.ts} +5 -5
- package/dist/index.d.ts.map +1 -0
- package/{src/interfaces.ts → dist/interfaces.d.ts} +5 -4
- package/dist/interfaces.d.ts.map +1 -0
- package/dist/objects/box.d.ts +17 -0
- package/dist/objects/box.d.ts.map +1 -0
- package/dist/objects/text.d.ts +11 -0
- package/dist/objects/text.d.ts.map +1 -0
- package/dist/screen.d.ts +20 -0
- package/dist/screen.d.ts.map +1 -0
- package/dist/util.d.ts +3 -0
- package/dist/util.d.ts.map +1 -0
- package/eslint.config.mjs +38 -0
- package/package.json +10 -3
- package/bun.lockb +0 -0
- package/src/objects/box.ts +0 -78
- package/src/objects/text.ts +0 -34
- package/src/screen.ts +0 -70
- package/src/util.ts +0 -32
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
2
|
+
# They are provided by a third-party and are governed by
|
|
3
|
+
# separate terms of service, privacy policy, and support
|
|
4
|
+
# documentation.
|
|
5
|
+
# ESLint is a tool for identifying and reporting on patterns
|
|
6
|
+
# found in ECMAScript/JavaScript code.
|
|
7
|
+
# More details at https://github.com/eslint/eslint
|
|
8
|
+
# and https://eslint.org
|
|
9
|
+
|
|
10
|
+
name: ESLint
|
|
11
|
+
|
|
12
|
+
on:
|
|
13
|
+
push:
|
|
14
|
+
branches: [ "main" ]
|
|
15
|
+
pull_request:
|
|
16
|
+
# The branches below must be a subset of the branches above
|
|
17
|
+
branches: [ "main" ]
|
|
18
|
+
schedule:
|
|
19
|
+
- cron: '21 0 * * 3'
|
|
20
|
+
|
|
21
|
+
jobs:
|
|
22
|
+
eslint:
|
|
23
|
+
name: Run eslint scanning
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
permissions:
|
|
26
|
+
contents: read
|
|
27
|
+
security-events: write
|
|
28
|
+
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
|
|
29
|
+
steps:
|
|
30
|
+
- name: Checkout code
|
|
31
|
+
uses: actions/checkout@v4
|
|
32
|
+
|
|
33
|
+
- name: Install ESLint
|
|
34
|
+
run: |
|
|
35
|
+
npm install eslint@8.10.0
|
|
36
|
+
npm install @microsoft/eslint-formatter-sarif@2.1.7
|
|
37
|
+
|
|
38
|
+
- name: Run ESLint
|
|
39
|
+
run: npx eslint .
|
|
40
|
+
--config .eslintrc.js
|
|
41
|
+
--ext .js,.jsx,.ts,.tsx
|
|
42
|
+
--format @microsoft/eslint-formatter-sarif
|
|
43
|
+
--output-file eslint-results.sarif
|
|
44
|
+
continue-on-error: true
|
|
45
|
+
|
|
46
|
+
- name: Upload analysis results to GitHub
|
|
47
|
+
uses: github/codeql-action/upload-sarif@v3
|
|
48
|
+
with:
|
|
49
|
+
sarif_file: eslint-results.sarif
|
|
50
|
+
wait-for-processing: true
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Box } from "./objects/box";
|
|
2
|
-
import { Text } from "./objects/text";
|
|
3
|
-
import { TideScreen } from "./screen";
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Box } from "./objects/box";
|
|
2
|
+
import { Text } from "./objects/text";
|
|
3
|
+
import { TideScreen } from "./screen";
|
|
4
|
+
export { Box, Text, TideScreen };
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export interface TideObject {
|
|
2
|
-
zIndex: number;
|
|
3
|
-
draw: Function;
|
|
4
|
-
}
|
|
1
|
+
export interface TideObject {
|
|
2
|
+
zIndex: number;
|
|
3
|
+
draw: Function;
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,CAAC;CAClB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TideObject } from "../interfaces";
|
|
2
|
+
export declare class Box implements TideObject {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
color: string;
|
|
8
|
+
title: string;
|
|
9
|
+
contents: TideObject[];
|
|
10
|
+
zIndex: number;
|
|
11
|
+
constructor(x: number, y: number, width: number, height: number, color?: string, title?: string, zIndex?: number);
|
|
12
|
+
addContent(content: TideObject): void;
|
|
13
|
+
clear(screen: string[][]): void;
|
|
14
|
+
draw(screen: string[][]): void;
|
|
15
|
+
move(dx: number, dy: number): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=box.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../../src/objects/box.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,qBAAa,GAAI,YAAW,UAAU;IAClC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;gBAEH,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,SAAU,EAAE,KAAK,SAAK,EAAE,MAAM,SAAI;IAWxG,UAAU,CAAC,OAAO,EAAE,UAAU;IAI9B,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;IAQxB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;IAoCvB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;CAI5B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TideObject } from "../interfaces";
|
|
2
|
+
export declare class Text implements TideObject {
|
|
3
|
+
relativeX: number;
|
|
4
|
+
relativeY: number;
|
|
5
|
+
text: string;
|
|
6
|
+
color: string;
|
|
7
|
+
zIndex: number;
|
|
8
|
+
constructor(x: number, y: number, text: string, color?: string, zIndex?: number);
|
|
9
|
+
draw(screen: string[][], boxX: number, boxY: number, boxWidth: number): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/objects/text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,qBAAa,IAAK,YAAW,UAAU;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;gBAEH,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,SAAU,EAAE,MAAM,SAAI;IAQ3E,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAetE"}
|
package/dist/screen.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TideObject } from "./interfaces";
|
|
2
|
+
export declare class TideScreen {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
screen: string[][];
|
|
6
|
+
buffer: string[][];
|
|
7
|
+
components: TideObject[];
|
|
8
|
+
fps: number | null;
|
|
9
|
+
updateFunction: (() => void) | null;
|
|
10
|
+
constructor(width: number, height: number);
|
|
11
|
+
clearScreen(): void;
|
|
12
|
+
clearBuffer(): void;
|
|
13
|
+
addComponent(component: TideObject): void;
|
|
14
|
+
renderBuffer(): void;
|
|
15
|
+
render(): void;
|
|
16
|
+
setUpdateFunction(fn: () => void): void;
|
|
17
|
+
setFPS(fps: number): void;
|
|
18
|
+
renderCycle(): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=screen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screen.d.ts","sourceRoot":"","sources":["../src/screen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,UAAU;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;IACnB,UAAU,EAAE,UAAU,EAAE,CAAC;IACzB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC1B,cAAc,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAQ;gBAE/B,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAQzC,WAAW;IAIX,WAAW;IAIX,YAAY,CAAC,SAAS,EAAE,UAAU;IAIlC,YAAY;IAMZ,MAAM;IAMN,iBAAiB,CAAC,EAAE,EAAE,MAAM,IAAI;IAIhC,MAAM,CAAC,GAAG,EAAE,MAAM;IAIlB,WAAW;CAkBd"}
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,UAczC;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,YAetD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import typescriptEslint from "@typescript-eslint/eslint-plugin";
|
|
2
|
+
import globals from "globals";
|
|
3
|
+
import tsParser from "@typescript-eslint/parser";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import js from "@eslint/js";
|
|
7
|
+
import { FlatCompat } from "@eslint/eslintrc";
|
|
8
|
+
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
const compat = new FlatCompat({
|
|
12
|
+
baseDirectory: __dirname,
|
|
13
|
+
recommendedConfig: js.configs.recommended,
|
|
14
|
+
allConfig: js.configs.all
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export default [
|
|
18
|
+
...compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended"),
|
|
19
|
+
{
|
|
20
|
+
plugins: {
|
|
21
|
+
"@typescript-eslint": typescriptEslint,
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
languageOptions: {
|
|
25
|
+
globals: {
|
|
26
|
+
...globals.node,
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
parser: tsParser,
|
|
30
|
+
ecmaVersion: 12,
|
|
31
|
+
sourceType: "module",
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
rules: {
|
|
35
|
+
"@typescript-eslint/no-unsafe-function-type": "off",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
];
|
package/package.json
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tidepool",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"author": "stuncs69",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"devDependencies": {
|
|
7
|
+
"@eslint/js": "^9.9.0",
|
|
7
8
|
"@types/node": "^22.2.0",
|
|
8
|
-
"typescript": "^
|
|
9
|
+
"@typescript-eslint/eslint-plugin": "^8.1.0",
|
|
10
|
+
"@typescript-eslint/parser": "^8.1.0",
|
|
11
|
+
"eslint": "^9.9.0",
|
|
12
|
+
"globals": "^15.9.0",
|
|
13
|
+
"typescript": "^5.5.4",
|
|
14
|
+
"typescript-eslint": "^8.1.0"
|
|
9
15
|
},
|
|
10
16
|
"description": "A CLI rendering engine in TypeScript.",
|
|
11
17
|
"license": "ISC",
|
|
12
18
|
"scripts": {
|
|
13
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
19
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
20
|
+
"lint": "eslint ./src/*"
|
|
14
21
|
}
|
|
15
22
|
}
|
package/bun.lockb
DELETED
|
Binary file
|
package/src/objects/box.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { TideObject } from "../interfaces";
|
|
2
|
-
import { getColorCode } from "../util";
|
|
3
|
-
|
|
4
|
-
export class Box implements TideObject {
|
|
5
|
-
x: number;
|
|
6
|
-
y: number;
|
|
7
|
-
width: number;
|
|
8
|
-
height: number;
|
|
9
|
-
color: string;
|
|
10
|
-
title: string;
|
|
11
|
-
contents: TideObject[];
|
|
12
|
-
zIndex: number;
|
|
13
|
-
|
|
14
|
-
constructor(x: number, y: number, width: number, height: number, color = 'reset', title = '', zIndex = 0) {
|
|
15
|
-
this.x = x;
|
|
16
|
-
this.y = y;
|
|
17
|
-
this.width = width;
|
|
18
|
-
this.height = height;
|
|
19
|
-
this.color = color;
|
|
20
|
-
this.title = title;
|
|
21
|
-
this.contents = [];
|
|
22
|
-
this.zIndex = zIndex;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
addContent(content: TideObject) {
|
|
26
|
-
this.contents.push(content);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
clear(screen: string[][]) {
|
|
30
|
-
for (let i = this.y; i < this.y + this.height; i++) {
|
|
31
|
-
for (let j = this.x; j < this.x + this.width; j++) {
|
|
32
|
-
screen[i][j] = ' ';
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
draw(screen: string[][]) {
|
|
38
|
-
this.clear(screen);
|
|
39
|
-
|
|
40
|
-
const colorCode = getColorCode(this.color);
|
|
41
|
-
const titleColorCode = getColorCode('magenta');
|
|
42
|
-
|
|
43
|
-
for (let i = this.x + 1; i < this.x + this.width - 1; i++) {
|
|
44
|
-
screen[this.y][i] = `${colorCode}─\x1b[0m`;
|
|
45
|
-
}
|
|
46
|
-
for (let i = this.x + 1; i < this.x + this.width - 1; i++) {
|
|
47
|
-
screen[this.y + this.height - 1][i] = `${colorCode}─\x1b[0m`;
|
|
48
|
-
}
|
|
49
|
-
for (let i = this.y + 1; i < this.y + this.height - 1; i++) {
|
|
50
|
-
screen[i][this.x] = `${colorCode}│\x1b[0m`;
|
|
51
|
-
screen[i][this.x + this.width - 1] = `${colorCode}│\x1b[0m`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
screen[this.y][this.x] = `${colorCode}┌\x1b[0m`;
|
|
55
|
-
screen[this.y][this.x + this.width - 1] = `${colorCode}┐\x1b[0m`;
|
|
56
|
-
screen[this.y + this.height - 1][this.x] = `${colorCode}└\x1b[0m`;
|
|
57
|
-
screen[this.y + this.height - 1][this.x + this.width - 1] = `${colorCode}┘\x1b[0m`;
|
|
58
|
-
|
|
59
|
-
if (this.title) {
|
|
60
|
-
const titlePosition = Math.max(this.x + 2, Math.min(this.x + this.width - 2 - this.title.length, this.x + 2));
|
|
61
|
-
for (let i = 0; i < this.title.length; i++) {
|
|
62
|
-
if (titlePosition + i < screen[0].length && this.y < screen.length) {
|
|
63
|
-
screen[this.y][titlePosition + i] = `${titleColorCode}${this.title[i]}\x1b[0m`;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
for (let content of this.contents) {
|
|
69
|
-
content.draw(screen, this.x + 1, this.y + 1, this.width - 2);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
move(dx: number, dy: number) {
|
|
74
|
-
this.x += dx;
|
|
75
|
-
this.y += dy;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
package/src/objects/text.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { TideObject } from "../interfaces";
|
|
2
|
-
import { getColorCode, wrapText } from "../util";
|
|
3
|
-
|
|
4
|
-
export class Text implements TideObject {
|
|
5
|
-
relativeX: number;
|
|
6
|
-
relativeY: number;
|
|
7
|
-
text: string;
|
|
8
|
-
color: string;
|
|
9
|
-
zIndex: number;
|
|
10
|
-
|
|
11
|
-
constructor(x: number, y: number, text: string, color = 'reset', zIndex = 0) {
|
|
12
|
-
this.relativeX = x;
|
|
13
|
-
this.relativeY = y;
|
|
14
|
-
this.text = text;
|
|
15
|
-
this.color = color;
|
|
16
|
-
this.zIndex = zIndex;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
draw(screen: string[][], boxX: number, boxY: number, boxWidth: number) {
|
|
20
|
-
const colorCode = getColorCode(this.color);
|
|
21
|
-
const lines = wrapText(this.text, boxWidth);
|
|
22
|
-
|
|
23
|
-
for (let i = 0; i < lines.length; i++) {
|
|
24
|
-
const line = lines[i];
|
|
25
|
-
for (let j = 0; j < line.length; j++) {
|
|
26
|
-
const screenX = boxX + this.relativeX + j;
|
|
27
|
-
const screenY = boxY + this.relativeY + i;
|
|
28
|
-
if (screenX < screen[0].length && screenY < screen.length) {
|
|
29
|
-
screen[screenY][screenX] = `${colorCode}${line[j]}\x1b[0m`;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
package/src/screen.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { TideObject } from "./interfaces";
|
|
2
|
-
|
|
3
|
-
export class TideScreen {
|
|
4
|
-
width: number;
|
|
5
|
-
height: number;
|
|
6
|
-
screen: string[][];
|
|
7
|
-
buffer: string[][];
|
|
8
|
-
components: TideObject[];
|
|
9
|
-
fps: number | null = null;
|
|
10
|
-
updateFunction: (() => void) | null = null;
|
|
11
|
-
|
|
12
|
-
constructor(width: number, height: number) {
|
|
13
|
-
this.width = width;
|
|
14
|
-
this.height = height;
|
|
15
|
-
this.screen = Array.from({ length: height }, () => Array(width).fill(' '));
|
|
16
|
-
this.buffer = Array.from({ length: height }, () => Array(width).fill(' '));
|
|
17
|
-
this.components = [];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
clearScreen() {
|
|
21
|
-
this.screen = Array.from({ length: this.height }, () => Array(this.width).fill(' '));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
clearBuffer() {
|
|
25
|
-
this.buffer = Array.from({ length: this.height }, () => Array(this.width).fill(' '));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
addComponent(component: TideObject) {
|
|
29
|
-
this.components.push(component);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
renderBuffer() {
|
|
33
|
-
this.clearBuffer();
|
|
34
|
-
this.components.sort((a, b) => b.zIndex - a.zIndex);
|
|
35
|
-
this.components.forEach(component => component.draw(this.buffer));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
render() {
|
|
39
|
-
console.clear();
|
|
40
|
-
const output = this.buffer.map(row => row.join('')).join('\n');
|
|
41
|
-
console.log(output);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
setUpdateFunction(fn: () => void) {
|
|
45
|
-
this.updateFunction = fn;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
setFPS(fps: number) {
|
|
49
|
-
this.fps = fps;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
renderCycle() {
|
|
53
|
-
if (this.fps === null) {
|
|
54
|
-
throw new Error("FPS must be set before starting the render cycle.");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const interval = 1000 / this.fps;
|
|
58
|
-
|
|
59
|
-
const loop = () => {
|
|
60
|
-
if (this.updateFunction) {
|
|
61
|
-
this.updateFunction();
|
|
62
|
-
}
|
|
63
|
-
this.renderBuffer(); // Prepare the buffer with updated content
|
|
64
|
-
this.render(); // Output the buffer to the screen
|
|
65
|
-
setTimeout(loop, interval);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
loop();
|
|
69
|
-
}
|
|
70
|
-
}
|
package/src/util.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export function getColorCode(color: string) {
|
|
2
|
-
const colors: { [key: string]: string } = {
|
|
3
|
-
reset: '\x1b[0m',
|
|
4
|
-
black: '\x1b[30m',
|
|
5
|
-
red: '\x1b[31m',
|
|
6
|
-
green: '\x1b[32m',
|
|
7
|
-
yellow: '\x1b[33m',
|
|
8
|
-
blue: '\x1b[34m',
|
|
9
|
-
magenta: '\x1b[35m',
|
|
10
|
-
cyan: '\x1b[36m',
|
|
11
|
-
white: '\x1b[37m',
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
return colors[color.toLowerCase()] || colors['reset'];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function wrapText(text: string, maxWidth: number) {
|
|
18
|
-
const lines = [];
|
|
19
|
-
let currentLine = '';
|
|
20
|
-
|
|
21
|
-
for (const word of text.split(' ')) {
|
|
22
|
-
if ((currentLine + word).length > maxWidth) {
|
|
23
|
-
lines.push(currentLine.trim());
|
|
24
|
-
currentLine = word + ' ';
|
|
25
|
-
} else {
|
|
26
|
-
currentLine += word + ' ';
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
lines.push(currentLine.trim());
|
|
30
|
-
|
|
31
|
-
return lines;
|
|
32
|
-
}
|