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.
43 lines
1.8 KiB
43 lines
1.8 KiB
import {EditorQuestion} from "inquirer";
|
|
import {InquireFunction} from "../Inquire";
|
|
import {personaPossessive, PersonaPrompt} 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 JournalEntryPromptOptions extends Partial<Omit<EditorQuestion, "name" | "type">>, PersonaPrompt {}
|
|
|
|
export interface JournalEntryPromptDependencies {
|
|
readonly inquire: InquireFunction
|
|
}
|
|
|
|
export function journalEntryPrompt(deps: JournalEntryPromptDependencies): {
|
|
(options: JournalEntryPromptOptions): Promise<string|null>,
|
|
mainMenu: EntryMainMenuChoice<"journalEntry">,
|
|
} {
|
|
return makeEntryMainMenuChoice({
|
|
property: "journalEntry",
|
|
name: (input) => typeof input === "string" ? `Change journal entry ${chalk.dim(`(currently ${chalk.greenBright(`${pluralize("word", wordcount(input), true)} long`)})`)}` : "Add journal entry",
|
|
key: "j",
|
|
injected: (options) => promptForJournalEntry(options, deps),
|
|
toOptions: asDefault,
|
|
toProperty: (input) => input === null ? undefined : input,
|
|
})
|
|
}
|
|
|
|
export async function promptForJournalEntry(options: JournalEntryPromptOptions, {inquire}: JournalEntryPromptDependencies): Promise<string | null> {
|
|
const {persona} = options
|
|
const result = await inquire({
|
|
type: "editor",
|
|
message: typeof options.default === "string" ? `Edit ${personaPossessive(persona)} journal entry:` : `Type up ${personaPossessive(persona)} journal entry:`,
|
|
...options,
|
|
})
|
|
const trimmed = result.trimEnd()
|
|
if (trimmed === "") {
|
|
return null
|
|
} else {
|
|
return trimmed
|
|
}
|
|
} |