Download packages/pi-tui/src/components/cancellable-loader.ts from SaylorTwift/kimi-code: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/pi-tui/src/components/cancellable-loader.ts
- Command line
-
hf download hf://SaylorTwift/kimi-code/packages/pi-tui/src/components/cancellable-loader.ts
-
curl -L -o cancellable-loader.ts https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/pi-tui/src/components/cancellable-loader.ts
1 kB
| import { getKeybindings } from "../keybindings.ts"; | |
| import { Loader } from "./loader.ts"; | |
| /** | |
| * Loader that can be cancelled with Escape. | |
| * Extends Loader with an AbortSignal for cancelling async operations. | |
| * | |
| * @example | |
| * const loader = new CancellableLoader(tui, cyan, dim, "Working..."); | |
| * loader.onAbort = () => done(null); | |
| * doWork(loader.signal).then(done); | |
| */ | |
| export class CancellableLoader extends Loader { | |
| private abortController = new AbortController(); | |
| /** Called when user presses Escape */ | |
| onAbort?: () => void; | |
| /** AbortSignal that is aborted when user presses Escape */ | |
| get signal(): AbortSignal { | |
| return this.abortController.signal; | |
| } | |
| /** Whether the loader was aborted */ | |
| get aborted(): boolean { | |
| return this.abortController.signal.aborted; | |
| } | |
| handleInput(data: string): void { | |
| const kb = getKeybindings(); | |
| if (kb.matches(data, "tui.select.cancel")) { | |
| this.abortController.abort(); | |
| this.onAbort?.(); | |
| } | |
| } | |
| dispose(): void { | |
| this.stop(); | |
| } | |
| } | |