UNPKG

@s-hiroshi/bks

Version:

Cli bookmarks application

59 lines 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FindControl = void 0; const inquirer = require("inquirer"); const createChoices_1 = require("../service/createChoices"); class FindControl { constructor(reader) { this.reader = reader; this.controlCharactor = "find"; } getControlCharactor() { return this.controlCharactor; } async execute(query) { if (!query) { query = await inquirer .prompt([ { name: "context", message: "Type a keyword or url", default: "", }, ]) .then((answer) => { return answer.context; }); } const items = this.reader.readItem(query, query); if (items.length > 0) { const contents = items.map((item, index) => { return `keyword: ${item.keyword}\n url: ${item.content}`; }); const choices = (0, createChoices_1.createChoices)(contents, ["Exit"]); const choiced = await inquirer .prompt([ { type: "list", name: "context", message: "Which one do you want to open", choices: choices, loop: false, }, ]) .then((answer) => { return answer.context; }); if (choiced !== "Exit") { return this.getChoicedItemUrl(choiced); } } } getChoicedItemUrl(choiced) { const choice = choiced.split("\n"); const url = choice[1].trim().split(" ")[1]; return url; } } exports.FindControl = FindControl; //# sourceMappingURL=FindControl.js.map