@teammates/consolonia 0.2.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/README.md +48 -0
- package/dist/__tests__/ansi.test.d.ts +1 -0
- package/dist/__tests__/ansi.test.js +520 -0
- package/dist/__tests__/chat-view.test.d.ts +4 -0
- package/dist/__tests__/chat-view.test.js +480 -0
- package/dist/__tests__/drawing.test.d.ts +4 -0
- package/dist/__tests__/drawing.test.js +426 -0
- package/dist/__tests__/input.test.d.ts +5 -0
- package/dist/__tests__/input.test.js +911 -0
- package/dist/__tests__/layout.test.d.ts +4 -0
- package/dist/__tests__/layout.test.js +689 -0
- package/dist/__tests__/pixel.test.d.ts +1 -0
- package/dist/__tests__/pixel.test.js +674 -0
- package/dist/__tests__/render.test.d.ts +1 -0
- package/dist/__tests__/render.test.js +400 -0
- package/dist/__tests__/styled.test.d.ts +4 -0
- package/dist/__tests__/styled.test.js +149 -0
- package/dist/__tests__/widgets.test.d.ts +5 -0
- package/dist/__tests__/widgets.test.js +924 -0
- package/dist/ansi/esc.d.ts +61 -0
- package/dist/ansi/esc.js +85 -0
- package/dist/ansi/output.d.ts +66 -0
- package/dist/ansi/output.js +192 -0
- package/dist/ansi/strip.d.ts +16 -0
- package/dist/ansi/strip.js +74 -0
- package/dist/app.d.ts +68 -0
- package/dist/app.js +297 -0
- package/dist/drawing/clip.d.ts +23 -0
- package/dist/drawing/clip.js +67 -0
- package/dist/drawing/context.d.ts +77 -0
- package/dist/drawing/context.js +275 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +63 -0
- package/dist/input/escape-matcher.d.ts +27 -0
- package/dist/input/escape-matcher.js +253 -0
- package/dist/input/events.d.ts +49 -0
- package/dist/input/events.js +17 -0
- package/dist/input/index.d.ts +15 -0
- package/dist/input/index.js +14 -0
- package/dist/input/matcher.d.ts +23 -0
- package/dist/input/matcher.js +14 -0
- package/dist/input/mouse-matcher.d.ts +27 -0
- package/dist/input/mouse-matcher.js +142 -0
- package/dist/input/paste-matcher.d.ts +23 -0
- package/dist/input/paste-matcher.js +104 -0
- package/dist/input/processor.d.ts +51 -0
- package/dist/input/processor.js +145 -0
- package/dist/input/raw-mode.d.ts +13 -0
- package/dist/input/raw-mode.js +24 -0
- package/dist/input/text-matcher.d.ts +14 -0
- package/dist/input/text-matcher.js +32 -0
- package/dist/layout/box.d.ts +33 -0
- package/dist/layout/box.js +92 -0
- package/dist/layout/column.d.ts +21 -0
- package/dist/layout/column.js +90 -0
- package/dist/layout/control.d.ts +73 -0
- package/dist/layout/control.js +215 -0
- package/dist/layout/row.d.ts +21 -0
- package/dist/layout/row.js +95 -0
- package/dist/layout/stack.d.ts +18 -0
- package/dist/layout/stack.js +64 -0
- package/dist/layout/types.d.ts +27 -0
- package/dist/layout/types.js +4 -0
- package/dist/pixel/background.d.ts +16 -0
- package/dist/pixel/background.js +16 -0
- package/dist/pixel/box-pattern.d.ts +38 -0
- package/dist/pixel/box-pattern.js +57 -0
- package/dist/pixel/buffer.d.ts +25 -0
- package/dist/pixel/buffer.js +51 -0
- package/dist/pixel/color.d.ts +48 -0
- package/dist/pixel/color.js +92 -0
- package/dist/pixel/foreground.d.ts +31 -0
- package/dist/pixel/foreground.js +64 -0
- package/dist/pixel/pixel.d.ts +21 -0
- package/dist/pixel/pixel.js +38 -0
- package/dist/pixel/symbol.d.ts +38 -0
- package/dist/pixel/symbol.js +192 -0
- package/dist/render/regions.d.ts +54 -0
- package/dist/render/regions.js +102 -0
- package/dist/render/render-target.d.ts +42 -0
- package/dist/render/render-target.js +118 -0
- package/dist/styled.d.ts +113 -0
- package/dist/styled.js +176 -0
- package/dist/widgets/border.d.ts +34 -0
- package/dist/widgets/border.js +121 -0
- package/dist/widgets/chat-view.d.ts +239 -0
- package/dist/widgets/chat-view.js +993 -0
- package/dist/widgets/interview.d.ts +87 -0
- package/dist/widgets/interview.js +187 -0
- package/dist/widgets/markdown.d.ts +87 -0
- package/dist/widgets/markdown.js +611 -0
- package/dist/widgets/panel.d.ts +19 -0
- package/dist/widgets/panel.js +35 -0
- package/dist/widgets/scroll-view.d.ts +43 -0
- package/dist/widgets/scroll-view.js +182 -0
- package/dist/widgets/styled-text.d.ts +38 -0
- package/dist/widgets/styled-text.js +183 -0
- package/dist/widgets/syntax.d.ts +37 -0
- package/dist/widgets/syntax.js +670 -0
- package/dist/widgets/text-input.d.ts +121 -0
- package/dist/widgets/text-input.js +618 -0
- package/dist/widgets/text.d.ts +34 -0
- package/dist/widgets/text.js +168 -0
- package/package.json +45 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single-line text input widget — the primary replacement for readline.
|
|
3
|
+
*
|
|
4
|
+
* Handles cursor movement, text editing, history navigation, word-jump,
|
|
5
|
+
* clipboard paste, and visual scrolling when the value exceeds the
|
|
6
|
+
* visible width.
|
|
7
|
+
*/
|
|
8
|
+
import type { DrawingContext, TextStyle } from "../drawing/context.js";
|
|
9
|
+
import type { InputEvent } from "../input/events.js";
|
|
10
|
+
import { Control } from "../layout/control.js";
|
|
11
|
+
import type { Constraint, Size } from "../layout/types.js";
|
|
12
|
+
/** Returns the style to use at each character position in the input value. */
|
|
13
|
+
export type InputColorizer = (value: string) => (TextStyle | null)[];
|
|
14
|
+
/**
|
|
15
|
+
* Called on backspace/delete to determine how many characters to remove.
|
|
16
|
+
* Receives the value and cursor position. Returns the number of chars to
|
|
17
|
+
* delete (backward for backspace, forward for delete). Default: 1.
|
|
18
|
+
*/
|
|
19
|
+
export type DeleteSizer = (value: string, cursor: number, direction: "backward" | "forward") => number;
|
|
20
|
+
export interface TextInputOptions {
|
|
21
|
+
placeholder?: string;
|
|
22
|
+
placeholderStyle?: TextStyle;
|
|
23
|
+
style?: TextStyle;
|
|
24
|
+
cursorStyle?: TextStyle;
|
|
25
|
+
prompt?: string;
|
|
26
|
+
promptStyle?: TextStyle;
|
|
27
|
+
value?: string;
|
|
28
|
+
history?: string[];
|
|
29
|
+
/** Optional per-character colorizer. Return null to use default style. */
|
|
30
|
+
colorize?: InputColorizer;
|
|
31
|
+
/** Optional callback to determine delete size for backspace/delete. */
|
|
32
|
+
deleteSize?: DeleteSizer;
|
|
33
|
+
/** Optional hint callback. Returns dim text to show after the value (e.g. placeholder params). */
|
|
34
|
+
hint?: (value: string) => string | null;
|
|
35
|
+
/** Style for hint text (default: dim/italic). */
|
|
36
|
+
hintStyle?: TextStyle;
|
|
37
|
+
}
|
|
38
|
+
export declare class TextInput extends Control {
|
|
39
|
+
private _value;
|
|
40
|
+
private _cursor;
|
|
41
|
+
private _prompt;
|
|
42
|
+
private _placeholder;
|
|
43
|
+
private _placeholderStyle;
|
|
44
|
+
private _style;
|
|
45
|
+
private _cursorStyle;
|
|
46
|
+
private _promptStyle;
|
|
47
|
+
private _colorize;
|
|
48
|
+
private _deleteSize;
|
|
49
|
+
private _hint;
|
|
50
|
+
private _hintStyle;
|
|
51
|
+
/** Command history entries (most recent last). */
|
|
52
|
+
private _history;
|
|
53
|
+
/** Current position in history (-1 = not browsing, 0 = oldest). */
|
|
54
|
+
private _historyIndex;
|
|
55
|
+
/** Saved input when user starts browsing history. */
|
|
56
|
+
private _savedInput;
|
|
57
|
+
constructor(options?: TextInputOptions);
|
|
58
|
+
get value(): string;
|
|
59
|
+
set value(v: string);
|
|
60
|
+
get cursor(): number;
|
|
61
|
+
set cursor(pos: number);
|
|
62
|
+
get prompt(): string;
|
|
63
|
+
set prompt(v: string);
|
|
64
|
+
get placeholder(): string;
|
|
65
|
+
set placeholder(v: string);
|
|
66
|
+
get style(): TextStyle;
|
|
67
|
+
set style(v: TextStyle);
|
|
68
|
+
get cursorStyle(): TextStyle;
|
|
69
|
+
set cursorStyle(v: TextStyle);
|
|
70
|
+
get promptStyle(): TextStyle;
|
|
71
|
+
set promptStyle(v: TextStyle);
|
|
72
|
+
get placeholderStyle(): TextStyle;
|
|
73
|
+
set placeholderStyle(v: TextStyle);
|
|
74
|
+
get history(): string[];
|
|
75
|
+
/** Clear the input value and reset cursor. */
|
|
76
|
+
clear(): void;
|
|
77
|
+
/** Set the value and move cursor to the end. */
|
|
78
|
+
setValue(text: string): void;
|
|
79
|
+
/** Insert text at the current cursor position. */
|
|
80
|
+
insert(text: string): void;
|
|
81
|
+
handleInput(event: InputEvent): boolean;
|
|
82
|
+
private _handlePaste;
|
|
83
|
+
private _handleKey;
|
|
84
|
+
/**
|
|
85
|
+
* Find the position of the start of the word to the left of `pos`.
|
|
86
|
+
* Skips any whitespace first, then skips non-whitespace.
|
|
87
|
+
*/
|
|
88
|
+
private _wordBoundaryLeft;
|
|
89
|
+
/**
|
|
90
|
+
* Find the position of the end of the word to the right of `pos`.
|
|
91
|
+
* Skips any non-whitespace first, then skips whitespace.
|
|
92
|
+
*/
|
|
93
|
+
private _wordBoundaryRight;
|
|
94
|
+
/**
|
|
95
|
+
* Build wrapped lines from the current value.
|
|
96
|
+
* Row 0 starts after the prompt (firstRowW chars wide).
|
|
97
|
+
* Subsequent rows use the full width.
|
|
98
|
+
* Breaks prefer spaces (word wrap) but will hard-break if a word
|
|
99
|
+
* is longer than the row width.
|
|
100
|
+
*/
|
|
101
|
+
private _wrapLines;
|
|
102
|
+
/**
|
|
103
|
+
* Find which wrapped line and column the cursor is on.
|
|
104
|
+
* Returns { row, col } in wrapped coordinates.
|
|
105
|
+
*/
|
|
106
|
+
private _cursorToRowCol;
|
|
107
|
+
/** Get the character offset where a given wrapped line starts. */
|
|
108
|
+
private _lineOffset;
|
|
109
|
+
/** Vertical scroll offset (first visible row). */
|
|
110
|
+
private _vScrollOffset;
|
|
111
|
+
/** Cached layout widths from last measure/render. */
|
|
112
|
+
private _lastTotalWidth;
|
|
113
|
+
private _lastFirstRowW;
|
|
114
|
+
measure(constraint: Constraint): Size;
|
|
115
|
+
render(ctx: DrawingContext): void;
|
|
116
|
+
/**
|
|
117
|
+
* Draw the cursor character with inverted foreground/background
|
|
118
|
+
* colours (swap fg and bg from the text style).
|
|
119
|
+
*/
|
|
120
|
+
private _drawCursor;
|
|
121
|
+
}
|