@siredvin/primeui-ts 0.1.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.
Files changed (3) hide show
  1. package/index.d.ts +392 -0
  2. package/index.lua +1076 -0
  3. package/package.json +39 -0
package/index.d.ts ADDED
@@ -0,0 +1,392 @@
1
+ // Uses @jackmacwindows/cc-types types for CC objects.
2
+
3
+ export type BlitImageFrame = [string, string, string][] & {
4
+ duration?: number;
5
+ palette?: ([number] | [number, number, number])[];
6
+ };
7
+ export type BlitImage = BlitImageFrame[] & {
8
+ version: string;
9
+ animated: boolean;
10
+ author?: string;
11
+ title?: string;
12
+ description?: string;
13
+ creator?: string;
14
+ date?: string;
15
+ width?: number;
16
+ height?: number;
17
+ secondsPerFrame?: number;
18
+ palette?: ([number] | [number, number, number])[];
19
+ };
20
+
21
+ /** @noSelf **/
22
+ export declare namespace PrimeUI {
23
+ /**
24
+ * Adds a task to run in the main loop.
25
+ * @param func The function to run, usually an `os.pullEvent` loop
26
+ */
27
+ function addTask(func: () => void): void;
28
+
29
+ /**
30
+ * Sends the provided arguments to the run loop, where they will be returned.
31
+ * @param args The parameters to send
32
+ */
33
+ function resolve(...args: any[]): never;
34
+
35
+ /**
36
+ * Clears the screen and resets all components. Do not use any previously
37
+ * created components after calling this function.
38
+ */
39
+ function clear(): void;
40
+
41
+ /**
42
+ * Sets or clears the window that holds where the cursor should be.
43
+ * @param win The window to set as the active window
44
+ */
45
+ function setCursorWindow(win: Window | null | undefined): void;
46
+
47
+ /**
48
+ * Gets the absolute position of a coordinate relative to a window.
49
+ * @param win The window to check
50
+ * @param x The relative X position of the point
51
+ * @param y The relative Y position of the point
52
+ * @return The absolute X and Y position of the window
53
+ */
54
+ function getWindowPos(
55
+ win: ITerminal,
56
+ x: number,
57
+ y: number
58
+ ): LuaMultiReturn<[number, number]>;
59
+
60
+ /**
61
+ * Runs the main loop, returning information on an action.
62
+ * @return The result of the coroutine that exited
63
+ */
64
+ function run(): LuaMultiReturn<any[]>;
65
+
66
+ /**
67
+ * Draws a thin border around a screen region.
68
+ * @param win The window to draw on
69
+ * @param x The X coordinate of the inside of the box
70
+ * @param y The Y coordinate of the inside of the box
71
+ * @param width The width of the inner box
72
+ * @param height The height of the inner box
73
+ * @param fgColor The color of the border (defaults to white)
74
+ * @param bgColor The color of the background (defaults to black)
75
+ */
76
+ function borderBox(
77
+ win: ITerminal,
78
+ x: number,
79
+ y: number,
80
+ width: number,
81
+ height: number,
82
+ fgColor?: Color,
83
+ bgColor?: Color
84
+ ): void;
85
+
86
+ /**
87
+ * Creates a clickable button on screen with text.
88
+ * @param win The window to draw on
89
+ * @param x The X position of the button
90
+ * @param y The Y position of the button
91
+ * @param text The text to draw on the button
92
+ * @param action A function to call when clicked, or a string to send with a `run` event
93
+ * @param fgColor The color of the button text (defaults to white)
94
+ * @param bgColor The color of the button (defaults to light gray)
95
+ * @param clickedColor The color of the button when clicked (defaults to gray)
96
+ */
97
+ function button(
98
+ win: ITerminal,
99
+ x: number,
100
+ y: number,
101
+ text: string,
102
+ action: (() => void) | string,
103
+ fgColor?: Color,
104
+ bgColor?: Color,
105
+ clickedColor?: Color
106
+ ): void;
107
+
108
+ /**
109
+ * Draws a line of text at a position.
110
+ * @param win The window to draw on
111
+ * @param x The X position of the left side of the box
112
+ * @param y The Y position of the box
113
+ * @param width The width of the box to draw in
114
+ * @param text The text to draw
115
+ * @param fgColor The color of the text (defaults to white)
116
+ * @param bgColor The color of the background (defaults to black)
117
+ */
118
+ function centerLabel(
119
+ win: ITerminal,
120
+ x: number,
121
+ y: number,
122
+ width: number,
123
+ text: string,
124
+ fgColor?: Color,
125
+ bgColor?: Color
126
+ ): void;
127
+
128
+ /**
129
+ * Creates a list of entries with toggleable check boxes.
130
+ * @param win The window to draw on
131
+ * @param x The X coordinate of the inside of the box
132
+ * @param y The Y coordinate of the inside of the box
133
+ * @param width The width of the inner box
134
+ * @param height The height of the inner box
135
+ * @param selections A list of entries to show, where the value is whether the item is pre-selected (or `"R"` for required/forced selected)
136
+ * @param action A function or `run` event that's called when a selection is made
137
+ * @param fgColor The color of the text (defaults to white)
138
+ * @param bgColor The color of the background (defaults to black)
139
+ */
140
+ function checkSelectionBox(
141
+ win: ITerminal,
142
+ x: number,
143
+ y: number,
144
+ width: number,
145
+ height: number,
146
+ selections: { [key: string]: boolean | "R" },
147
+ action: (() => void) | string,
148
+ fgColor?: Color,
149
+ bgColor?: Color
150
+ ): void;
151
+
152
+ /**
153
+ * Draws a BIMG-formatted image to the screen. This does not support transparency,
154
+ * and does not handle animation on its own (but the index parameter may be
155
+ * used by apps to implement animation).
156
+ * @param win The window to draw on
157
+ * @param x The X position of the top left corner of the image
158
+ * @param y The Y position of the top left corner of the image
159
+ * @param data The path to the image to load, or the image data itself
160
+ * @param index The index of the frame to draw (defaults to 1)
161
+ * @param setPalette Whether to set the palette if the image contains one (defaults to true)
162
+ */
163
+ function drawImage(
164
+ win: ITerminal,
165
+ x: number,
166
+ y: number,
167
+ data: string | BlitImage,
168
+ index?: number,
169
+ setPalette?: boolean
170
+ ): void;
171
+
172
+ /** Draws a block of text inside a window with word wrapping, optionally resizing the window to fit.
173
+ * @param win The window to draw in
174
+ * @param text The text to draw
175
+ * @param resizeToFit Whether to resize the window to fit the text (defaults to false). This is useful for scroll boxes.
176
+ * @param fgColor The color of the text (defaults to white)
177
+ * @param bgColor The color of the background (defaults to black)
178
+ * @return The total number of lines drawn
179
+ */
180
+ function drawText(
181
+ win: ITerminal,
182
+ text: string,
183
+ resizeToFit?: boolean,
184
+ fgColor?: Color,
185
+ bgColor?: Color
186
+ ): number;
187
+
188
+ /**
189
+ * Draws a horizontal line at a position with the specified width.
190
+ * @param win The window to draw on
191
+ * @param x The X position of the left side of the line
192
+ * @param y The Y position of the line
193
+ * @param width The width/length of the line
194
+ * @param fgColor The color of the line (defaults to white)
195
+ * @param bgColor The color of the background (defaults to black)
196
+ */
197
+ function horizontalLine(
198
+ win: ITerminal,
199
+ x: number,
200
+ y: number,
201
+ width: number,
202
+ fgColor?: Color,
203
+ bgColor?: Color
204
+ ): void;
205
+
206
+ /**
207
+ * Creates a text input box.
208
+ * @param win window The window to draw on
209
+ * @param x number The X position of the left side of the box
210
+ * @param y number The Y position of the box
211
+ * @param width number The width/length of the box
212
+ * @param action function|string A function or `run` event to call when the enter key is pressed
213
+ * @param fgColor color|nil The color of the text (defaults to white)
214
+ * @param bgColor color|nil The color of the background (defaults to black)
215
+ * @param replacement string|nil A character to replace typed characters with
216
+ * @param history string[]|nil A list of previous entries to provide
217
+ * @param completion function|nil A function to call to provide completion
218
+ * @param default string|nil A string to return if the box is empty
219
+ */
220
+ function inputBox(
221
+ win: ITerminal,
222
+ x: number,
223
+ y: number,
224
+ width: number,
225
+ action: (() => void) | string,
226
+ fgColor?: Color,
227
+ bgColor?: Color,
228
+ replacement?: string,
229
+ history?: string[],
230
+ completion?: (partial: string) => string[],
231
+ defaultString?: string
232
+ ): void;
233
+
234
+ /**
235
+ * Runs a function or action repeatedly after a specified time period until canceled.
236
+ * If a function is passed as an action, it may return a number to change the
237
+ * period, or `false` to stop it.
238
+ * @param time The amount of time to wait for each time, in seconds
239
+ * @param action The function to call when the timer completes, or a `run` event to send
240
+ * @return A function to cancel the timer
241
+ */
242
+ function interval(
243
+ time: number,
244
+ action: (() => number | false | null | undefined | void) | string
245
+ ): () => void;
246
+
247
+ /**
248
+ * Adds an action to trigger when a key is pressed.
249
+ * @param key The key to trigger on, from `keys.*`
250
+ * @param action A function to call when clicked, or a string to use as a key for a `run` return event
251
+ */
252
+ function keyAction(key: Key, action: (() => void) | string): void;
253
+
254
+ /**
255
+ * Adds an action to trigger when a key is pressed with modifier keys.
256
+ * @param key The key to trigger on, from `keys.*`
257
+ * @param withCtrl Whether Ctrl is required
258
+ * @param withAlt Whether Alt is required
259
+ * @param withShift Whether Shift is required
260
+ * @param action A function to call when clicked, or a string to use as a key for a `run` return event
261
+ */
262
+ function keyCombo(
263
+ key: Key,
264
+ withCtrl: boolean,
265
+ withAlt: boolean,
266
+ withShift: boolean,
267
+ action: (() => void) | string
268
+ ): void;
269
+
270
+ /**
271
+ * Draws a line of text at a position.
272
+ * @param win The window to draw on
273
+ * @param x The X position of the left side of the text
274
+ * @param y The Y position of the text
275
+ * @param text The text to draw
276
+ * @param fgColor The color of the text (defaults to white)
277
+ * @param bgColor The color of the background (defaults to black)
278
+ */
279
+ function label(
280
+ win: ITerminal,
281
+ x: number,
282
+ y: number,
283
+ text: string,
284
+ fgColor?: Color,
285
+ bgColor?: Color
286
+ ): void;
287
+
288
+ /**
289
+ * Creates a progress bar, which can be updated by calling the returned function.
290
+ * @param win The window to draw on
291
+ * @param x The X position of the left side of the bar
292
+ * @param y The Y position of the bar
293
+ * @param width The width of the bar
294
+ * @param fgColor The color of the activated part of the bar (defaults to white)
295
+ * @param bgColor The color of the inactive part of the bar (defaults to black)
296
+ * @param useShade Whether to use shaded areas for the inactive part (defaults to false)
297
+ * @return A function to call to update the progress of the bar, taking a number from 0.0 to 1.0
298
+ */
299
+ function progressBar(
300
+ win: ITerminal,
301
+ x: number,
302
+ y: number,
303
+ width: number,
304
+ fgColor?: Color,
305
+ bgColor?: Color,
306
+ useShade?: boolean
307
+ ): (progress: number) => void;
308
+
309
+ /**
310
+ * Creates a scrollable window, which allows drawing large content in a small area.
311
+ * @param win The parent window of the scroll box
312
+ * @param x The X position of the box
313
+ * @param y The Y position of the box
314
+ * @param width The width of the box
315
+ * @param height The height of the outer box
316
+ * @param innerHeight The height of the inner scroll area
317
+ * @param allowArrowKeys Whether to allow arrow keys to scroll the box (defaults to true)
318
+ * @param showScrollIndicators Whether to show arrow indicators on the right side when scrolling is available, which reduces the inner width by 1 (defaults to false)
319
+ * @param fgColor The color of scroll indicators (defaults to white)
320
+ * @param bgColor The color of the background (defaults to black)
321
+ * @return The inner window to draw inside
322
+ */
323
+ function scrollBox(
324
+ win: ITerminal,
325
+ x: number,
326
+ y: number,
327
+ width: number,
328
+ height: number,
329
+ innerHeight: number,
330
+ allowArrowKeys?: boolean,
331
+ showScrollIndicators?: boolean,
332
+ fgColor?: Color,
333
+ bgColor?: Color
334
+ ): Window;
335
+
336
+ /**
337
+ * Creates a list of entries that can each be selected.
338
+ * @param win The window to draw on
339
+ * @param x The X coordinate of the inside of the box
340
+ * @param y The Y coordinate of the inside of the box
341
+ * @param width The width of the inner box
342
+ * @param height The height of the inner box
343
+ * @param entries A list of entries to show, where the value is whether the item is pre-selected (or `"R"` for required/forced selected)
344
+ * @param action A function or `run` event that's called when a selection is made
345
+ * @param selectChangeAction A function or `run` event that's called when the current selection is changed
346
+ * @param fgColor The color of the text (defaults to white)
347
+ * @param bgColor The color of the background (defaults to black)
348
+ */
349
+ function selectionBox(
350
+ win: ITerminal,
351
+ x: number,
352
+ y: number,
353
+ width: number,
354
+ height: number,
355
+ entries: string[],
356
+ action: (() => void) | string,
357
+ selectChangeAction?: (() => void) | string,
358
+ fgColor?: Color,
359
+ bgColor?: Color
360
+ ): void;
361
+
362
+ /**
363
+ * Creates a text box that wraps text and can have its text modified later.
364
+ * @param win The parent window of the text box
365
+ * @param x The X position of the box
366
+ * @param y The Y position of the box
367
+ * @param width The width of the box
368
+ * @param height The height of the box
369
+ * @param text The initial text to draw
370
+ * @param fgColor The color of the text (defaults to white)
371
+ * @param bgColor The color of the background (defaults to black)
372
+ * @return A function to redraw the window with new contents
373
+ */
374
+ function textBox(
375
+ win: ITerminal,
376
+ x: number,
377
+ y: number,
378
+ width: number,
379
+ height: number,
380
+ text: string,
381
+ fgColor?: Color,
382
+ bgColor?: Color
383
+ ): (text: string) => void;
384
+
385
+ /**
386
+ * Runs a function or action after the specified time period, with optional canceling.
387
+ * @param time The amount of time to wait for, in seconds
388
+ * @param action The function to call when the timer completes, or a `run` event to send
389
+ * @returns A function to cancel the timer
390
+ */
391
+ function timeout(time: number, action: (() => void) | string): () => void;
392
+ }