You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.7 KiB
42 lines
1.7 KiB
3 years ago
|
import {InputQuestion} from "inquirer";
|
||
|
import {InquireFunction} from "../Inquire";
|
||
|
import {personaName, personaPossessive, PersonaPrompt, personaVerb} from "../../datatypes/Persona";
|
||
|
import {EntryMainMenuChoice, makeEntryMainMenuChoice} from "./EntryMainMenuPrompt";
|
||
|
import chalk from "chalk";
|
||
|
import pluralize from "pluralize";
|
||
|
import wordcount from "wordcount";
|
||
|
import {asDefault} from "../../utils/Objects";
|
||
|
|
||
|
export interface SummaryPromptOptions extends Partial<Omit<InputQuestion, "name" | "type">>, PersonaPrompt {}
|
||
|
|
||
|
export interface SummaryPromptDependencies {
|
||
|
readonly inquire: InquireFunction
|
||
|
}
|
||
|
|
||
|
export function summaryPrompt(deps: SummaryPromptDependencies): {
|
||
|
(options: SummaryPromptOptions): Promise<string|null>,
|
||
|
mainMenu: EntryMainMenuChoice<"summary">,
|
||
|
} {
|
||
|
return makeEntryMainMenuChoice({
|
||
|
property: "summary",
|
||
|
name: (input) => typeof input === "string" ? `Change summary ${chalk.dim(`(currently ${chalk.greenBright(`${pluralize("word", wordcount(input), true)} long`)})`)}` : "Add summary",
|
||
|
key: "s",
|
||
|
injected: (options) => promptForSummary(options, deps),
|
||
|
toOptions: asDefault,
|
||
|
toProperty: (input) => input === null ? undefined : input,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
export async function promptForSummary(options: SummaryPromptOptions, {inquire}: SummaryPromptDependencies): Promise<string | null> {
|
||
|
const {persona} = options
|
||
|
const result = await inquire({
|
||
|
type: "input",
|
||
|
message: typeof options.default === "string" ? `What's ${personaPossessive(persona)} new summary?` : `Can you summarize how ${personaName(persona)} ${personaVerb(persona, "feel", "feels")}?`,
|
||
|
...options,
|
||
|
})
|
||
|
if (result === "") {
|
||
|
return null
|
||
|
} else {
|
||
|
return result
|
||
|
}
|
||
|
}
|