import type { CompletionContext, CompletionResult } from "../deps.ts"; import { useRef, useState } from "../deps.ts"; import { MiniEditor } from "./mini_editor.tsx"; export function Prompt({ message, defaultValue, vimMode, darkMode, completer, callback, }: { message: string; defaultValue?: string; vimMode: boolean; darkMode: boolean; completer: (context: CompletionContext) => Promise; callback: (value?: string) => void; }) { const [text, setText] = useState(defaultValue || ""); const returnEl = (
{ callback(text); return true; }} onEscape={() => { callback(); }} onChange={(text) => { setText(text); }} />
); return returnEl; } export function Confirm({ message, callback, }: { message: string; callback: (value: boolean) => void; }) { const okButtonRef = useRef(null); setTimeout(() => { okButtonRef.current?.focus(); }); const returnEl = (
{ e.stopPropagation(); e.preventDefault(); switch (e.key) { case "Enter": callback(true); break; case "Escape": callback(false); break; } }} >
); return returnEl; }