tinky 1.1.1 → 1.1.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/lib/components/App.js +4 -4
- package/lib/core/tinky.js +2 -2
- package/lib/types/io.d.ts +6 -57
- package/lib/utils/empty-stream.js +0 -3
- package/package.json +1 -1
package/lib/components/App.js
CHANGED
|
@@ -93,16 +93,16 @@ export class App extends PureComponent {
|
|
|
93
93
|
// Ensure raw mode is enabled only once
|
|
94
94
|
if (this.rawModeEnabledCount === 0) {
|
|
95
95
|
stdin.ref?.();
|
|
96
|
-
stdin.setRawMode(true);
|
|
97
|
-
stdin.on("data", this.handleReadable);
|
|
96
|
+
stdin.setRawMode?.(true);
|
|
97
|
+
stdin.on?.("data", this.handleReadable);
|
|
98
98
|
}
|
|
99
99
|
this.rawModeEnabledCount++;
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
102
|
// Disable raw mode only when no components left that are using it
|
|
103
103
|
if (--this.rawModeEnabledCount === 0) {
|
|
104
|
-
stdin.setRawMode(false);
|
|
105
|
-
stdin.off("data", this.handleReadable);
|
|
104
|
+
stdin.setRawMode?.(false);
|
|
105
|
+
stdin.off?.("data", this.handleReadable);
|
|
106
106
|
stdin.unref?.();
|
|
107
107
|
}
|
|
108
108
|
};
|
package/lib/core/tinky.js
CHANGED
|
@@ -113,9 +113,9 @@ export class Tinky {
|
|
|
113
113
|
this.patchConsole();
|
|
114
114
|
}
|
|
115
115
|
if (!this.isCI) {
|
|
116
|
-
options.stdout.on("resize", this.resized);
|
|
116
|
+
options.stdout.on?.("resize", this.resized);
|
|
117
117
|
this.unsubscribeResize = () => {
|
|
118
|
-
options.stdout.off("resize", this.resized);
|
|
118
|
+
options.stdout.off?.("resize", this.resized);
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
121
|
}
|
package/lib/types/io.d.ts
CHANGED
|
@@ -12,22 +12,11 @@
|
|
|
12
12
|
* const myStream: WriteStream = {
|
|
13
13
|
* write: (str) => { console.log(str); return true; },
|
|
14
14
|
* columns: 80,
|
|
15
|
-
* rows: 24
|
|
16
|
-
* on: (event, listener) => { return myStream; },
|
|
17
|
-
* off: (event, listener) => { return myStream; },
|
|
18
|
-
* once: (event, listener) => { return myStream; }
|
|
15
|
+
* rows: 24
|
|
19
16
|
* };
|
|
20
17
|
* ```
|
|
21
18
|
*/
|
|
22
19
|
export interface WriteStream {
|
|
23
|
-
/**
|
|
24
|
-
* Writes data to the stream.
|
|
25
|
-
*
|
|
26
|
-
* @param buffer - The data to write as a Uint8Array.
|
|
27
|
-
* @param cb - Optional callback to be invoked when the write is complete.
|
|
28
|
-
* @returns `true` if the string has been flushed to the kernel buffer.
|
|
29
|
-
*/
|
|
30
|
-
write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean;
|
|
31
20
|
/**
|
|
32
21
|
* Writes a string to the stream.
|
|
33
22
|
*
|
|
@@ -59,7 +48,7 @@ export interface WriteStream {
|
|
|
59
48
|
* @param listener - The callback function.
|
|
60
49
|
* @returns The stream instance for chaining.
|
|
61
50
|
*/
|
|
62
|
-
on(event: string, listener: (...args: unknown[]) => void): this;
|
|
51
|
+
on?(event: string, listener: (...args: unknown[]) => void): this;
|
|
63
52
|
/**
|
|
64
53
|
* Remove an event listener.
|
|
65
54
|
*
|
|
@@ -67,15 +56,7 @@ export interface WriteStream {
|
|
|
67
56
|
* @param listener - The callback function to remove.
|
|
68
57
|
* @returns The stream instance for chaining.
|
|
69
58
|
*/
|
|
70
|
-
off(event: string, listener: (...args: unknown[]) => void): this;
|
|
71
|
-
/**
|
|
72
|
-
* Register a one-time event listener.
|
|
73
|
-
*
|
|
74
|
-
* @param event - The event name.
|
|
75
|
-
* @param listener - The callback function.
|
|
76
|
-
* @returns The stream instance for chaining.
|
|
77
|
-
*/
|
|
78
|
-
once(event: string, listener: (...args: unknown[]) => void): this;
|
|
59
|
+
off?(event: string, listener: (...args: unknown[]) => void): this;
|
|
79
60
|
}
|
|
80
61
|
/**
|
|
81
62
|
* Interface representing a readable stream (e.g., stdin).
|
|
@@ -87,18 +68,6 @@ export interface WriteStream {
|
|
|
87
68
|
* @example
|
|
88
69
|
* ```typescript
|
|
89
70
|
* const myStdin: ReadStream = {
|
|
90
|
-
* setRawMode: (mode) => myStdin,
|
|
91
|
-
* on: (event, listener) => {
|
|
92
|
-
* if (event === 'data') {
|
|
93
|
-
* // simulate input
|
|
94
|
-
* listener('input string');
|
|
95
|
-
* }
|
|
96
|
-
* return myStdin;
|
|
97
|
-
* },
|
|
98
|
-
* off: () => myStdin,
|
|
99
|
-
* once: () => myStdin,
|
|
100
|
-
* pause: () => myStdin,
|
|
101
|
-
* resume: () => myStdin,
|
|
102
71
|
* isTTY: true
|
|
103
72
|
* };
|
|
104
73
|
* ```
|
|
@@ -114,7 +83,7 @@ export interface ReadStream {
|
|
|
114
83
|
* @param mode - `true` to enable raw mode, `false` to disable.
|
|
115
84
|
* @returns The stream instance.
|
|
116
85
|
*/
|
|
117
|
-
setRawMode(mode: boolean): this;
|
|
86
|
+
setRawMode?(mode: boolean): this;
|
|
118
87
|
/**
|
|
119
88
|
* Register an event listener.
|
|
120
89
|
*
|
|
@@ -122,7 +91,7 @@ export interface ReadStream {
|
|
|
122
91
|
* @param listener - The callback function.
|
|
123
92
|
* @returns The stream instance.
|
|
124
93
|
*/
|
|
125
|
-
on(event: string, listener: (...args: unknown[]) => void): this;
|
|
94
|
+
on?(event: string, listener: (...args: unknown[]) => void): this;
|
|
126
95
|
/**
|
|
127
96
|
* Remove an event listener.
|
|
128
97
|
*
|
|
@@ -130,27 +99,7 @@ export interface ReadStream {
|
|
|
130
99
|
* @param listener - The callback function.
|
|
131
100
|
* @returns The stream instance.
|
|
132
101
|
*/
|
|
133
|
-
off(event: string, listener: (...args: unknown[]) => void): this;
|
|
134
|
-
/**
|
|
135
|
-
* Register a one-time event listener.
|
|
136
|
-
*
|
|
137
|
-
* @param event - The event name.
|
|
138
|
-
* @param listener - The callback function.
|
|
139
|
-
* @returns The stream instance.
|
|
140
|
-
*/
|
|
141
|
-
once(event: string, listener: (...args: unknown[]) => void): this;
|
|
142
|
-
/**
|
|
143
|
-
* Pauses the stream.
|
|
144
|
-
*
|
|
145
|
-
* @returns The stream instance.
|
|
146
|
-
*/
|
|
147
|
-
pause(): this;
|
|
148
|
-
/**
|
|
149
|
-
* Resumes the stream.
|
|
150
|
-
*
|
|
151
|
-
* @returns The stream instance.
|
|
152
|
-
*/
|
|
153
|
-
resume(): this;
|
|
102
|
+
off?(event: string, listener: (...args: unknown[]) => void): this;
|
|
154
103
|
/**
|
|
155
104
|
* Indicates whether the stream is a TTY (Terminal).
|
|
156
105
|
*/
|