@nan0web/ui 1.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.
- package/.datasets/README.dataset.jsonl +12 -0
- package/.editorconfig +20 -0
- package/CONTRIBUTING.md +42 -0
- package/LICENSE +15 -0
- package/README.md +238 -0
- package/docs/uk/README.md +240 -0
- package/package.json +64 -0
- package/playground/User.js +52 -0
- package/playground/currency.exchange.js +48 -0
- package/playground/i18n/index.js +21 -0
- package/playground/i18n/uk.js +53 -0
- package/playground/language.form.js +25 -0
- package/playground/main.js +72 -0
- package/playground/registration.form.js +58 -0
- package/playground/topup.telephone.js +62 -0
- package/src/App/Command/Options.js +78 -0
- package/src/App/Command/index.js +9 -0
- package/src/App/Core/CoreApp.js +129 -0
- package/src/App/Core/UI.js +116 -0
- package/src/App/Core/Widget.js +67 -0
- package/src/App/Core/index.js +11 -0
- package/src/App/Scenario.js +45 -0
- package/src/App/User/Command/Message.js +44 -0
- package/src/App/User/Command/Options.js +48 -0
- package/src/App/User/Command/index.js +11 -0
- package/src/App/User/UserApp.js +73 -0
- package/src/App/User/UserApp.test.js +56 -0
- package/src/App/User/UserUI.js +20 -0
- package/src/App/User/UserUI.test.js +51 -0
- package/src/App/User/index.js +15 -0
- package/src/App/index.js +22 -0
- package/src/Component/Process/Input.js +70 -0
- package/src/Component/Process/Process.js +26 -0
- package/src/Component/Process/index.js +5 -0
- package/src/Component/Welcome/Input.js +50 -0
- package/src/Component/Welcome/Welcome.js +26 -0
- package/src/Component/Welcome/index.js +5 -0
- package/src/Component/index.js +9 -0
- package/src/Frame/Frame.js +591 -0
- package/src/Frame/Frame.test.js +429 -0
- package/src/Frame/Props.js +102 -0
- package/src/Locale.js +119 -0
- package/src/Model/User/User.js +56 -0
- package/src/Model/index.js +7 -0
- package/src/README.md.js +371 -0
- package/src/StdIn.js +111 -0
- package/src/StdOut.js +99 -0
- package/src/View/RenderOptions.js +48 -0
- package/src/View/View.js +289 -0
- package/src/View/View.test.js +77 -0
- package/src/core/Form/Form.js +289 -0
- package/src/core/Form/Form.test.js +116 -0
- package/src/core/Form/Input.js +116 -0
- package/src/core/Form/Input.test.js +58 -0
- package/src/core/Form/Message.js +86 -0
- package/src/core/Form/Message.test.js +54 -0
- package/src/core/Form/index.js +11 -0
- package/src/core/InputAdapter.js +41 -0
- package/src/core/InputAdapter.test.js +35 -0
- package/src/core/Message/InputMessage.js +119 -0
- package/src/core/Message/InputMessage.test.js +45 -0
- package/src/core/Message/Message.js +77 -0
- package/src/core/Message/Message.test.js +58 -0
- package/src/core/Message/OutputMessage.js +143 -0
- package/src/core/Message/OutputMessage.test.js +61 -0
- package/src/core/Message/index.js +7 -0
- package/src/core/OutputAdapter.js +50 -0
- package/src/core/OutputAdapter.test.js +35 -0
- package/src/core/Stream.js +71 -0
- package/src/core/Stream.test.js +78 -0
- package/src/core/StreamEntry.js +59 -0
- package/src/core/index.js +13 -0
- package/src/functions.js +38 -0
- package/src/index.js +34 -0
- package/src/index.test.js +14 -0
- package/src/models/SimpleUser.js +18 -0
- package/stories/App/AppView.js +15 -0
- package/stories/App/AppView.test.js +22 -0
- package/stories/App/RenderOptions.js +14 -0
- package/stories/nodejs/interface.test.js +27 -0
- package/system.md +187 -0
- package/system1.md +137 -0
- package/task.md +181 -0
- package/tsconfig.json +23 -0
- package/types/App/Command/Options.d.ts +46 -0
- package/types/App/Command/index.d.ts +8 -0
- package/types/App/Core/CoreApp.d.ts +70 -0
- package/types/App/Core/UI.d.ts +49 -0
- package/types/App/Core/Widget.d.ts +40 -0
- package/types/App/Core/index.d.ts +10 -0
- package/types/App/Scenario.d.ts +26 -0
- package/types/App/User/Command/Message.d.ts +30 -0
- package/types/App/User/Command/Options.d.ts +27 -0
- package/types/App/User/Command/index.d.ts +8 -0
- package/types/App/User/UserApp.d.ts +31 -0
- package/types/App/User/UserUI.d.ts +18 -0
- package/types/App/User/index.d.ts +12 -0
- package/types/App/index.d.ts +14 -0
- package/types/Component/Process/Input.d.ts +48 -0
- package/types/Component/Process/Process.d.ts +13 -0
- package/types/Component/Process/index.d.ts +4 -0
- package/types/Component/Welcome/Input.d.ts +34 -0
- package/types/Component/Welcome/Welcome.d.ts +13 -0
- package/types/Component/Welcome/index.d.ts +4 -0
- package/types/Component/index.d.ts +8 -0
- package/types/Frame/Frame.d.ts +186 -0
- package/types/Frame/Props.d.ts +77 -0
- package/types/Locale.d.ts +55 -0
- package/types/Model/User/User.d.ts +36 -0
- package/types/Model/index.d.ts +6 -0
- package/types/StdIn.d.ts +62 -0
- package/types/StdOut.d.ts +52 -0
- package/types/View/RenderOptions.d.ts +29 -0
- package/types/View/View.d.ts +115 -0
- package/types/core/Form/Form.d.ts +123 -0
- package/types/core/Form/Input.d.ts +69 -0
- package/types/core/Form/Message.d.ts +28 -0
- package/types/core/Form/index.d.ts +5 -0
- package/types/core/InputAdapter.d.ts +28 -0
- package/types/core/Message/InputMessage.d.ts +71 -0
- package/types/core/Message/Message.d.ts +50 -0
- package/types/core/Message/OutputMessage.d.ts +53 -0
- package/types/core/Message/index.d.ts +5 -0
- package/types/core/OutputAdapter.d.ts +33 -0
- package/types/core/Stream.d.ts +27 -0
- package/types/core/StreamEntry.d.ts +45 -0
- package/types/core/index.d.ts +9 -0
- package/types/functions.d.ts +3 -0
- package/types/index.d.ts +20 -0
- package/types/models/SimpleUser.d.ts +21 -0
- package/vitest.config.js +26 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
export class FrameRenderMethod {
|
|
2
|
+
static APPEND: string;
|
|
3
|
+
static REPLACE: string;
|
|
4
|
+
static VISIBLE: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* @link https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 - ANSI escape codes
|
|
8
|
+
*/
|
|
9
|
+
export default class Frame {
|
|
10
|
+
/** @type {typeof FrameRenderMethod} */
|
|
11
|
+
static RenderMethod: typeof FrameRenderMethod;
|
|
12
|
+
static Props: typeof FrameProps;
|
|
13
|
+
/** @type {string} End of line */
|
|
14
|
+
static EOL: string;
|
|
15
|
+
/** @type {string} Beginning of line */
|
|
16
|
+
static BOL: string;
|
|
17
|
+
/** @type {string} Beginning of frame */
|
|
18
|
+
static BOF: string;
|
|
19
|
+
/** @type {string} Hide cursor */
|
|
20
|
+
static HIDE_CURSOR: string;
|
|
21
|
+
/** @type {string} Show cursor */
|
|
22
|
+
static SHOW_CURSOR: string;
|
|
23
|
+
/** @type {string} Tab */
|
|
24
|
+
static TAB: string;
|
|
25
|
+
/** @type {string} Bold */
|
|
26
|
+
static BOLD: string;
|
|
27
|
+
/** @type {string} Italic */
|
|
28
|
+
static ITALIC: string;
|
|
29
|
+
/** @type {string} Underline */
|
|
30
|
+
static UNDERLINE: string;
|
|
31
|
+
/** @type {string} Strikethrough */
|
|
32
|
+
static STRIKETHROUGH: string;
|
|
33
|
+
/** @type {string} Reset */
|
|
34
|
+
static RESET: string;
|
|
35
|
+
/** @type {string} Clear line */
|
|
36
|
+
static CLEAR_LINE: string;
|
|
37
|
+
/**
|
|
38
|
+
* Check if a value can be used to create a Frame instance.
|
|
39
|
+
* @param {*} value - Value to check.
|
|
40
|
+
* @returns {boolean} True if the value is valid for Frame creation.
|
|
41
|
+
*/
|
|
42
|
+
static is(value: any): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Create a Frame instance from input.
|
|
45
|
+
* @param {*} input - Input value to convert.
|
|
46
|
+
* @returns {Frame} A new Frame instance.
|
|
47
|
+
*/
|
|
48
|
+
static from(input: any): Frame;
|
|
49
|
+
/**
|
|
50
|
+
* Create a function to space columns based on options.
|
|
51
|
+
* @param {object} options - Spacing options.
|
|
52
|
+
* @param {number[]} [options.cols=[]] - Widths of the columns.
|
|
53
|
+
* @param {number} [options.padding=1] - Padding between columns.
|
|
54
|
+
* @param {string[]} [options.aligns=[]] - Alignment for each column ('l' or 'r').
|
|
55
|
+
* @returns {Function} Function that spaces a row.
|
|
56
|
+
*/
|
|
57
|
+
static spaces(options?: {
|
|
58
|
+
cols?: number[] | undefined;
|
|
59
|
+
padding?: number | undefined;
|
|
60
|
+
aligns?: string[] | undefined;
|
|
61
|
+
}): Function;
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @param {Array} arr
|
|
65
|
+
* @returns {(v) => number[]}
|
|
66
|
+
*/
|
|
67
|
+
static weight(arr: any[]): (v: any) => number[];
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
* @param {object} options
|
|
71
|
+
* @param {Function} [options.fn=(fn = v => v)] - Function to calculate weight.
|
|
72
|
+
* @param {number[]} [options.cols=[]] - Widths of the columns.
|
|
73
|
+
* @param {number} [options.padding=1] - The padding between columns.
|
|
74
|
+
* @param {string[]} [options.aligns=[]] - The column aligns: l, r
|
|
75
|
+
* @returns {(arr: []) => string[][]}
|
|
76
|
+
*/
|
|
77
|
+
static table(options?: {
|
|
78
|
+
fn?: Function | undefined;
|
|
79
|
+
cols?: number[] | undefined;
|
|
80
|
+
padding?: number | undefined;
|
|
81
|
+
aligns?: string[] | undefined;
|
|
82
|
+
}): (arr: []) => string[][];
|
|
83
|
+
/**
|
|
84
|
+
* Move cursor up by specified lines.
|
|
85
|
+
* @param {number} [lines=1] - Number of lines to move up.
|
|
86
|
+
* @returns {string} ANSI escape code for cursor movement.
|
|
87
|
+
*/
|
|
88
|
+
static cursorUp(lines?: number | undefined): string;
|
|
89
|
+
/**
|
|
90
|
+
* Move cursor down by specified lines.
|
|
91
|
+
* @param {number} [lines=1] - Number of lines to move down.
|
|
92
|
+
* @returns {string} ANSI escape code for cursor movement.
|
|
93
|
+
*/
|
|
94
|
+
static cursorDown(lines?: number | undefined): string;
|
|
95
|
+
/**
|
|
96
|
+
* Clear the current line.
|
|
97
|
+
* @param {string} [str="\r"] - String to append after clearing.
|
|
98
|
+
* @returns {string} ANSI escape code for line clearing followed by the string.
|
|
99
|
+
*/
|
|
100
|
+
static clearLine(str?: string | undefined): string;
|
|
101
|
+
/**
|
|
102
|
+
* Clear the entire screen.
|
|
103
|
+
* @returns {string} ANSI escape codes for screen clearing.
|
|
104
|
+
*/
|
|
105
|
+
static clearScreen(): string;
|
|
106
|
+
/**
|
|
107
|
+
* @param {object} [input]
|
|
108
|
+
* @param {string[]|string[][]} [input.value]
|
|
109
|
+
* @param {number} [input.width]
|
|
110
|
+
* @param {number} [input.height]
|
|
111
|
+
* @param {string} [input.imprint]
|
|
112
|
+
* @param {string} [input.renderMethod]
|
|
113
|
+
* @param {FrameProps} [input.defaultProps]
|
|
114
|
+
*/
|
|
115
|
+
constructor(input?: {
|
|
116
|
+
value?: string[] | string[][] | undefined;
|
|
117
|
+
width?: number | undefined;
|
|
118
|
+
height?: number | undefined;
|
|
119
|
+
imprint?: string | undefined;
|
|
120
|
+
renderMethod?: string | undefined;
|
|
121
|
+
defaultProps?: FrameProps | undefined;
|
|
122
|
+
} | undefined);
|
|
123
|
+
/**
|
|
124
|
+
* @example
|
|
125
|
+
* ```js
|
|
126
|
+
* new Frame([
|
|
127
|
+
* ["Hello", "World"],
|
|
128
|
+
* [["Hello", { color: "red", bgColor: "#009" }], "World"],
|
|
129
|
+
* ["<b i fg=#900>Hello</b>", "<i>World</i>"],
|
|
130
|
+
* ])
|
|
131
|
+
* ```
|
|
132
|
+
* @type {string[][]|any[][]}
|
|
133
|
+
*/
|
|
134
|
+
value: string[][] | any[][];
|
|
135
|
+
/** @type {FrameProps} */
|
|
136
|
+
defaultProps: FrameProps;
|
|
137
|
+
/** @type {string} */
|
|
138
|
+
imprint: string;
|
|
139
|
+
/** @type {number} */
|
|
140
|
+
width: number;
|
|
141
|
+
/** @type {number} */
|
|
142
|
+
height: number;
|
|
143
|
+
/** @type {string} */
|
|
144
|
+
renderMethod: string;
|
|
145
|
+
/**
|
|
146
|
+
* Get whether the frame is empty.
|
|
147
|
+
* @returns {boolean} True if the frame has no content.
|
|
148
|
+
*/
|
|
149
|
+
get empty(): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Calculate the visual width of a string.
|
|
152
|
+
* @param {string} str
|
|
153
|
+
* @returns {number} The visual width of the string.
|
|
154
|
+
*/
|
|
155
|
+
lengthOf(str: string): number;
|
|
156
|
+
/**
|
|
157
|
+
* Render the frame into a string representation.
|
|
158
|
+
* @param {object} [options]
|
|
159
|
+
* @param {string} [options.method] - Render method to use.
|
|
160
|
+
* @param {FrameProps} [options.props] - Properties to apply during rendering.
|
|
161
|
+
* @returns {string} The rendered frame as a string.
|
|
162
|
+
*/
|
|
163
|
+
render(options?: {
|
|
164
|
+
method?: string | undefined;
|
|
165
|
+
props?: FrameProps | undefined;
|
|
166
|
+
} | undefined): string;
|
|
167
|
+
/**
|
|
168
|
+
* Convert the frame to its string representation.
|
|
169
|
+
* @returns {string} The frame's imprint.
|
|
170
|
+
*/
|
|
171
|
+
toString(): string;
|
|
172
|
+
/**
|
|
173
|
+
* Transform each cell in the frame using a function.
|
|
174
|
+
* @param {Function} fn - Function to apply to each cell.
|
|
175
|
+
* @returns {Frame} A new Frame with transformed values.
|
|
176
|
+
*/
|
|
177
|
+
transform(fn: Function): Frame;
|
|
178
|
+
/**
|
|
179
|
+
* Set the window size for the frame.
|
|
180
|
+
* @param {number} width - The width of the window.
|
|
181
|
+
* @param {number} height - The height of the window.
|
|
182
|
+
*/
|
|
183
|
+
setWindowSize(width: number, height: number): void;
|
|
184
|
+
#private;
|
|
185
|
+
}
|
|
186
|
+
import FrameProps from "./Props.js";
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export default FrameProps;
|
|
2
|
+
/**
|
|
3
|
+
* Represents default styling properties for Frame rendering.
|
|
4
|
+
* Every tag must be a separate value in the array of rows/columns.
|
|
5
|
+
* If you want to apply the same props to multiple values, you can use an array of values.
|
|
6
|
+
* If you want to apply different props to multiple values, you can use an object with the props.
|
|
7
|
+
* If you want to apply props to a single value, you can use a string with the props in XML format.
|
|
8
|
+
* Parser checks every atom for its beginning and end and if it's a tag, it applies the props to the value.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const defaultProps = new FrameProps({
|
|
12
|
+
* color: "red",
|
|
13
|
+
* bgColor: "blue",
|
|
14
|
+
* bold: true,
|
|
15
|
+
* italic: true,
|
|
16
|
+
* underline: true,
|
|
17
|
+
* strikethrough: true,
|
|
18
|
+
* })
|
|
19
|
+
* or by aliases:
|
|
20
|
+
* const defaultProps = new FrameProps({
|
|
21
|
+
* fg: "red",
|
|
22
|
+
* bg: "blue",
|
|
23
|
+
* b: true,
|
|
24
|
+
* i: true,
|
|
25
|
+
* u: true,
|
|
26
|
+
* s: true,
|
|
27
|
+
* })
|
|
28
|
+
* from an array of strings:
|
|
29
|
+
* const rows = [
|
|
30
|
+
* ["Hello", "World"],
|
|
31
|
+
* ["<fg=red>Hello</>", "<bg=blue>World</>"],
|
|
32
|
+
* ["<b>Hello</b>", "<i>World</i>"],
|
|
33
|
+
* ["<u>Hello</u>", "<s>World</s>"],
|
|
34
|
+
* ["<b fg=red>Hello</b>", "<i bg=blue>World</i>"],
|
|
35
|
+
* ["<b i>Hello</b>", "<i b>World</i>"],
|
|
36
|
+
* ["<b i s>Some</b>", ["thing", {b: true, i: true, s: true}]],
|
|
37
|
+
* [["Hello", "World", {b: true}]],
|
|
38
|
+
* ]
|
|
39
|
+
* const defaultProps = new FrameProps(rows)
|
|
40
|
+
*/
|
|
41
|
+
declare class FrameProps extends ObjectWithAlias {
|
|
42
|
+
/**
|
|
43
|
+
* Property aliases for shorthand notation.
|
|
44
|
+
* @type {Record<string, string>}
|
|
45
|
+
*/
|
|
46
|
+
static ALIAS: Record<string, string>;
|
|
47
|
+
/**
|
|
48
|
+
* @param {object} props - Frame properties
|
|
49
|
+
* @param {string} [props.color=""] - Text color
|
|
50
|
+
* @param {string} [props.bgColor=""] - Background color
|
|
51
|
+
* @param {boolean} [props.bold=false] - Bold text flag
|
|
52
|
+
* @param {boolean} [props.italic=false] - Italic text flag
|
|
53
|
+
* @param {boolean} [props.underline=false] - Underline text flag
|
|
54
|
+
* @param {boolean} [props.strikethrough=false] - Strikethrough text flag
|
|
55
|
+
*/
|
|
56
|
+
constructor(props?: {
|
|
57
|
+
color?: string | undefined;
|
|
58
|
+
bgColor?: string | undefined;
|
|
59
|
+
bold?: boolean | undefined;
|
|
60
|
+
italic?: boolean | undefined;
|
|
61
|
+
underline?: boolean | undefined;
|
|
62
|
+
strikethrough?: boolean | undefined;
|
|
63
|
+
});
|
|
64
|
+
/** @type {string} Text color */
|
|
65
|
+
color: string;
|
|
66
|
+
/** @type {string} Background color */
|
|
67
|
+
bgColor: string;
|
|
68
|
+
/** @type {boolean} Bold text flag */
|
|
69
|
+
bold: boolean;
|
|
70
|
+
/** @type {boolean} Italic text flag */
|
|
71
|
+
italic: boolean;
|
|
72
|
+
/** @type {boolean} Underline text flag */
|
|
73
|
+
underline: boolean;
|
|
74
|
+
/** @type {boolean} Strikethrough text flag */
|
|
75
|
+
strikethrough: boolean;
|
|
76
|
+
}
|
|
77
|
+
import { ObjectWithAlias } from "@nan0web/types";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles locale-specific formatting for different data types.
|
|
3
|
+
*/
|
|
4
|
+
export default class Locale {
|
|
5
|
+
/**
|
|
6
|
+
* @param {any} input
|
|
7
|
+
* @returns {Locale}
|
|
8
|
+
*/
|
|
9
|
+
static from(input: any): Locale;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new Locale instance.
|
|
12
|
+
* @param {object} props - Locale properties or all locale string
|
|
13
|
+
* @param {string} [props.lang=""] - Language locale
|
|
14
|
+
* @param {string} [props.collate=""] - Collation locale
|
|
15
|
+
* @param {string} [props.ctype=""] - Character type locale
|
|
16
|
+
* @param {string} [props.messages=""] - Messages locale
|
|
17
|
+
* @param {string} [props.monetary=""] - Monetary locale
|
|
18
|
+
* @param {string} [props.numeric=""] - Numeric locale
|
|
19
|
+
* @param {string} [props.time=""] - Time locale
|
|
20
|
+
* @param {string} [props.all="uk_UA.UTF-8"] - General locale fallback
|
|
21
|
+
*/
|
|
22
|
+
constructor(props?: {
|
|
23
|
+
lang?: string | undefined;
|
|
24
|
+
collate?: string | undefined;
|
|
25
|
+
ctype?: string | undefined;
|
|
26
|
+
messages?: string | undefined;
|
|
27
|
+
monetary?: string | undefined;
|
|
28
|
+
numeric?: string | undefined;
|
|
29
|
+
time?: string | undefined;
|
|
30
|
+
all?: string | undefined;
|
|
31
|
+
});
|
|
32
|
+
/** @type {string} Language locale */
|
|
33
|
+
lang: string;
|
|
34
|
+
/** @type {string} Collation locale */
|
|
35
|
+
collate: string;
|
|
36
|
+
/** @type {string} Character type locale */
|
|
37
|
+
ctype: string;
|
|
38
|
+
/** @type {string} Messages locale */
|
|
39
|
+
messages: string;
|
|
40
|
+
/** @type {string} Monetary locale */
|
|
41
|
+
monetary: string;
|
|
42
|
+
/** @type {string} Numeric locale */
|
|
43
|
+
numeric: string;
|
|
44
|
+
/** @type {string} Time locale */
|
|
45
|
+
time: string;
|
|
46
|
+
/** @type {string} General locale fallback */
|
|
47
|
+
all: string;
|
|
48
|
+
/**
|
|
49
|
+
* Formats values according to locale settings.
|
|
50
|
+
* @param {Function} type - Type constructor (Number, String, etc.)
|
|
51
|
+
* @param {object} options - Formatting options
|
|
52
|
+
* @returns {Function|null} Formatting function or null if unsupported type
|
|
53
|
+
*/
|
|
54
|
+
format(type: Function, options: object): Function | null;
|
|
55
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export default User;
|
|
2
|
+
/**
|
|
3
|
+
* Represents a user with name and email properties.
|
|
4
|
+
*/
|
|
5
|
+
declare class User {
|
|
6
|
+
/**
|
|
7
|
+
* Creates a User instance from the given props.
|
|
8
|
+
* @param {User|object|string} props - The properties to create from
|
|
9
|
+
* @returns {User} A User instance
|
|
10
|
+
*/
|
|
11
|
+
static from(props: User | object | string): User;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new User instance.
|
|
14
|
+
* @param {object} props - User properties or name string
|
|
15
|
+
* @param {string} [props.name=""] - User name
|
|
16
|
+
* @param {string} [props.email=""] - User email
|
|
17
|
+
*/
|
|
18
|
+
constructor(props?: {
|
|
19
|
+
name?: string | undefined;
|
|
20
|
+
email?: string | undefined;
|
|
21
|
+
});
|
|
22
|
+
/** @type {string} User name */
|
|
23
|
+
name: string;
|
|
24
|
+
/** @type {string} User email */
|
|
25
|
+
email: string;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if user data is empty (no name and no email).
|
|
28
|
+
* @returns {boolean} True if both name and email are empty, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
get empty(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Converts user to string representation.
|
|
33
|
+
* @returns {string} User name and email (if exists)
|
|
34
|
+
*/
|
|
35
|
+
toString(): string;
|
|
36
|
+
}
|
package/types/StdIn.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export default StdIn;
|
|
2
|
+
/**
|
|
3
|
+
* Handles standard input stream with message buffering.
|
|
4
|
+
*/
|
|
5
|
+
declare class StdIn extends EventProcessor {
|
|
6
|
+
/** @type {number} Read interval in milliseconds */
|
|
7
|
+
static READ_INTERVAL: number;
|
|
8
|
+
/** @type {string[]} Messages to ignore */
|
|
9
|
+
static IGNORE_MESSAGES: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Creates a StdIn instance from the given input.
|
|
12
|
+
* @param {StdIn|object} input - The input to create from
|
|
13
|
+
* @returns {StdIn} A StdIn instance
|
|
14
|
+
*/
|
|
15
|
+
static from(input: StdIn | object): StdIn;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new StdIn instance.
|
|
18
|
+
* @param {object} props - StdIn properties
|
|
19
|
+
* @param {Processor} [props.processor] - Input processor
|
|
20
|
+
* @param {InputMessage[]} [props.stream=[]] - Initial input stream
|
|
21
|
+
*/
|
|
22
|
+
constructor(props?: {
|
|
23
|
+
processor?: Processor | undefined;
|
|
24
|
+
stream?: InputMessage[] | undefined;
|
|
25
|
+
});
|
|
26
|
+
/** @type {InputMessage[]} Input message buffer */
|
|
27
|
+
stream: InputMessage[];
|
|
28
|
+
/** @type {Processor} Input processor */
|
|
29
|
+
processor: Processor;
|
|
30
|
+
/**
|
|
31
|
+
* Checks if there are messages waiting in the input stream.
|
|
32
|
+
* @returns {boolean} True if waiting messages, false otherwise
|
|
33
|
+
*/
|
|
34
|
+
get waiting(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if the input stream has ended (no messages left).
|
|
37
|
+
* @returns {boolean} True if no messages left, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
get ended(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Reads a message from the input stream.
|
|
42
|
+
* Waits until messages are available if stream is empty.
|
|
43
|
+
* @returns {Promise<InputMessage>} Next input message
|
|
44
|
+
*/
|
|
45
|
+
read(): Promise<InputMessage>;
|
|
46
|
+
/**
|
|
47
|
+
* Writes a message to the input stream.
|
|
48
|
+
* @param {string} message - Message to write
|
|
49
|
+
* @returns {boolean} True if message accepted, False if ignored
|
|
50
|
+
*/
|
|
51
|
+
write(message: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Decodes a message into an InputMessage instance.
|
|
54
|
+
* @param {InputMessage | string[] | any} message - Message to decode
|
|
55
|
+
* @returns {InputMessage} Decoded input message
|
|
56
|
+
*/
|
|
57
|
+
decode(message: InputMessage | string[] | any): InputMessage;
|
|
58
|
+
}
|
|
59
|
+
import EventProcessor from "@nan0web/event/oop";
|
|
60
|
+
import InputMessage from "./core/Message/InputMessage.js";
|
|
61
|
+
declare class Processor extends EventProcessor {
|
|
62
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export default StdOut;
|
|
2
|
+
/**
|
|
3
|
+
* Handles standard output stream with formatting capabilities.
|
|
4
|
+
*/
|
|
5
|
+
declare class StdOut extends EventProcessor {
|
|
6
|
+
/** @type {string} End of line character */
|
|
7
|
+
static EOL: string;
|
|
8
|
+
/** @type {string} Beginning of line character */
|
|
9
|
+
static BOL: string;
|
|
10
|
+
/** @type {string} Reset formatting escape code */
|
|
11
|
+
static RESET: string;
|
|
12
|
+
/** @type {string} Clear screen escape code */
|
|
13
|
+
static CLEAR: string;
|
|
14
|
+
/** @type {object} Color escape codes */
|
|
15
|
+
static COLORS: object;
|
|
16
|
+
/** @type {Record<string, string>} Style escape codes */
|
|
17
|
+
static STYLES: Record<string, string>;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new StdOut instance.
|
|
20
|
+
* @param {object} props - StdOut properties
|
|
21
|
+
* @param {any} [props.processor] - Output processor
|
|
22
|
+
* @param {string[]} [props.stream=[]] - Initial output stream
|
|
23
|
+
* @param {number[]} [props.windowSize=[144, 33]] - Window size [width, height]
|
|
24
|
+
*/
|
|
25
|
+
constructor(props?: {
|
|
26
|
+
processor?: any;
|
|
27
|
+
stream?: string[] | undefined;
|
|
28
|
+
windowSize?: number[] | undefined;
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* @todo define go top by rows constants.
|
|
32
|
+
*/
|
|
33
|
+
/** @type {string[]} Output stream buffer */
|
|
34
|
+
stream: string[];
|
|
35
|
+
/** @type {number[]} Window size [width, height] */
|
|
36
|
+
windowSize: number[];
|
|
37
|
+
/** @type {any} Output processor */
|
|
38
|
+
processor: any;
|
|
39
|
+
/**
|
|
40
|
+
* Writes output to the output stream.
|
|
41
|
+
* Must be overwritten by other apps.
|
|
42
|
+
* @param {any} output - Output to write
|
|
43
|
+
* @param {Function} onError - Error handler callback
|
|
44
|
+
*/
|
|
45
|
+
write(output: any, onError?: Function): void;
|
|
46
|
+
/**
|
|
47
|
+
* Gets the window size.
|
|
48
|
+
* @returns {number[]} Window size [width, height]
|
|
49
|
+
*/
|
|
50
|
+
getWindowSize(): number[];
|
|
51
|
+
}
|
|
52
|
+
import EventProcessor from "@nan0web/event/oop";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export default RenderOptions;
|
|
2
|
+
declare class RenderOptions {
|
|
3
|
+
static DEFAULTS: {
|
|
4
|
+
resizeToView: boolean;
|
|
5
|
+
translateFrame: boolean;
|
|
6
|
+
render: boolean;
|
|
7
|
+
renderMethod: string;
|
|
8
|
+
};
|
|
9
|
+
static from(props?: {}): RenderOptions;
|
|
10
|
+
constructor(props?: {});
|
|
11
|
+
/** @type {boolean} [false] */
|
|
12
|
+
resizeToView: boolean;
|
|
13
|
+
/** @type {boolean} [false] */
|
|
14
|
+
translateFrame: boolean;
|
|
15
|
+
/** @type {boolean} [true] */
|
|
16
|
+
render: boolean;
|
|
17
|
+
/** @type {string} */
|
|
18
|
+
renderMethod: string;
|
|
19
|
+
/** @type {number} */
|
|
20
|
+
width: number;
|
|
21
|
+
/** @type {number} */
|
|
22
|
+
height: number;
|
|
23
|
+
get DEFAULTS(): {
|
|
24
|
+
resizeToView: boolean;
|
|
25
|
+
translateFrame: boolean;
|
|
26
|
+
render: boolean;
|
|
27
|
+
renderMethod: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} ComponentFn
|
|
3
|
+
* @property {string} name
|
|
4
|
+
* @property {(input: InputMessage) => Promise<any>} ask
|
|
5
|
+
* @property {Function} bind
|
|
6
|
+
*/
|
|
7
|
+
export default class View {
|
|
8
|
+
/** @type {typeof RenderOptions} */
|
|
9
|
+
static RenderOptions: typeof RenderOptions;
|
|
10
|
+
/** @type {typeof FrameRenderMethod} */
|
|
11
|
+
static RenderMethod: typeof FrameRenderMethod;
|
|
12
|
+
/**
|
|
13
|
+
* @param {Frame} frame
|
|
14
|
+
* @param {RenderOptions} [options]
|
|
15
|
+
* @returns {Frame}
|
|
16
|
+
*/
|
|
17
|
+
static fixFrame(frame: Frame, options?: RenderOptions | undefined): Frame;
|
|
18
|
+
/**
|
|
19
|
+
* @param {object} [input]
|
|
20
|
+
* @param {StdIn} [input.stdin]
|
|
21
|
+
* @param {StdOut} [input.stdout]
|
|
22
|
+
* @param {number} [input.startedAt]
|
|
23
|
+
* @param {Frame} [input.frame]
|
|
24
|
+
* @param {Locale} [input.locale]
|
|
25
|
+
* @param {Map} [input.vocab]
|
|
26
|
+
* @param {number[]} [input.windowSize]
|
|
27
|
+
* @param {Map<string, ComponentFn>} [input.components]
|
|
28
|
+
* @param {string} [input.renderMethod]
|
|
29
|
+
*/
|
|
30
|
+
constructor(input?: {
|
|
31
|
+
stdin?: StdIn | undefined;
|
|
32
|
+
stdout?: StdOut | undefined;
|
|
33
|
+
startedAt?: number | undefined;
|
|
34
|
+
frame?: Frame | undefined;
|
|
35
|
+
locale?: Locale | undefined;
|
|
36
|
+
vocab?: Map<any, any> | undefined;
|
|
37
|
+
windowSize?: number[] | undefined;
|
|
38
|
+
components?: Map<string, ComponentFn> | undefined;
|
|
39
|
+
renderMethod?: string | undefined;
|
|
40
|
+
} | undefined);
|
|
41
|
+
/** @type {StdIn} */
|
|
42
|
+
stdin: StdIn;
|
|
43
|
+
/** @type {StdOut} */
|
|
44
|
+
stdout: StdOut;
|
|
45
|
+
/** @type {number} */
|
|
46
|
+
startedAt: number;
|
|
47
|
+
/** @type {Frame} */
|
|
48
|
+
frame: Frame;
|
|
49
|
+
/** @type {Locale} */
|
|
50
|
+
locale: Locale;
|
|
51
|
+
/** @type {Map} */
|
|
52
|
+
vocab: Map<any, any>;
|
|
53
|
+
/** @type {number[]} */
|
|
54
|
+
windowSize: number[];
|
|
55
|
+
/** @type {Map<string, ComponentFn>} */
|
|
56
|
+
components: Map<string, ComponentFn>;
|
|
57
|
+
/** @type {string} */
|
|
58
|
+
renderMethod: string;
|
|
59
|
+
get empty(): boolean;
|
|
60
|
+
get RenderMethod(): typeof FrameRenderMethod;
|
|
61
|
+
get RenderOptions(): typeof RenderOptions;
|
|
62
|
+
getWindowSize(): number[];
|
|
63
|
+
setWindowSize(width: any, height: any): void;
|
|
64
|
+
startTimer(): void;
|
|
65
|
+
spent(checkpoint?: number): number;
|
|
66
|
+
/**
|
|
67
|
+
* @param {boolean | number | Function | ComponentFn} [shouldRender=0]
|
|
68
|
+
* @param {RenderOptions} [options]
|
|
69
|
+
* @returns {(value: Frame|string|string[], ...args: any) => Frame}
|
|
70
|
+
*/
|
|
71
|
+
render(shouldRender?: number | boolean | Function | ComponentFn | undefined, options?: RenderOptions | undefined): (value: Frame | string | string[], ...args: any) => Frame;
|
|
72
|
+
clear(shouldRender?: number): Frame;
|
|
73
|
+
progress(shouldRender?: boolean): (value: any) => Frame;
|
|
74
|
+
t(value: any): any;
|
|
75
|
+
debug(...args: any[]): Frame;
|
|
76
|
+
info(...args: any[]): Frame;
|
|
77
|
+
warn(...args: any[]): Frame;
|
|
78
|
+
error(...args: any[]): Frame;
|
|
79
|
+
/**
|
|
80
|
+
* @param {string} name
|
|
81
|
+
* @param {ComponentFn} component
|
|
82
|
+
*/
|
|
83
|
+
register(name: string, component: ComponentFn): void;
|
|
84
|
+
/**
|
|
85
|
+
* @param {string} name
|
|
86
|
+
*/
|
|
87
|
+
unregister(name: string): void;
|
|
88
|
+
/**
|
|
89
|
+
* @param {string} name
|
|
90
|
+
* @returns {boolean}
|
|
91
|
+
*/
|
|
92
|
+
has(name: string): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* @param {string} name
|
|
95
|
+
* @returns {ComponentFn | undefined}
|
|
96
|
+
*/
|
|
97
|
+
get(name: string): ComponentFn | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* @param {InputMessage} input
|
|
100
|
+
* @returns {Promise<InputMessage | null>}
|
|
101
|
+
*/
|
|
102
|
+
ask(input: InputMessage): Promise<InputMessage | null>;
|
|
103
|
+
}
|
|
104
|
+
export type ComponentFn = {
|
|
105
|
+
name: string;
|
|
106
|
+
ask: (input: InputMessage) => Promise<any>;
|
|
107
|
+
bind: Function;
|
|
108
|
+
};
|
|
109
|
+
import StdIn from "../StdIn.js";
|
|
110
|
+
import StdOut from "../StdOut.js";
|
|
111
|
+
import Frame from "../Frame/Frame.js";
|
|
112
|
+
import Locale from "../Locale.js";
|
|
113
|
+
import { FrameRenderMethod } from "../Frame/Frame.js";
|
|
114
|
+
import RenderOptions from "./RenderOptions.js";
|
|
115
|
+
import InputMessage from "../core/Message/InputMessage.js";
|