UNPKG

2.1 kBTypeScriptView Raw
1import { Change } from "diff";
2import { Answers, PromptModule, QuestionCollection } from "inquirer";
3import { Logger } from "./util/log";
4
5declare namespace TerminalAdapter {
6 /**
7 * Provides options for creating an adapter.
8 */
9 interface AdapterOptions {
10 /**
11 * A console-object for logging messages.
12 */
13 console?: Console | undefined;
14 }
15
16 /**
17 * Represents a set of questions.
18 */
19 type Questions<T extends Answers> = QuestionCollection<T>;
20}
21
22/**
23 * `TerminalAdapter` is the default implementation of `Adapter`, an abstraction
24 * layer that defines the I/O interactions.
25 *
26 * It provides a CLI interaction
27 */
28declare class TerminalAdapter {
29 /**
30 * An inquirer prompt module.
31 */
32 promptModule: PromptModule;
33
34 /**
35 * A console-object for logging messages.
36 */
37 console: Console;
38
39 /**
40 * A component for logging messages.
41 */
42 log: Logger;
43
44 /**
45 * Initializes a new instance of the `TerminalAdapter` class.
46 *
47 * @param options The options for creating the adapter.
48 */
49 constructor(options: TerminalAdapter.AdapterOptions);
50
51 /**
52 * Prompts the user for one or more questions.
53 *
54 * @param questions The questions to prompt.
55 */
56 prompt<T extends Answers>(questions: TerminalAdapter.Questions<T>): Promise<T>;
57
58 /**
59 * Prompts the user for one or more questions.
60 *
61 * @param questions The questions to prompt.
62 * @param cb Deprecated: The callback for handling the result.
63 */
64 prompt<TAnswers extends Answers, TResult>(
65 questions: TerminalAdapter.Questions<TAnswers>,
66 answers?: TAnswers,
67 cb?: (res: TAnswers) => TResult,
68 ): Promise<TResult>;
69
70 /**
71 * Shows a color-based diff of two strings.
72 *
73 * @param actual The actual text.
74 * @param expected The expected text.
75 * @param changes The changes returned by `diff`.
76 * @returns The formatted message.
77 */
78 diff(actual: string, expected: string, changes: Change[]): string;
79}
80
81export = TerminalAdapter;