MCPcopy Create free account
hub / github.com/coder/ghostty-web / InputHandler

Class InputHandler

lib/input-handler.ts:161–604  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159 * keyboard events to terminal input data
160 */
161export class InputHandler {
162 private encoder: KeyEncoder;
163 private container: HTMLElement;
164 private onDataCallback: (data: string) => void;
165 private onBellCallback: () => void;
166 private onKeyCallback?: (keyEvent: IKeyEvent) => void;
167 private customKeyEventHandler?: (event: KeyboardEvent) => boolean;
168 private getModeCallback?: (mode: number) => boolean;
169 private keydownListener: ((e: KeyboardEvent) => void) | null = null;
170 private keypressListener: ((e: KeyboardEvent) => void) | null = null;
171 private pasteListener: ((e: ClipboardEvent) => void) | null = null;
172 private compositionStartListener: ((e: CompositionEvent) => void) | null = null;
173 private compositionUpdateListener: ((e: CompositionEvent) => void) | null = null;
174 private compositionEndListener: ((e: CompositionEvent) => void) | null = null;
175 private isComposing = false;
176 private isDisposed = false;
177
178 /**
179 * Create a new InputHandler
180 * @param ghostty - Ghostty instance (for creating KeyEncoder)
181 * @param container - DOM element to attach listeners to
182 * @param onData - Callback for terminal data (escape sequences to send to PTY)
183 * @param onBell - Callback for bell/beep event
184 * @param onKey - Optional callback for raw key events
185 * @param customKeyEventHandler - Optional custom key event handler
186 * @param getMode - Optional callback to query terminal mode state (for application cursor mode)
187 */
188 constructor(
189 ghostty: Ghostty,
190 container: HTMLElement,
191 onData: (data: string) => void,
192 onBell: () => void,
193 onKey?: (keyEvent: IKeyEvent) => void,
194 customKeyEventHandler?: (event: KeyboardEvent) => boolean,
195 getMode?: (mode: number) => boolean
196 ) {
197 this.encoder = ghostty.createKeyEncoder();
198 this.container = container;
199 this.onDataCallback = onData;
200 this.onBellCallback = onBell;
201 this.onKeyCallback = onKey;
202 this.customKeyEventHandler = customKeyEventHandler;
203 this.getModeCallback = getMode;
204
205 // Attach event listeners
206 this.attach();
207 }
208
209 /**
210 * Set custom key event handler (for runtime updates)
211 */
212 setCustomKeyEventHandler(handler: (event: KeyboardEvent) => boolean): void {
213 this.customKeyEventHandler = handler;
214 }
215
216 /**
217 * Attach keyboard event listeners to container
218 */

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…