tidepool 1.0.6 → 2.0.0

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.
@@ -1,17 +1,21 @@
1
- import { TideObject } from "../interfaces";
1
+ import type { RenderContext, TideEffect, TideObject } from "../interfaces";
2
2
  export declare class Box implements TideObject {
3
3
  x: number;
4
4
  y: number;
5
5
  width: number;
6
6
  height: number;
7
7
  color: string;
8
+ borderColor: string;
9
+ backgroundColor: string;
8
10
  title: string;
9
11
  contents: TideObject[];
10
12
  zIndex: number;
11
- constructor(x: number, y: number, width: number, height: number, color?: string, title?: string, zIndex?: number);
13
+ effects: TideEffect[];
14
+ constructor(x: number, y: number, width: number, height: number, color?: string, borderColor?: string, backgroundColor?: string, title?: string, zIndex?: number);
12
15
  addContent(content: TideObject): void;
13
- clear(screen: string[][]): void;
14
- draw(screen: string[][]): void;
15
- move(dx: number, dy: number): void;
16
+ clear(ctx: RenderContext): void;
17
+ draw(ctx: RenderContext): void;
18
+ addEffect(effect: TideEffect): void;
19
+ move(x: number, y: number): void;
16
20
  }
17
21
  //# sourceMappingURL=box.d.ts.map
@@ -1 +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;IAWxB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;IAyCvB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;CAI9B"}
1
+ {"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../../src/objects/box.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAGhF,qBAAa,GAAI,YAAW,UAAU;IACpC,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,eAAe,EAAE,MAAM,CAAA;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,UAAU,EAAE,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,UAAU,EAAE,CAAK;gBAGxB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,KAAK,SAAU,EACf,WAAW,SAAU,EACrB,eAAe,SAAU,EACzB,KAAK,SAAK,EACV,MAAM,SAAI;IAcZ,UAAU,CAAC,OAAO,EAAE,UAAU;IAI9B,KAAK,CAAC,GAAG,EAAE,aAAa;IAsBxB,IAAI,CAAC,GAAG,EAAE,aAAa;IAsJvB,SAAS,CAAC,MAAM,EAAE,UAAU;IAI1B,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;CAI5B"}
@@ -3,64 +3,102 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Box = void 0;
4
4
  const util_1 = require("../util");
5
5
  class Box {
6
- constructor(x, y, width, height, color = 'reset', title = '', zIndex = 0) {
6
+ constructor(x, y, width, height, color = "reset", borderColor = "reset", backgroundColor = "reset", title = "", zIndex = 0) {
7
+ this.effects = [];
7
8
  this.x = x;
8
9
  this.y = y;
9
10
  this.width = width;
10
11
  this.height = height;
11
12
  this.color = color;
13
+ this.borderColor = borderColor;
14
+ this.backgroundColor = backgroundColor;
12
15
  this.title = title;
13
16
  this.contents = [];
14
- this.zIndex = zIndex;
17
+ this.zIndex = zIndex * 10;
15
18
  }
16
19
  addContent(content) {
17
20
  this.contents.push(content);
18
21
  }
19
- clear(screen) {
20
- const maxY = Math.min(this.y + this.height, screen.length);
21
- const maxX = Math.min(this.x + this.width, screen[0].length);
22
- for (let i = this.y; i < maxY; i++) {
23
- for (let j = this.x; j < maxX; j++) {
24
- screen[i][j] = ' ';
22
+ clear(ctx) {
23
+ const screen = ctx.buffer;
24
+ const originX = ctx.origin.x + this.x;
25
+ const originY = ctx.origin.y + this.y;
26
+ const maxY = Math.min(originY + this.height, screen.length);
27
+ const maxX = Math.min(originX + this.width, screen[0].length);
28
+ const bgColorCode = (0, util_1.getColorCode)(this.backgroundColor);
29
+ for (let i = originY; i < maxY; i++) {
30
+ for (let j = originX; j < maxX; j++) {
31
+ (0, util_1.setCell)(screen, j, i, `${bgColorCode} \x1b[0m`, ctx.clip, ctx.dirtyRows);
25
32
  }
26
33
  }
27
34
  }
28
- draw(screen) {
29
- const maxY = Math.min(this.y + this.height, screen.length);
30
- const maxX = Math.min(this.x + this.width, screen[0].length);
31
- if (this.x >= screen[0].length || this.y >= screen.length || maxY <= this.y || maxX <= this.x) {
35
+ draw(ctx) {
36
+ const screen = ctx.buffer;
37
+ const originX = ctx.origin.x + this.x;
38
+ const originY = ctx.origin.y + this.y;
39
+ const maxY = Math.min(originY + this.height, screen.length);
40
+ const maxX = Math.min(originX + this.width, screen[0].length);
41
+ if (originX >= screen[0].length ||
42
+ originY >= screen.length ||
43
+ maxY <= originY ||
44
+ maxX <= originX) {
32
45
  return;
33
46
  }
34
- this.clear(screen);
35
- const colorCode = (0, util_1.getColorCode)(this.color);
36
- const titleColorCode = (0, util_1.getColorCode)('magenta');
37
- for (let i = this.x + 1; i < maxX - 1; i++) {
38
- screen[this.y][i] = `${colorCode}─\x1b[0m`;
47
+ const borderColorCode = (0, util_1.getColorCode)(this.borderColor);
48
+ const titleColorCode = (0, util_1.getColorCode)("magenta");
49
+ const bgColorCode = (0, util_1.getColorCode)(this.backgroundColor);
50
+ const resetCode = "\x1b[0m";
51
+ for (let i = originX + 1; i < maxX - 1; i++) {
52
+ (0, util_1.setCell)(screen, i, originY, `${bgColorCode}${borderColorCode}─${resetCode}`, ctx.clip, ctx.dirtyRows);
53
+ (0, util_1.setCell)(screen, i, maxY - 1, `${bgColorCode}${borderColorCode}─${resetCode}`, ctx.clip, ctx.dirtyRows);
39
54
  }
40
- for (let i = this.x + 1; i < maxX - 1; i++) {
41
- screen[maxY - 1][i] = `${colorCode}─\x1b[0m`;
55
+ for (let i = originY + 1; i < maxY - 1; i++) {
56
+ (0, util_1.setCell)(screen, originX, i, `${bgColorCode}${borderColorCode}│${resetCode}`, ctx.clip, ctx.dirtyRows);
57
+ (0, util_1.setCell)(screen, maxX - 1, i, `${bgColorCode}${borderColorCode}│${resetCode}`, ctx.clip, ctx.dirtyRows);
42
58
  }
43
- for (let i = this.y + 1; i < maxY - 1; i++) {
44
- screen[i][this.x] = `${colorCode}│\x1b[0m`;
45
- screen[i][maxX - 1] = `${colorCode}│\x1b[0m`;
59
+ (0, util_1.setCell)(screen, originX, originY, `${bgColorCode}${borderColorCode}┌${resetCode}`, ctx.clip, ctx.dirtyRows);
60
+ (0, util_1.setCell)(screen, maxX - 1, originY, `${bgColorCode}${borderColorCode}┐${resetCode}`, ctx.clip, ctx.dirtyRows);
61
+ (0, util_1.setCell)(screen, originX, maxY - 1, `${bgColorCode}${borderColorCode}└${resetCode}`, ctx.clip, ctx.dirtyRows);
62
+ (0, util_1.setCell)(screen, maxX - 1, maxY - 1, `${bgColorCode}${borderColorCode}┘${resetCode}`, ctx.clip, ctx.dirtyRows);
63
+ for (let i = originY + 1; i < maxY - 1; i++) {
64
+ for (let j = originX + 1; j < maxX - 1; j++) {
65
+ (0, util_1.setCell)(screen, j, i, `${bgColorCode} ${resetCode}`, ctx.clip, ctx.dirtyRows);
66
+ }
46
67
  }
47
- screen[this.y][this.x] = `${colorCode}┌\x1b[0m`;
48
- screen[this.y][maxX - 1] = `${colorCode}┐\x1b[0m`;
49
- screen[maxY - 1][this.x] = `${colorCode}└\x1b[0m`;
50
- screen[maxY - 1][maxX - 1] = `${colorCode}┘\x1b[0m`;
51
68
  if (this.title) {
52
- const titlePosition = Math.max(this.x + 2, Math.min(maxX - 2 - this.title.length, this.x + 2));
69
+ const titlePosition = Math.max(originX + 2, Math.min(maxX - 2 - this.title.length, originX + 2));
53
70
  for (let i = 0; i < this.title.length && titlePosition + i < maxX; i++) {
54
- screen[this.y][titlePosition + i] = `${titleColorCode}${this.title[i]}\x1b[0m`;
71
+ (0, util_1.setCell)(screen, titlePosition + i, originY, `${bgColorCode}${titleColorCode}${this.title[i]}${resetCode}`, ctx.clip, ctx.dirtyRows);
55
72
  }
56
73
  }
74
+ for (const effect of this.effects) {
75
+ effect.apply(this, ctx);
76
+ }
77
+ const innerRect = {
78
+ x: originX + 1,
79
+ y: originY + 1,
80
+ width: Math.max(0, maxX - originX - 2),
81
+ height: Math.max(0, maxY - originY - 2),
82
+ };
83
+ const innerClip = (0, util_1.intersectRect)(ctx.clip, innerRect);
84
+ if (!innerClip) {
85
+ return;
86
+ }
57
87
  for (const content of this.contents) {
58
- content.draw(screen, this.x + 1, this.y + 1, maxX - this.x - 2);
88
+ content.draw({
89
+ buffer: screen,
90
+ origin: { x: innerRect.x, y: innerRect.y },
91
+ clip: innerClip,
92
+ screenSize: ctx.screenSize,
93
+ });
59
94
  }
60
95
  }
61
- move(dx, dy) {
62
- this.x += dx;
63
- this.y += dy;
96
+ addEffect(effect) {
97
+ this.effects.push(effect);
98
+ }
99
+ move(x, y) {
100
+ this.x += x;
101
+ this.y += y;
64
102
  }
65
103
  }
66
104
  exports.Box = Box;
@@ -0,0 +1,29 @@
1
+ import type { Focusable, KeyInfo, RenderContext, TideEffect, TideObject } from "../interfaces";
2
+ export interface ButtonOptions {
3
+ onPress?: () => void;
4
+ focusedBackgroundColor?: string;
5
+ focusedTextColor?: string;
6
+ }
7
+ export declare class Button implements TideObject, Focusable {
8
+ x: number;
9
+ y: number;
10
+ width: number;
11
+ height: number;
12
+ text: string;
13
+ textColor: string;
14
+ backgroundColor: string;
15
+ zIndex: number;
16
+ effects: TideEffect[];
17
+ isFocused: boolean;
18
+ onPress?: () => void;
19
+ focusedBackgroundColor: string;
20
+ focusedTextColor: string;
21
+ constructor(zIndex: number, x: number, y: number, width: number, height: number, text: string, textColor?: string, backgroundColor?: string, options?: ButtonOptions);
22
+ focus(): void;
23
+ blur(): void;
24
+ contains(x: number, y: number): boolean;
25
+ handleClick(_x: number, _y: number): boolean;
26
+ handleKey(_input: string, key: KeyInfo): boolean;
27
+ draw(ctx: RenderContext): void;
28
+ }
29
+ //# sourceMappingURL=button.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../src/objects/button.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG/F,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,qBAAa,MAAO,YAAW,UAAU,EAAE,SAAS;IAClD,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,UAAU,EAAE,CAAM;IAC3B,SAAS,UAAS;IAClB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,gBAAgB,EAAE,MAAM,CAAC;gBAGvB,MAAM,EAAE,MAAM,EACd,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,SAAS,SAAU,EACnB,eAAe,SAAS,EACxB,OAAO,GAAE,aAAkB;IAe7B,KAAK;IAIL,IAAI;IAIJ,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAS7B,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAOlC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO;IAUtC,IAAI,CAAC,GAAG,EAAE,aAAa;CAoDxB"}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Button = void 0;
4
+ const util_1 = require("../util");
5
+ class Button {
6
+ constructor(zIndex, x, y, width, height, text, textColor = "white", backgroundColor = "blue", options = {}) {
7
+ var _a, _b;
8
+ this.effects = [];
9
+ this.isFocused = false;
10
+ this.zIndex = zIndex * 10;
11
+ this.x = x;
12
+ this.y = y;
13
+ this.width = width;
14
+ this.height = height;
15
+ this.text = text;
16
+ this.textColor = textColor;
17
+ this.backgroundColor = backgroundColor;
18
+ this.onPress = options.onPress;
19
+ this.focusedBackgroundColor = (_a = options.focusedBackgroundColor) !== null && _a !== void 0 ? _a : "white";
20
+ this.focusedTextColor = (_b = options.focusedTextColor) !== null && _b !== void 0 ? _b : "black";
21
+ }
22
+ focus() {
23
+ this.isFocused = true;
24
+ }
25
+ blur() {
26
+ this.isFocused = false;
27
+ }
28
+ contains(x, y) {
29
+ return (x >= this.x &&
30
+ y >= this.y &&
31
+ x < this.x + this.width &&
32
+ y < this.y + this.height);
33
+ }
34
+ handleClick(_x, _y) {
35
+ if (this.onPress) {
36
+ this.onPress();
37
+ }
38
+ return true;
39
+ }
40
+ handleKey(_input, key) {
41
+ if (key.name === "return" || key.name === "enter" || key.name === "space") {
42
+ if (this.onPress) {
43
+ this.onPress();
44
+ }
45
+ return true;
46
+ }
47
+ return false;
48
+ }
49
+ draw(ctx) {
50
+ const screen = ctx.buffer;
51
+ const originX = ctx.origin.x + this.x;
52
+ const originY = ctx.origin.y + this.y;
53
+ const activeTextColor = this.isFocused
54
+ ? this.focusedTextColor
55
+ : this.textColor;
56
+ const activeBackground = this.isFocused
57
+ ? this.focusedBackgroundColor
58
+ : this.backgroundColor;
59
+ const textColorCode = (0, util_1.getColorCode)(activeTextColor);
60
+ const bgColorCode = (0, util_1.getColorCode)(activeBackground);
61
+ const resetCode = "\x1b[0m";
62
+ // Fill the button area with background-colored spaces
63
+ for (let i = originY; i < originY + this.height; i++) {
64
+ for (let j = originX; j < originX + this.width; j++) {
65
+ (0, util_1.setCell)(screen, j, i, `${bgColorCode} ${resetCode}`, ctx.clip, ctx.dirtyRows);
66
+ }
67
+ }
68
+ // Pad the text with one space on each side.
69
+ const paddedText = " " + this.text + " ";
70
+ // Calculate the starting x position for centered text.
71
+ // Make sure we center the padded text, not the original text.
72
+ const textStart = originX + Math.floor((this.width - paddedText.length) / 2);
73
+ const textRow = originY + Math.floor(this.height / 2);
74
+ // Draw the padded text onto the screen.
75
+ for (let i = 0; i < paddedText.length && textStart + i < this.x + this.width; i++) {
76
+ (0, util_1.setCell)(screen, textStart + i, textRow, `${bgColorCode}${textColorCode}${paddedText[i]}${resetCode}`, ctx.clip, ctx.dirtyRows);
77
+ }
78
+ }
79
+ }
80
+ exports.Button = Button;
@@ -0,0 +1,38 @@
1
+ import type { Focusable, KeyInfo, RenderContext, TideObject } from "../interfaces";
2
+ export interface InputFieldOptions {
3
+ zIndex?: number;
4
+ textColor?: string;
5
+ backgroundColor?: string;
6
+ borderColor?: string;
7
+ placeholder?: string;
8
+ placeholderColor?: string;
9
+ maxLength?: number;
10
+ onChange?: (value: string) => void;
11
+ onSubmit?: (value: string) => void;
12
+ }
13
+ export declare class InputField implements TideObject, Focusable {
14
+ x: number;
15
+ y: number;
16
+ width: number;
17
+ height: number;
18
+ value: string;
19
+ zIndex: number;
20
+ isFocused: boolean;
21
+ cursor: number;
22
+ textColor: string;
23
+ backgroundColor: string;
24
+ borderColor: string;
25
+ placeholder: string;
26
+ placeholderColor: string;
27
+ maxLength: number;
28
+ onChange?: (value: string) => void;
29
+ onSubmit?: (value: string) => void;
30
+ constructor(x: number, y: number, width: number, height?: number, initialValue?: string, options?: InputFieldOptions);
31
+ focus(): void;
32
+ blur(): void;
33
+ contains(x: number, y: number): boolean;
34
+ handleClick(_x: number, _y: number): boolean;
35
+ handleKey(input: string, key: KeyInfo): boolean;
36
+ draw(ctx: RenderContext): void;
37
+ }
38
+ //# sourceMappingURL=input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/objects/input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGnF,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED,qBAAa,UAAW,YAAW,UAAU,EAAE,SAAS;IACtD,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,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,UAAS;IAClB,MAAM,SAAK;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;gBAGjC,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,MAAM,EACb,MAAM,SAAI,EACV,YAAY,SAAK,EACjB,OAAO,GAAE,iBAAsB;IAmBjC,KAAK;IAIL,IAAI;IAIJ,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAS7B,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAIlC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO;IA+DrC,IAAI,CAAC,GAAG,EAAE,aAAa;CAwHxB"}
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InputField = void 0;
4
+ const util_1 = require("../util");
5
+ class InputField {
6
+ constructor(x, y, width, height = 3, initialValue = "", options = {}) {
7
+ var _a, _b, _c, _d, _e, _f, _g;
8
+ this.isFocused = false;
9
+ this.cursor = 0;
10
+ this.x = x;
11
+ this.y = y;
12
+ this.width = width;
13
+ this.height = height;
14
+ this.value = initialValue;
15
+ this.cursor = initialValue.length;
16
+ this.zIndex = ((_a = options.zIndex) !== null && _a !== void 0 ? _a : 0) * 10;
17
+ this.textColor = (_b = options.textColor) !== null && _b !== void 0 ? _b : "white";
18
+ this.backgroundColor = (_c = options.backgroundColor) !== null && _c !== void 0 ? _c : "reset";
19
+ this.borderColor = (_d = options.borderColor) !== null && _d !== void 0 ? _d : "cyan";
20
+ this.placeholder = (_e = options.placeholder) !== null && _e !== void 0 ? _e : "";
21
+ this.placeholderColor = (_f = options.placeholderColor) !== null && _f !== void 0 ? _f : "gray";
22
+ this.maxLength = (_g = options.maxLength) !== null && _g !== void 0 ? _g : 256;
23
+ this.onChange = options.onChange;
24
+ this.onSubmit = options.onSubmit;
25
+ }
26
+ focus() {
27
+ this.isFocused = true;
28
+ }
29
+ blur() {
30
+ this.isFocused = false;
31
+ }
32
+ contains(x, y) {
33
+ return (x >= this.x &&
34
+ y >= this.y &&
35
+ x < this.x + this.width &&
36
+ y < this.y + this.height);
37
+ }
38
+ handleClick(_x, _y) {
39
+ return true;
40
+ }
41
+ handleKey(input, key) {
42
+ if (key.name === "left") {
43
+ this.cursor = Math.max(0, this.cursor - 1);
44
+ return true;
45
+ }
46
+ if (key.name === "right") {
47
+ this.cursor = Math.min(this.value.length, this.cursor + 1);
48
+ return true;
49
+ }
50
+ if (key.name === "home") {
51
+ this.cursor = 0;
52
+ return true;
53
+ }
54
+ if (key.name === "end") {
55
+ this.cursor = this.value.length;
56
+ return true;
57
+ }
58
+ if (key.name === "backspace") {
59
+ if (this.cursor > 0) {
60
+ this.value =
61
+ this.value.slice(0, this.cursor - 1) +
62
+ this.value.slice(this.cursor);
63
+ this.cursor -= 1;
64
+ if (this.onChange) {
65
+ this.onChange(this.value);
66
+ }
67
+ }
68
+ return true;
69
+ }
70
+ if (key.name === "delete") {
71
+ if (this.cursor < this.value.length) {
72
+ this.value =
73
+ this.value.slice(0, this.cursor) + this.value.slice(this.cursor + 1);
74
+ if (this.onChange) {
75
+ this.onChange(this.value);
76
+ }
77
+ }
78
+ return true;
79
+ }
80
+ if (key.name === "return" || key.name === "enter") {
81
+ if (this.onSubmit) {
82
+ this.onSubmit(this.value);
83
+ }
84
+ return true;
85
+ }
86
+ if (input && input.length === 1 && !key.ctrl && !key.meta) {
87
+ if (this.value.length < this.maxLength) {
88
+ this.value =
89
+ this.value.slice(0, this.cursor) +
90
+ input +
91
+ this.value.slice(this.cursor);
92
+ this.cursor += 1;
93
+ if (this.onChange) {
94
+ this.onChange(this.value);
95
+ }
96
+ }
97
+ return true;
98
+ }
99
+ return false;
100
+ }
101
+ draw(ctx) {
102
+ var _a, _b;
103
+ const originX = ctx.origin.x + this.x;
104
+ const originY = ctx.origin.y + this.y;
105
+ const maxX = originX + this.width;
106
+ const maxY = originY + this.height;
107
+ const borderColor = (0, util_1.getColorCode)(this.borderColor);
108
+ const resetCode = "\x1b[0m";
109
+ for (let x = originX + 1; x < maxX - 1; x++) {
110
+ (0, util_1.setCell)(ctx.buffer, x, originY, `${borderColor}─${resetCode}`, ctx.clip, ctx.dirtyRows);
111
+ (0, util_1.setCell)(ctx.buffer, x, maxY - 1, `${borderColor}─${resetCode}`, ctx.clip, ctx.dirtyRows);
112
+ }
113
+ for (let y = originY + 1; y < maxY - 1; y++) {
114
+ (0, util_1.setCell)(ctx.buffer, originX, y, `${borderColor}│${resetCode}`, ctx.clip, ctx.dirtyRows);
115
+ (0, util_1.setCell)(ctx.buffer, maxX - 1, y, `${borderColor}│${resetCode}`, ctx.clip, ctx.dirtyRows);
116
+ }
117
+ (0, util_1.setCell)(ctx.buffer, originX, originY, `${borderColor}┌${resetCode}`, ctx.clip, ctx.dirtyRows);
118
+ (0, util_1.setCell)(ctx.buffer, maxX - 1, originY, `${borderColor}┐${resetCode}`, ctx.clip, ctx.dirtyRows);
119
+ (0, util_1.setCell)(ctx.buffer, originX, maxY - 1, `${borderColor}└${resetCode}`, ctx.clip, ctx.dirtyRows);
120
+ (0, util_1.setCell)(ctx.buffer, maxX - 1, maxY - 1, `${borderColor}┘${resetCode}`, ctx.clip, ctx.dirtyRows);
121
+ const contentWidth = Math.max(0, this.width - 2);
122
+ const contentY = originY + Math.floor(this.height / 2);
123
+ const display = this.value.length > 0 ? this.value : this.placeholder;
124
+ const displayColor = this.value.length > 0 ? this.textColor : this.placeholderColor;
125
+ const colorCode = (0, util_1.getColorCode)(displayColor);
126
+ const bgCode = (0, util_1.getColorCode)(this.backgroundColor);
127
+ const cursorOffset = Math.max(0, this.cursor - (contentWidth - 1));
128
+ const slice = display.slice(cursorOffset, cursorOffset + contentWidth);
129
+ for (let i = 0; i < contentWidth; i++) {
130
+ const ch = (_a = slice[i]) !== null && _a !== void 0 ? _a : " ";
131
+ (0, util_1.setCell)(ctx.buffer, originX + 1 + i, contentY, `${bgCode}${colorCode}${ch}${resetCode}`, ctx.clip, ctx.dirtyRows);
132
+ }
133
+ if (this.isFocused && contentWidth > 0) {
134
+ const cursorIndex = Math.min(this.cursor - cursorOffset, contentWidth - 1);
135
+ const cursorChar = (_b = slice[cursorIndex]) !== null && _b !== void 0 ? _b : " ";
136
+ const cursorX = originX + 1 + cursorIndex;
137
+ (0, util_1.setCell)(ctx.buffer, cursorX, contentY, `${bgCode}\x1b[7m${cursorChar}${resetCode}`, ctx.clip, ctx.dirtyRows);
138
+ }
139
+ }
140
+ }
141
+ exports.InputField = InputField;
@@ -1,4 +1,4 @@
1
- import { TideObject } from "../interfaces";
1
+ import type { RenderContext, TideObject } from "../interfaces";
2
2
  export declare class Line implements TideObject {
3
3
  relativeX: number;
4
4
  relativeY: number;
@@ -6,6 +6,6 @@ export declare class Line implements TideObject {
6
6
  color: string;
7
7
  zIndex: number;
8
8
  constructor(x: number, y: number, length: number, color?: string, zIndex?: number);
9
- draw(screen: string[][], boxX: number, boxY: number): void;
9
+ draw(ctx: RenderContext): void;
10
10
  }
11
11
  //# sourceMappingURL=line.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"line.d.ts","sourceRoot":"","sources":["../../src/objects/line.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,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;gBAEH,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,SAAU,EAAE,MAAM,SAAI;IAQ7E,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAUtD"}
1
+ {"version":3,"file":"line.d.ts","sourceRoot":"","sources":["../../src/objects/line.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG/D,qBAAa,IAAK,YAAW,UAAU;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;gBAEH,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,SAAU,EAAE,MAAM,SAAI;IAQ7E,IAAI,CAAC,GAAG,EAAE,aAAa;CAe1B"}
@@ -8,16 +8,14 @@ class Line {
8
8
  this.relativeY = y;
9
9
  this.length = length;
10
10
  this.color = color;
11
- this.zIndex = zIndex;
11
+ this.zIndex = zIndex * 10;
12
12
  }
13
- draw(screen, boxX, boxY) {
13
+ draw(ctx) {
14
14
  const colorCode = (0, util_1.getColorCode)(this.color);
15
15
  for (let i = 0; i < this.length; i++) {
16
- const screenX = boxX + this.relativeX + i;
17
- const screenY = boxY + this.relativeY;
18
- if (screenX < screen[0].length && screenY < screen.length) {
19
- screen[screenY][screenX] = `${colorCode}─\x1b[0m`;
20
- }
16
+ const screenX = ctx.origin.x + this.relativeX + i;
17
+ const screenY = ctx.origin.y + this.relativeY;
18
+ (0, util_1.setCell)(ctx.buffer, screenX, screenY, `${colorCode}─\x1b[0m`, ctx.clip, ctx.dirtyRows);
21
19
  }
22
20
  }
23
21
  }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=progress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../src/objects/progress.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ "use strict";
@@ -1,11 +1,13 @@
1
- import { TideObject } from "../interfaces";
1
+ import type { RenderContext, TideEffect, TideObject } from "../interfaces";
2
2
  export declare class Text implements TideObject {
3
3
  relativeX: number;
4
4
  relativeY: number;
5
5
  text: string;
6
6
  color: string;
7
7
  zIndex: number;
8
+ effects: TideEffect[];
8
9
  constructor(x: number, y: number, text: string, color?: string, zIndex?: number);
9
- draw(screen: string[][], boxX: number, boxY: number, boxWidth: number): void;
10
+ applyEffect(effect: TideEffect): void;
11
+ draw(ctx: RenderContext): void;
10
12
  }
11
13
  //# sourceMappingURL=text.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/objects/text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3E,qBAAa,IAAK,YAAW,UAAU;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,UAAU,EAAE,CAAM;gBAEf,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,SAAU,EAAE,MAAM,SAAI;IAQ3E,WAAW,CAAC,MAAM,EAAE,UAAU;IAI9B,IAAI,CAAC,GAAG,EAAE,aAAa;CA0BxB"}
@@ -3,24 +3,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Text = void 0;
4
4
  const util_1 = require("../util");
5
5
  class Text {
6
- constructor(x, y, text, color = 'reset', zIndex = 0) {
6
+ constructor(x, y, text, color = "reset", zIndex = 0) {
7
+ this.effects = [];
7
8
  this.relativeX = x;
8
9
  this.relativeY = y;
9
10
  this.text = text;
10
11
  this.color = color;
11
- this.zIndex = zIndex;
12
+ this.zIndex = zIndex * 10;
12
13
  }
13
- draw(screen, boxX, boxY, boxWidth) {
14
+ applyEffect(effect) {
15
+ this.effects.push(effect);
16
+ }
17
+ draw(ctx) {
18
+ const screen = ctx.buffer;
14
19
  const colorCode = (0, util_1.getColorCode)(this.color);
15
- const lines = (0, util_1.wrapText)(this.text, boxWidth);
20
+ const maxWidth = Math.max(0, ctx.clip.width);
21
+ const lines = (0, util_1.wrapText)(this.text, maxWidth);
22
+ for (const effect of this.effects) {
23
+ effect.apply(this, ctx);
24
+ }
16
25
  for (let i = 0; i < lines.length; i++) {
17
26
  const line = lines[i];
18
27
  for (let j = 0; j < line.length; j++) {
19
- const screenX = boxX + this.relativeX + j;
20
- const screenY = boxY + this.relativeY + i;
21
- if (screenX < screen[0].length && screenY < screen.length) {
22
- screen[screenY][screenX] = `${colorCode}${line[j]}\x1b[0m`;
23
- }
28
+ const screenX = ctx.origin.x + this.relativeX + j;
29
+ const screenY = ctx.origin.y + this.relativeY + i;
30
+ (0, util_1.setCell)(screen, screenX, screenY, `${colorCode}${line[j]}\x1b[0m`, ctx.clip, ctx.dirtyRows);
24
31
  }
25
32
  }
26
33
  }
package/dist/screen.d.ts CHANGED
@@ -1,24 +1,34 @@
1
- import { TideObject } from "./interfaces";
1
+ import type { TideObject } from "./interfaces";
2
2
  export declare class TideScreen {
3
3
  width: number;
4
4
  height: number;
5
- screen: string[][];
6
- buffer: string[][];
5
+ frontBuffer: string[][];
6
+ backBuffer: string[][];
7
7
  components: TideObject[];
8
8
  fps: number | null;
9
9
  updateFunction: (() => void) | null;
10
10
  backgroundColor: string;
11
+ private needsSort;
12
+ private resizeListener;
13
+ private didInitialClear;
11
14
  constructor(width: number, height: number, backgroundColor?: string);
12
- clearScreen(): void;
13
- clearBuffer(): void;
15
+ private createBuffer;
16
+ clearBuffer(buffer: string[][], dirtyRows?: Set<number>): void;
14
17
  addComponent(component: TideObject): void;
18
+ invalidateSort(): void;
15
19
  private getBackgroundColorCode;
16
20
  private renderBuffer;
17
- applyBackgroundColor(): void;
21
+ applyBackgroundColor(dirtyRows?: Set<number>): void;
22
+ resize(width: number, height: number): void;
23
+ enableAutoResize(getSize?: () => {
24
+ width: number;
25
+ height: number;
26
+ }): void;
27
+ disableAutoResize(): void;
18
28
  private render;
19
29
  setUpdateFunction(fn: () => void): void;
20
30
  setFPS(fps: number): void;
21
31
  nextFrame(): void;
22
- renderCycle(): void;
32
+ renderCycle(beforeRender?: () => void, afterRender?: () => void): void;
23
33
  }
24
34
  //# sourceMappingURL=screen.d.ts.map
@@ -1 +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;IAC3C,eAAe,EAAE,MAAM,CAAC;gBAEZ,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAE,MAAsB;IASlF,WAAW;IAIX,WAAW;IAIX,YAAY,CAAC,SAAS,EAAE,UAAU;IAIlC,OAAO,CAAC,sBAAsB;IAiB9B,OAAO,CAAC,YAAY;IAMpB,oBAAoB;IAUpB,OAAO,CAAC,MAAM;IAOd,iBAAiB,CAAC,EAAE,EAAE,MAAM,IAAI;IAIhC,MAAM,CAAC,GAAG,EAAE,MAAM;IAIlB,SAAS;IAQT,WAAW;CAkBd"}
1
+ {"version":3,"file":"screen.d.ts","sourceRoot":"","sources":["../src/screen.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,UAAU,EAAE,MAAM,cAAc,CAAC;AAE9D,qBAAa,UAAU;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,EAAE,EAAE,CAAC;IACxB,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC;IACvB,UAAU,EAAE,UAAU,EAAE,CAAC;IACzB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC1B,cAAc,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAQ;IAC3C,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,cAAc,CAA6B;IACnD,OAAO,CAAC,eAAe,CAAS;gBAEpB,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,SAAgB;IAS1E,OAAO,CAAC,YAAY;IAIpB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC;IAWvD,YAAY,CAAC,SAAS,EAAE,UAAU;IAKlC,cAAc;IAId,OAAO,CAAC,sBAAsB;IAiB9B,OAAO,CAAC,YAAY;IAkBpB,oBAAoB,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC;IAkB5C,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAOpC,gBAAgB,CACd,OAAO,GAAE,MAAM;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAG5C;IAYJ,iBAAiB;IAQjB,OAAO,CAAC,MAAM;IA2Bd,iBAAiB,CAAC,EAAE,EAAE,MAAM,IAAI;IAIhC,MAAM,CAAC,GAAG,EAAE,MAAM;IAIlB,SAAS;IAQT,WAAW,CAAC,YAAY,CAAC,EAAE,MAAM,IAAI,EAAE,WAAW,CAAC,EAAE,MAAM,IAAI;CA6BhE"}