MCPcopy
hub / github.com/bombshell-dev/clack / constructor

Method constructor

packages/core/src/prompts/multi-line.ts:89–153  ·  view source on GitHub ↗
(opts: MultiLineOptions)

Source from the content-addressed store, hash-verified

87 }
88
89 constructor(opts: MultiLineOptions) {
90 const initialUserInput = opts.initialUserInput ?? opts.initialValue;
91
92 super(
93 {
94 ...opts,
95 initialUserInput,
96 },
97 false
98 );
99
100 if (initialUserInput !== undefined) {
101 this._cursor = initialUserInput.length;
102 }
103
104 this.#showSubmit = opts.showSubmit ?? false;
105
106 this.on('key', (char, key) => {
107 if (key?.name && cursorActions.has(key.name as CursorAction)) {
108 this.#lastKeyWasReturn = false;
109 this.#handleCursor(key.name as CursorAction);
110 return;
111 }
112 if (char === '\t' && this.#showSubmit) {
113 this.focused = this.focused === 'editor' ? 'submit' : 'editor';
114 return;
115 }
116 if (key?.name === 'return') {
117 return;
118 }
119 this.#lastKeyWasReturn = false;
120 if (key?.name === 'backspace' && this.cursor > 0) {
121 this._setUserInput(
122 this.userInput.slice(0, this.cursor - 1) + this.userInput.slice(this.cursor)
123 );
124 this._cursor--;
125 return;
126 }
127 if (key?.name === 'delete' && this.cursor < this.userInput.length) {
128 this._setUserInput(
129 this.userInput.slice(0, this.cursor) + this.userInput.slice(this.cursor + 1)
130 );
131 return;
132 }
133 if (char) {
134 if (this.#showSubmit && this.focused === 'submit') {
135 this.focused = 'editor';
136 }
137 this.#insertAtCursor(char ?? '');
138 this._cursor++;
139 }
140 });
141
142 this.on('userInput', (input) => {
143 this._setValue(input);
144 });
145 this.on('finalize', () => {
146 if (!this.value) {

Callers

nothing calls this directly

Calls 5

#handleCursorMethod · 0.95
#insertAtCursorMethod · 0.95
onMethod · 0.80
_setUserInputMethod · 0.80
_setValueMethod · 0.80

Tested by

no test coverage detected